Java Reference
In-Depth Information
means that the client doesn't have to handle this type of exception, and it doesn't know that the service
is implemented by an EJB component. The business interface for postage calculation is shown following:
package com.apress.springenterpriserecipes.post;
public interface PostageService {
public double calculatePostage(String country, double weight);
}
Now, in FrontDeskImpl , you can define a setter method for the PostageService business interface
to let Spring inject the service implementation so that your FrontDeskImpl will no longer be EJB specific.
Later, if you reimplement the PostageService interface with another technology (SOAP, RMI, Hessian/
Burlap, Flash AMF, etc), you won't need to modify a single line of code.
package com.apress.springenterpriserecipes.post;
public class FrontDeskImpl implements FrontDesk {
private PostageService postageService;
public void setPostageService(PostageService postageService) {
this.postageService = postageService;
}
public double calculatePostage(String country, double weight) {
return postageService.calculatePostage(country, weight);
}
}
Spring offers the proxy factory bean SimpleRemoteStatelessSessionProxyFactoryBean to create a
local proxy for a remote stateless session bean.
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="postageService"
class="org.springframework.ejb.access.SimpleRemoteStatelessSession
ProxyFactoryBean">
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">
org.apache.openejb.client.RemoteInitialContextFactory
</prop>
<prop key="java.naming.provider.url">
ejbd://localhost:4201
</prop>
</props>
</property>
<property name="jndiName" value="PostageServiceRemoteHome" />
<property name="businessInterface"
value="com.apress.springenterpriserecipes.post.PostageService" />
</bean>
Search WWH ::




Custom Search