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
1 2 3 4 5 6 7 |
<bean id="loyaltyService"> <property name="serviceInterface" value="com.mybook.loyalty.services.LoyaltyService"/> <property name="wsdlDocumentUrl" value="http://host:8080/loyalty/services/loyaltyService?WSDL"/> <property name="namespaceUri" value="http://host:8080/loyalty/services/loyaltyService"/> <property name="serviceName" value="LoyaltyService"/> <property name="portName" value="LoyaltyPort"/> </bean> |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import org.springframework.remoting.jaxrpc.ServletEndpointSupport; public class LoyaltyServiceEndpoint extends ServletEndpointSupport implements RemoteLoyaltyService { private LoyaltyService loyaltyService; protected void onInit() { this.loyaltyService = (LoyaltyService) getWebApplicationContext(). getBean("loyaltyService"); } public void doSomething() throws RemoteException { loyaltyService.doSomething(); } } |
Listing 19-16. Remote interface which extends Remote interface
1 2 3 4 5 6 7 8 9 |
import java.rmi.Remote; import java.rmi. RemoteException; public interface RemoteLoyaltyService extends Remote { public void doSomething() throws RemoteException; } |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import org.springframework.web.context.support.SpringBeanAutowiringSupport; public class LoyaltyServiceEndpoint extends SpringBeanAutowiringSupport { @Autowired private LoyaltyService loyaltyService; public void doSomething() { loyaltyService.doSomething(); } } |
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
1 2 3 4 5 6 7 |
<bean id="loyaltyService"> <property name="serviceInterface" value="com.mybook.loyalty.services.LoyaltyService"/> <property name="wsdlDocumentUrl" value="http://host:8888/loyalty/services/LoyaltyService?WSDL"/> <property name="namespaceUri" value="http://host:8888/loyalty/services/LoyaltyService"/> <property name="serviceName" value="LoyaltyService"/> <property name="portName" value="LoyaltyPort"/> </bean> |
Page Visitors: 4713

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023