Spring Book – Chapter 18 – Remoting

JAX-RPC

JAX-API stands for Java API for XML based Remote Procedure Call. Spring provides remoting support for web services via JAX-RPC (J2EE 1.4′s web service API). Spring supports WSDL/SOAP-based Web Services through the standard JAX-RPC API and covers client access and server endpoints. Spring provides two factory beans for creating JAX-RPC web service proxies namely org.springframework.remoting.jaxrpc.LocalJaxRpcServiceFactoryBean and org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean.

JaxRpcPortProxyFactoryBean is FactoryBean for a specific port of a JAX-RPC service. It exposes a proxy for the port, to be used for bean references. It inherits configuration properties from org.springframework.remoting.jaxrpc.JaxRpcPortClientInterceptor. This factory bean is deprecated in new versions of Spring in favor of JAX-WS support in org.springframework.remoting.jaxws package.

LocalJaxRpcServiceFactoryBean is a FactoryBean for locally defined JAX-RPC Service references. Similar to JaxRpcPortProxyFactoryBean, this factory bean is deprecated in new versions of Spring in favor of JAX-WS. Listing 19-14 shows configuring bean using JAX-RPC and using it in the client to call the business methods on this service.

Listing 19-14. Configuring bean using JAX-RPC remoting technology

You then have to write a wrapper Java class extending ServletEndpointSupport class and delegate the methods to the actual remote object. This wrapper class is necessary because JAX-RPC requires working with dedicated endpoint classes. If an existing service needs to be exported, a wrapper that extends ServletEndpointSupport for simple application context access is the simplest JAX-RPC compliant way. Listing 19-15 shows one such wrapper class and Listing 19-16 shows the remote interface having same methods as the original interface and extends java.rmi.Remote interface.

Listing 19-15. Wrapper class for exposing LoyaltyService class using JAX-RPC

Listing 19-16. Remote interface which extends Remote interface

Note: – JAX-RPC 1.x is the standard web service API in J2EE 1.4. This has been superseded by JAX-WS 2.x in Java EE 5, being more flexible in terms of bindings but also being heavily annotation-based.

JAX-WS

JAX-WS stands for Java API for XML Web Services. Spring provides remoting support for web services via JAX-WS (the successor of JAX-RPC, as introduced in Java EE 5 and Java 6).

Similar to JAX-RPC, JAX-WS requires wrapper class because JAX-WS requires working with dedicated endpoint classes. If an existing service needs to be exported, a wrapper that extends SpringBeanAutowiringSupport for simple Spring bean autowiring (through the @Autowired annotation) is the simplest JAX-WS compliant way. This is the class registered with the server-side JAX-WS implementation. Listing 19-17 shows this wrapper class.

Listing 19-17. Wrapper class for JAX-WS remoting technology

Listing 19-18 shows configuring the service as bean in the Spring configuration file using JAX-WS remoting technology.

Listing 19-18. Configuring service bean in spring configuration using JAX-WS technology

Page Visitors: 4814

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *