RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Best-of-Both-Worlds Remote Services with Spring HTTP Invoker : Page 3

Implement remote services from plain Java classes using the Spring HTTP invoker, which combines the simplicity of HTTP communication with Java's built-in object serialization.

Spring Configuration
The HTTP invoker remoting example uses two configuration XML files that define the Spring beans for the classes you wrote to implement the flood remote service: loanapp-servlet.xml and loanapp-client.xml. Implementation
Following are the steps for implementing a remote service for the sample loan-processing application with the HTTP invoker:
  1. Create a HTTP invoker service exporter class (HttpInvokerServiceExporter).
  2. Create a HTTP proxy (using HttpInvokerProxyFactoryBean). You specify parameters like serviceUrl and serviceInterface in this class.
  3. Define a URL mapping for the clients to call the remote HTTP service.
  4. Configure the Spring beans in the loanapp-servlet.xml file.
  5. Configure the Spring Web layer (DispatcherServlet) in web.xml file.
  6. Write the client class (using HTTP or Commons HttpClient).
  7. Write a JUnit test case to call the method in the client class.

The source code download contains a JUnit test client (FloodCertClientTest) to test the client class calling the flood remote service. It calls the client with several different test loan applications for properties with different zip codes. Based on the property zip code submitted, the flood service returns the results of the flood certification analysis.

Best-of-Both-Worlds Remoting
Spring remoting offers a simple and flexible solution for exposing business domain services as remoting services. It also provides the flexibility of exposing the same service under multiple protocols (at different URLs, of course). For example, you can implement the flood certification check service in the sample application as a RMI service (for Java clients to take advantage of the faster Java-to-Java remoting), as well as a HTTP service for non-Java clients. This way, you would write the business service logic in only one place but expose the service as two remote service endpoints.

The HTTP invoker framework provides the necessary proxies with plain Java service interfaces and a consistent usage and configuration style for implementing Java classes as remote services. This solution presents a best-of-both-worlds remoting solution that combines the simplicity of HTTP communication with Java’s built-in object serialization. This makes HTTP invoker a great alternative to either RMI or Hessian/Burlap.

HTTP invoker's one significant limitation is that it is offered only by the Spring framework. This means that both the client and the service applications must be implemented using Spring. But it is a good choice when you need a lightweight, easy-to-setup, and flexible remoting solution.

Srini Penchikala works as an Information Systems Subject Matter Expert at Flagstar Bank. His IT career spans over nine years with systems architecture, design, and development experience in client/server and Internet applications. He has been involved in designing and developing J2EE applications since 1998. Srini holds a Master's degree (Southern Illinois University, Edwardsville) and a bachelor's degree (Sri Venkateswara University, India) in Engineering. In his free time, Srini loves to research new J2EE technologies and frameworks.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date