Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Make the Right Decision with Our Side-by-Side Comparison of Spring and EJB 3.0, Part 2 : Page 2

Explore the similarities and differences between two of the most popular Java technologies today and learn key distinctions in making a technological decision between the two. Part 2 explores messaging, remoting, dependency injection, and more.


advertisement
Remoting
Whereas messaging typically involves asynchronous messages being exchanged between systems, remoting is the ability to make synchronous requests between systems. This is useful in a variety of cases, for instance, in the context of my flight booking application, to perform authorization against a passenger's credit card. The most popular mechanisms for remoting today are Web services and RMI. Web services requests are typically transported via HTTP and as such are routable through corporate firewalls. Their message structure is XML and as such is not platform- or programming language- specific. RMI on the other hand is typically used for communication between Java applications and is generally not routable through firewalls.

Remoting—Functional Comparison
For this comparison consider the role the booking agent plays in coordinating the purchase of airline tickets (see Figure 2).

Figure 2. Remote Booking Agent. In this example the booking agent illustrated in the first article is distributed; clients interact with the agent unaware that it is running on a remote server.



The test for this use case is listed in the first article. It can be satisfied using Spring to implement a remote booking agent. In this implementation nothing must be done to the Spring booking agent to make it accessible remotely. All that must be done is to export the agent using the RmiServiceExporter as illustrated below:

<bean class="org.springframework.remoting.rmi.RmiServiceExporter" lazy-init="false"> <property name="serviceName" value="bookingAgentService" /> <property name="service" ref="remoteBookingAgentService" /> <property name="serviceInterface" value="org.jug.flight.booking.BookingAgent" /> <property name="registryPort" value="1199" /> </bean> <bean id="remoteBookingAgent" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://localhost:1199/bookingAgentService" /> <property name="serviceInterface" value="org.jug.flight.booking.BookingAgent" /> </bean>

To make the EJB 3.0 version of the booking agent remote all that must be done to it is to annotate it as a remote component as shown below:

@Stateful @Remote public class BookingAgentEJB implements BookingAgent { ... }

Notice that in both cases neither the interface nor logic of the booking agent had to change to expose the agent to remote callers. In fact, the Spring implementation did not require any changes to the booking agent at all! The same result could have been achieved with EJB 3.0 if I had decided to use XML instead of annotations to declare the component as remote.

Remoting—Non-Functional Comparison
EJB remoting is built on RMI and makes creating distributed Java applications easy, including support for security and transaction propagation. Stateless EJBs may also be exposed as Web services using the metadata annotations defined in JSR 181 (Web Services Metadata for the Java Platform).

Spring 2.0 supports various forms of remoting including RMI, Web services, Hessian, Burlap, and HTTP invokers (using JDK serialization). It is differentiated from EJB in that any POJO may be exposed as a remote object. This is implemented through a combination of Spring helper classes and configuration. But Spring remoting does not support security and transaction propagation as EJB remoting does.

Remoting—Summary
Table 2 summarizes the differences between remoting support in Spring and EJB 3.

Table 2. Remoting Support in Spring and EJB 3.0

Feature Spring EJB 3.0
Supported Protocols RMI, Web Services, Hessian, Burlap, HTTP RMI, Web Services
Expose remote objects √ (Any POJO) √ (EJBs only)
Instance pooling and load balancing --
Transaction Propagation --
Security Propagation --



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap