spring remote call

1. Overview of Spring remote invocation

1. To publish some available functions of an application as remote services and provide them for use by other applications, we need to publish the basic functions of this application interface as remote services.

 

2. Spring supports several different RPC models including

rmi, access/publish java-based services regardless of network restrictions (hard to get through firewalls because rmi uses arbitrary ports to interact)

hessian, burlap, accessing/publishing java-based services via http when considering network constraints

http invoker, considering network constraints and wishing to access/publish spring-based services using xml-based or proprietary java serialization mechanisms

jax-rpc and jax-ws access/publish platform-neutral, soap-based web services.

 

3. In all models, remote services are proxied, so they can be wired into client code like other spring beans. Remote calls will throw remoteAccessException exception.

 

2. Use RMI

(1) Configure RMI service: RmiServiceExporter can publish any Spring-managed bean as an RMI service. The RmiServiceExporter works by wrapping a bean into a service adapter and binding the service adapter to the RMI registry. Thus converting the POJO to an RMI service.

<bean class = "org.springframework.remoting.rmi.RmiSeriviceExporter"

p:service-ref = "spitterService"

p:serviceName = "SpitterService"

p:serviceInterface = "Interface full name"

p:registryHost = “rmi.spitter.com”

p:registryPort = "1199" />

 

(2) Assembling the RMI 

Spring's RmiProxyFactoryBean is a factory bean that can create proxies for rmi services. Using RmiProxyFactoryBean to reference a SpitterService's RMI service is very simple

<bean id = "spitterService" class = "org.springframework.remoting.rmi.RmiProxyFactoryBean" p:serviceUrl = "rmi://localhost/spitterService" 

p:serviceInterface = "com.habuma.spitter.service.SpitterService"> 

 

3. Use hessian and burlap to publish remote services: It is a lightweight remote service solution based on http. The message of hession is binary, while the message of burlap is xml.

 

Fourth, using spring's httpinvoker, because rmi uses the java standard object serialization mechanism, it is difficult to penetrate the firewall. Hession and burlap can penetrate firewalls well, but use a proprietary object serialization mechanism.

1. To export the bean as an http invoker service, we need to use httpinvokerserivceExporter

<bean id=httpInvokerSpitterService class = "org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"

p:service-ref = "spitterService"

p:serviceInterface="com.habuma.spitter.service.SpitterService">

 

2. httpinvokerserivceeExporter is a Spring MVC controller that receives requests from clients through DispatcherServlet and converts these requests into method calls to pojos that implement services. So we need to build a url handler. Map the http url to the corresponding server.

<bean id = "urlMapping" class = "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

   <property name = "mappings">

      <value>

       /spitter.service = httpInvokerSpitterService

      </value>

    </property>

</bean>

 

5. Publish and use web services (use spring's support for JAX-WS to publish the Spitter service as a web service and use this web service), use the jax-ws service exporter to create a web service, and spring provides a jax-ws service exporter

1: Autowire jax-ws endpoints in spring

The jax -ws programming model uses annotations to declare classes and class methods as operations for web services. Classes annotated with the @webservice annotation are considered web service endpoints, while methods annotated with the @webmethod annotation . But must inherit springbeanautowiringsupport

 

2: Export the standalone jax-ws endpoint: 

 

3: Proxy the jax-ws service on the client side:

Using spring to publish web services is completely different from our use of rmi, hessian, buralp and http invoker to publish services.

But the client proxies involved in accessing web services using Spring work in the same way that Spring-based clients use other remote invocation techniques.

 

Using JaxWsPortProxyFactoryBean, we can wire the spitter web service in spring just like any other bean. jaxwsportproxyfactorybean is a spring factory bean. It generates a proxy that interacts with soap web.

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326590917&siteId=291194637