Chapter 10. Spring Remoting

In this chapter, we will cover:

  • Setting up Web-Services using RMI

  • Setting up servlet-based Web-Services using Hessian/Burlap, exposing business beans

  • Setting up Web-Services using JAX-WS

  • Exposing servlet-based Web-Services using Apache CXF

  • Exposing Web-Services using JMS as the underlying communication protocol

Introduction

Spring-WS project is a contract-first approach to build a Web-Service. This approach is already detailed in the first eight chapters. However, sometimes the requirement is to expose the existing business Spring beans as a Web-Service, which is called contract-last approach, to set up a Web-Service.

Spring's remoting supports communication with several remoting technologies. Spring remoting allows you to expose existing Spring beans on server side as a Web-Service. On the client side, Spring remoting allows the client application to call a remote Spring bean (which is exposed as a Web-Service) through a local interface. In this chapter, Spring's features for the following remoting technologies are detailed:

  • RMI: Spring's RmiServiceExporter allows you to expose local business services on Remote Method Invocation (RMI) on the server side, and Spring's RmiProxyFactoryBean is the client-side proxy bean to call the Web-Service.

  • Hessian: Spring's HessianServiceExporter allows you to expose local business services on lightweight HTTP-based protocol, introduced by Caucho technology ( http://hessian.caucho.com) on the server side, and HessianProxyFactoryBean is the client-side proxy bean to call the Web-Service.

  • Burlap: This is an XML alternative of Hessian by Caucho Technology. Spring provides support classes using two of Spring's beans, namely, BurlapProxyFactoryBean and BurlapServiceExporter.

  • JAX-RPC: Spring's support to set up Web-Services is based on a Remote Procedure Call that uses J2EE 1.4's JAX-RPC Web-Service API

  • JAX-WS: Spring's support to set up Web-Services using Java EE 5+ JAX-WS API that allows message-oriented as well as Remote Procedure Call Web-Service development.

  • JMS: Spring exposes/consumes Web-Services using JMS as the underlying communication protocol using JmsInvokerServiceExporter and JmsInvokerProxyFactoryBean classes.

Since JAX-WS is the successor of JAX-RPC, JAX-RPC is not included in this chapter. Instead, Apache CXF will be detailed in this chapter, as it can use JAX-WS to set up Web-Services, even though it is not part of Spring's remoting.

For simplification, in this chapter, the following local business service is to be exposed as a Web-Service (the domain model is the one described in the Introduction section of Chapter 1,Building SOAP Web-Services).

public interface OrderService {
placeOrderResponse placeOrder(PlaceOrderRequest placeOrderRequest);
}

And this is the interface implementation:

public class OrderServiceImpl implements OrderService{
public PlaceOrderResponse placeOrder(PlaceOrderRequest placeOrderRequest) {
PlaceOrderResponse response=new PlaceOrderResponse();
response.setRefNumber(getRandomOrderRefNo());
return response;
}
...

Setting up Web-Services using RMI

RMI, a part of J2SE, allows calling a method on different Java Virtual Machines (JVMs). RMI's goal is to expose objects in separate JVM's, as if they are like local objects. The client that calls the remote object through RMI doesn't know whether an object is remote or local, and calling methods on the remote object has the same syntax as a method invocation on a local object.

Spring's remoting provides features to expose/access Web-Services, based on RMI technology. On the server side, Spring's RmiServiceExporter bean exposes server-side Spring business bean as a Web-Service. On the client-side, Spring's RmiProxyFactoryBean presents the Web-Service's methods as a local interface.

In this recipe, we will learn to set up a Web-Service using RMI, and learn how the call to Web-Service through RMI is presented.

Getting ready

In this recipe, we have the following two projects:

  1. LiveRestaurant_R-10.1 (for a server-side Web-Service), with the following Maven dependencies:

    • spring-context-3.0.5.RELEASE.jar

    • log4j-1.2.9.jar

  2. LiveRestaurant_R-10.1-Client (for the client-side), with the following Maven dependencies:

    • spring-context-3.0.5.RELEASE.jar

    • spring-ws-test-2.0.0.RELEASE.jar

    • log4j-1.2.9.jar

    • junit-4.7.jar

    • xmlunit-1.1.jar

How to do it...

  1. Register the server-side service implementation within Spring's RmiServiceExporter in the server-side application context (applicationContext.xml) and set the port and service name.

  2. Register the local interface (same as server-side) within Spring's RmiProxyFactoryBean in the client-side application context (applicationContext.xml) and set the service's URL.

  3. Add a Java class to load the server-side application context-file (in the class's main method) to set up the server.

  4. Add a JUnit test case class on the client side that calls a Web-Service using the local interface.

  5. Run the following command on Liverestaurant_R-10.1:

    mvn clean package exec:java
    
    
  6. Run the following command on Liverestaurant_R-10.1-Client:

mvn clean package

  • Here is the client-side output:

......
... - Located RMI stub with URL [rmi://localhost:1199/OrderService]
....- RMI stub [rmi://localhost:1199/OrderService] is an RMI invoker
......
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.78 sec
...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
......
[INFO] BUILD SUCCESS

How it works...

OrderServiceSetUp is the class that loads the server-side application context and sets up the server to expose the server-side business service as a Web-Service. OrderServiceClientTest is the client-side test class that loads the client-side application context and calls the Web-Service methods through a client-side local interface that represents a remote business service.

The OrderServiceImpl is the service to be exposed through a Web-Service. In the server-side's application context, within org.springframework.remoting.rmi.RmiServiceExporter Bean, OrderService is the name of the service that will be registered with the RMI registry. The service property is for passing the RmiServiceExporter and the bean instance. serviceInterface is the interface that represents the local business service remotely. Only those methods that are defined in this interface can be called remotely:

<bean id="orderService" class="com.packtpub.liverestaurant.service.OrderServiceImpl" />
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="OrderService" />
<property name="service" ref="orderService" />
<property name="serviceInterface" value="com.packtpub.liverestaurant.service.OrderService" />
<property name="registryPort" value="1199" />
</bean>

On the client side's configuration file, serviceUrl is the URL address of the Web-Service and serviceInterface in the local interface that enables client calls to the server-side methods remotely:

<bean id="orderService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value=" rmi://localhost:1199/OrderService" />
<property name="serviceInterface" value="com.packtpub.liverestaurant.service.OrderService" />
</bean>

OrderServiceClientTest is the JUnit test case class that loads the application context and calls remote methods through the local interface:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext.xml")
public class OrderServiceClientTest {
@Autowired
OrderService orderService;
@Autowired
private GenericApplicationContext applicationContext;
@Before
@After
public void setUpAfter() {
applicationContext.close();
}
@Test
public final void testPlaceOrder() throws Exception {
PlaceOrderRequest orderRequest = new PlaceOrderRequest();
orderRequest.setOrder(getDummyOrder());
PlaceOrderResponse orderResponse = orderService.placeOrder(orderRequest);
Assert.assertTrue(orderResponse.getRefNumber().indexOf("1234")>0);
}
private Order getDummyOrder() {
Order order=new Order();
order.setRefNumber("123");
List<FoodItem> items=new ArrayList<FoodItem>();
FoodItem item1=new FoodItem();
item1.setType(FoodItemType.BEVERAGES);
item1.setName("beverage");
item1.setQuantity(1.0);
......
}
........
}

Setting up a servlet-based Web-Service using Hessian/Burlap, exposing business beans

Hessian and Burlap, developed by Caucho (http://hessian.caucho.com), are lightweight HTTP-based remoting technologies. Even though both of them use the HTTP protocol to communicate, Hessian communicates using binary messages, while Burlap communicates using XML messages.

Spring's remoting provides features to expose/access Web-Services based on these technologies. On the server side, Spring's ServiceExporter bean exposes the server-side Spring business bean ( OrderServiceImpl) as a Web-Service:

<bean id="orderService" class="com.packtpub.liverestaurant.service.OrderServiceImpl" />
<bean name="/OrderService" class="....ServiceExporter">
<property name="service" ref="orderService" />
</bean>

On the client-side, Spring's ProxyFactory bean exposes remote interface through local client-side interface ( OrderService):

<bean id="orderService" class="....ProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/LiveRestaurant/services/OrderService" />
<property name="serviceInterface" value="com.packtpub.liverestaurant.service.OrderService" />

Getting ready

In this recipe, we have the following two projects:

  1. LiveRestaurant_R-10.2 (for the server-side Web-Service), with the following Maven dependencies:

    • spring-webmvc-3.0.5.RELEASE.jar

    • log4j-1.2.9.jar

    • hessian-3.1.5.jar

  2. LiveRestaurant_R-10.2-Client (for the client-side), with the following Maven dependencies:

    • spring-web-3.0.5.RELEASE.jar

    • spring-test-3.0.5.RELEASE.jar

    • log4j-1.2.9.jar

    • junit-4.7.jar

    • hessian-3.1.5.jar

How to do it...

Follow these steps to set up a servlet-based Web-Service using the Hessian service:

  1. Configure DispatcherServlet inside the web.xml file (URL: http://<host>:<port>/<appcontext>/services to be forwarded to this servlet).

  2. Register the server-side service interface within Spring's HessianServiceExporter in the server-side application context ( applicationContext.xml), and set service name and service interface.

  3. Register the local interface (same as the server side) within Spring's HessianProxyFactoryBean in the client-side application context ( applicationContext.xml), and set service's URL.

  4. Add a JUnit test case class in the client side that calls a Web-Service using the local interface

  5. Run the following command on Liverestaurant_R-10.2:

    mvn clean package tomcat:run
    
    
  6. Run the following command on Liverestaurant_R-10.2-Client:

mvn clean package

  • In the client-side output, you will be able to see the success message of running the test case, as follows:

text.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.71 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]

Follow these steps to set up a servlet-based Web-Service using the Burlap service:

  1. Modify the server-side service interface to Spring's BurlapServiceExporter in the server-side application context ( applicationContext.xml).

  2. Modify the client-side application context ( applicationContext.xml) to Spring's BurlapProxyFactoryBean.

  3. Run the following command on Liverestaurant_R-10.2:

    mvn clean package tomcat:run
    
    
  4. Run the following command on Liverestaurant_R-10.2-Client:

mvn clean package

  • In the client-side output, you will be able to see the success message of a running test case, as follows:

text.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.849 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar ..
[INFO] Building jar: ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

How it works...

The Liverestaurant_R-10.2 project is a server-side Web-Service that sets up a servlet-based Web-Service, using the burlap/hessian exporter from Spring's remoting.

The Liverestaurant_R-10.2-Client project is a client-side test project that calls the burlap/hessian Web-Service, using the burlap/hessian client proxy from Spring's remoting.

On the server side, DiapatcherServlet will forward all the requests using the URL pattern to BurlapServiceExporter/ HessianServiceExporter (http://<hostaddress>/<context>/<services>):

<servlet>
<servlet-name>order</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

These exporters expose the internal local service implementation (OrderServiceImpl) as a Web-Service:

<bean name="/OrderService" class="org.springframework.remoting.caucho.BurlapServiceExporter">
<property name="service" ref="orderService" />
<property name="serviceInterface" value="com.packtpub.liverestaurant.service.OrderService" />
</bean>

On the client-side, BurlapProxyFactoryBean/HessianProxyFactoryBean is responsible for exposing remote methods to the client, using a local client-side service interface ( OrderService):

<bean id="orderService" class="org.springframework.remoting.caucho.BurlapProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/LiveRestaurant/services/OrderService" />
<property name="serviceInterface" value="com.packtpub.liverestaurant.service.OrderService" />
</bean>

The OrderServiceClientTest implementation is the same as described in the recipe Setting up Web-Services using RMI.

See also...

In this chapter:

Setting up a Web-Services using RMI

Setting up Web-Services using JAX-WS

JAX-RPC was a standard that came with Java EE 1.4 to develop Web-Services, and has become less and less popular in recent years. JAX-WS 2.0 was introduced with Java EE 5 and is more flexible and annotation-based than JAX-RPC in biding concept. Here are some of the advantages of JAX-WS over JAX-RPC:

  • JAX-WS supports both message-oriented as well as Remote Procedure Call (RPC) Web-Services, while JAX-RPC supports only RPC

  • JAX-WS supports SOAP 1.2 and SOAP 1.1, but JAX-RPC supports SOAP 1.1

  • JAX-WS relies on the rich features of Java 5.0, while JAX-RPC works with Java 1.4

  • JAX-WS uses the very powerful XML for Object mapping framework (uses JAXB) while JAX-RPC uses its own framework that appeared weak on complex data models

Spring remoting provides feature to set up a JAX-WS Web-Service using java 1.5+ features. For example here, the annotation @WebService causes Spring to detect and expose this service as a Web-Service, and @WebMethod causes the following method: public OrderResponse placeOrder(..), to be called as a Web-Service method (placeOrder):

@Service("OrderServiceImpl")
@WebService(serviceName = "OrderService",endpointInterface = "com.packtpub.liverestaurant.service.OrderService")
public class OrderServiceImpl implements OrderService {
@WebMethod(operationName = "placeOrder")
public PlaceOrderResponse placeOrder(PlaceOrderRequest placeOrderRequest) {

In this recipe, JDK's built-in HTTP server is used to set up the Web-Service (since Sun's JDK 1.6.0_04, JAX-WS can be integrated with the JDK's built-in HTTP server).

Getting ready

Install Java and Maven (SE runtime environment (build jdk1.6.0_29)).

In this recipe, we have the following two projects:

  1. LiveRestaurant_R-10.3 (for the server-side Web-Service), with the following Maven dependencies:

    • spring-web-3.0.5.RELEASE.jar

    • log4j-1.2.9.jar

  2. LiveRestaurant_R-10.3-Client (for the client-side), with the following Maven dependencies:

    • spring-web-3.0.5.RELEASE.jar

    • log4j-1.2.9.jar

    • junit-4.7.jar

How to do it...

  1. Annotate the business service class and its methods.

  2. Register the service in the application context file ( applicationContext.xml), then configure the SimpleJaxWsServiceExporter bean, and create a class to load the server-side application context (this sets up the server).

  3. Register the local interface (in the same way as you did for the server-side interface) within Spring's .JaxWsPortProxyFactoryBean in the client-side application context (applicationContext.xml), and set the service's URL.

  4. Add a JUnit test case class in the client-side that calls the Web-Service using the local interface.

  5. Run the following command on Liverestaurant_R-10.3 and browse to see the WSDL file located at http://localhost:9999/OrderService?wsdl:

    mvn clean package exec:java
    
    
  6. Run the following command on Liverestaurant_R-10.3-Client:

mvn clean package

  • In the client-side output, you will be able to see the success message of a running test case, as follows:

.....
Dynamically creating request wrapper Class com.packtpub.liverestaurant.service.jaxws.PlaceOrder
Nov 14, 2011 11:34:13 PM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class com.packtpub.liverestaurant.service.jaxws.PlaceOrderResponse
......
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

How it works...

The Liverestaurant_R-10.3 project is a server-side Web-Service (by Spring remoting's exporter bean) that sets up a JAX-WS using DK's built-in HTTP server.

The Liverestaurant_R-10.3-Client project is a client-side test project that calls JAX-WS Web-Service using the client proxy from Spring remoting.

On the server-side, applicationContext.xml scans and detects annotating tags in OrderServiceImpl. Then SimpleJaxWsServiceExporter exposes this business service as a Web-Service:

<context:annotation-config/>
<context:component-scan base-package= "com.packtpub.liverestaurant.service"/>
<bean class= "org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
<property name="baseAddress" value="http://localhost:9999/" />
</bean>

In the service class, the annotations @WebService and @WebMethod cause Spring detects(by scanning), and expose(by SimpleJaxWsServiceExporter) this service class as a Web-Service and its method ( placeOrder) as a Web-Service method:

@Service("orderServiceImpl")
@WebService(serviceName = "OrderService")
public class OrderServiceImpl implements OrderService {
@WebMethod(operationName = "placeOrder")
public PlaceOrderResponse placeOrder(PlaceOrderRequest placeOrderRequest) {
PlaceOrderResponse response=new PlaceOrderResponse();
response.setRefNumber(getRandomOrderRefNo());
return response;
}
.......
}

On the client side, JaxWsPortProxyFactoryBean is responsible for exposing remote methods to the client, using a local client-side interface. WsdlDocumentUrl is the Web-Service WSDL address, portName is the portName value in WSDL, namespaceUri is the targetNameSpace in WSDL, and serviceInterface is the local client-side service interface:

<bean id="orderService" class= "org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="serviceInterface" value= "com.packtpub.liverestaurant.service.OrderService"/>
<property name="serviceInterface" value= "com.packtpub.liverestaurant.service.OrderService"/>
<property name="wsdlDocumentUrl" value= "http://localhost:9999/OrderService?wsdl"/>
<property name="namespaceUri" value= "http://service.liverestaurant.packtpub.com/"/>
<property name="serviceName" value="OrderService"/>
<property name="portName" value="OrderServiceImplPort"/>
</bean>

The OrderServiceClientTest implementation is the same as described in the recipe named Setting up a Web-Services using RMI.

See also...

In this chapter:

Setting up a Web-Services using RMI

In this book:

Chapter 2,Building Clients for SOAP Web Services

Creating a Web-Service client on HTTP transport

Exposing servlet-based Web-Services using Apache CXF

Apache CXF originated from a combination of the projects, namely: Celtix (IONA Technologies) and XFire (Codehaus), which are integrated into the Apache software foundation. CXF, by name, implies that it originates from the Celtix and XFire project names.

Apache CXF provides features to build and deploy Web-Services. The Apache CXF's recommended Web-Service configuration method (frontend or API) is JAX-WS 2.x. Apache CXF, which is not part of Spring's remoting, however, since it can use JAX-WS as its frontend, will be explained in this recipe.

Getting ready

Install Java and Maven (SE Runtime Environment (build jdk1.6.0_29)).

In this recipe, we have the following two projects:

  1. LiveRestaurant_R-10.4 (for the server-side Web-Service), with the following Maven dependencies:

    • cxf-rt-frontend-jaxws-2.2.6.jar

    • cxf-rt-transports-http-2.2.6.jar

    • spring-web-3.0.5.RELEASE.jar

    • commons-logging-1.1.1.jar

  2. LiveRestaurant_R-10.4-Client (for the client side), with the following Maven dependencies:

    • cxf-rt-frontend-jaxws-2.2.6.jar

    • cxf-rt-transports-http-2.2.6.jar

    • spring-web-3.0.5.RELEASE.jar

    • log4j-1.2.9.jar

    • junit-4.7.jar

How to do it...

  1. Annotate the business service class and methods (in the same way as you did for JAX-WS).

  2. Register the service in the application context file ( applicationContext.xml) and configure CXFServlet inside the web.xml file (URL: http://<host>:<port>/ is to be forwarded to this servlet).

  3. Register the local interface (in the same way as you did for the server side) within Spring's .JaxWsPortProxyFactoryBean, in the client-side application context ( applicationContext.xml), and set the service's URL.

  4. Add a JUnit test case class in the client side, which calls the Web-Service using the local interface.

How it works...

The Liverestaurant_R-10.4 project is a server-side Web-Service that set up a CXF, using the JAX-WS API.

The Liverestaurant_R-10.4-Client project is a client-side test project that calls JAX-WS Web-Service, using the client proxy from Spring's remoting.

On the server side, the configuration in applicationContext.xml detects annotating tags in OrderServiceImpl. Then jaxws:endpoint exposes this business service as a Web-Service:

<!-- Service Implementation -->
<bean id="orderServiceImpl" class= "com.packtpub.liverestaurant.service.OrderServiceImpl" />
<!-- JAX-WS Endpoint -->
<jaxws:endpoint id="orderService" implementor="#orderServiceImpl" address="/OrderService" />

The OrderServiceImpl explanation is the same as described in the recipe Setting up Web-Services using JAX-WS.

On the client side, JaxWsProxyFactoryBean is responsible for exposing remote methods to the client using a local client-side interface. address is the Web-Service service address and serviceInterface is the local client-side service interface:

<bean id="client" class= "com.packtpub.liverestaurant.service.OrderService" factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.packtpub.liverestaurant.service.OrderService"/>
<property name="address" value="http://localhost:8080/LiveRestaurant/OrderService"/>
</bean>

The OrderServiceClientTest implementation is the same as described in the recipe Setting up Web-Services using RMI.

See also...

In this chapter:

Setting up Web-Services using RMI

Exposing Web-Services using JMS as the underlying communication protocol

Java Message Service (JMS) introduced by Java 2 and J2EE was founded by Sun Microsystems in 1999. Systems using JMS are able to communicate in a synchronous or asynchronous mode, and are based on the point-to-point and publish-subscribe models.

Spring remoting provides the facility to expose Web-Services using JMS as the underlying communication protocol. Spring's JMS remoting sends and receives messages on the same thread in the single-threaded and non-transactional session.

However, for multi-threaded and transactional support for Web-Service on JMS, you can use Spring-WS on JMS protocol, which is based on Spring's JMS-based messaging.

In this recipe, apache-activemq-5.4.2 is used to set up a JMS server, and default objects, created by this JMS server (queue, broker), are used by the projects.

Getting ready

Install Java and Maven (SE Runtime Environment (build jdk1.6.0_29)).

Install apache-activemq-5.4.2.

In this recipe, we have the following two projects:

  1. LiveRestaurant_R-10.5 (for the server-side Web-Service), with the following Maven dependencies:

    • activemq-all-5.2.0.jar

    • spring-jms-3.0.5.RELEASE.jar

  2. LiveRestaurant_R-10.5-Client (for the client side), with the following Maven dependencies:

    • activemq-all-5.2.0.jar

    • spring-jms-3.0.5.RELEASE.jar

    • junit-4.7.jar

    • spring-test-3.0.5.RELEASE.jar

    • xmlunit-1.1.jar

How to do it...

Register the business service within the JmsInvokerServiceExporter bean and register SimpleMessageListenerContainer using the activemq default objects (broker, destination) in the server-side application context file.

  1. Create a Java class to load the application context and set up the server.

  2. Register JmsInvokerProxyFactoryBean in the client-side application context file using the activemq default objects (broker, destination)

  3. Add a JUnit test case class in the client side that calls the Web-Service using the local interface.

  4. Run apache-activemq-5.4.2 (to set up the JMS server).

  5. Run the following command on Liverestaurant_R-10.5 and browse to see the WSDL file located at http://localhost:9999/OrderService?wsdl:

    mvn clean package exec:java
    
    
  6. Run the following command on Liverestaurant_R-10.5-Client:

mvn clean package

  • In the client-side output, you will be able to see a success message of a running test case.

T E S T S
-------------------------------------------------------
Running com.packtpub.liverestaurant.service.client.OrderServiceClientTest
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.138 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

How it works...

The Liverestaurant_R-10.5 project is a server-side Web-Service that sets up a Web-Service by listening on a JMS queue.

The Liverestaurant_R-10.5-Client project is a client-side test project that sends JMS messages to a JMS queue.

On the server side, the class OrderServiceSetUp loads applicationContext.xml and creates a messageListener in a container (using SimpleMessageListenerContainer) that waits to listen for a message at a specific destination ( requestQueue). As soon as a message arrives, it calls the method on the business class ( OrderServiceImpl) through Spring's remoting class (JmsInvokerServiceExporter):

<bean id="orderService" class="com.packtpub.liverestaurant.service.OrderServiceImpl"/>
<bean id="listener" class="org.springframework.jms.remoting.JmsInvokerServiceExporter">
<property name="service" ref="orderService"/>
<property name="serviceInterface" value="com.packtpub.liverestaurant.service.OrderService"/>
</bean>
<bean id="container" class= "org.springframework.jms.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="messageListener" ref="listener"/>
<property name="destination" ref="requestQueue"/>
</bean>

On the client side, JmsInvokerProxyFactory is responsible for exposing remote methods to the client, using a local client-side interface (OrderService). When the client calls the method OrderService, JmsInvokerProxyFactory send a JMS message to the queue (requestQueue), which is the queue the server is listening to:

<bean id="orderService" class= "org.springframework.jms.remoting.JmsInvokerProxyFactoryBean">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="queue" ref="requestQueue"/>
<property name="serviceInterface" value="com.packtpub.liverestaurant.service.OrderService"/>
</bean>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset