as mentioned earlier, RMI uses the Java standard object serialization mechanism, but it is difficult to penetrate firewalls. on the other hand, hessian and burlap can penetrate firewalls well, but use private object serialization mechanisms.
The HTTP Invker provided by spring is a new remote invocation model that, as part of the spring framework, is capable of executing HTTP-based remote calls (making firewalls awkward) and using the Java serialization mechanism (which makes developers optimistic about their changes).
Spring's Httpinvoker combines the simplicity of HTTP with the built-in Java object serialization mechanism. This makes Httpinvoker an alternative to the RMI Hessian burlap option
But there is one limitation: it is just a remote invocation scenario provided by a spring framework, which means that the client and server must be spring applications. and indicates that both the client and the server are Java-based. In addition, using the Java serialization mechanism, the client and server must use the same version of the class.
To export the bean as an RMI service, we use the Rmiserviceexporter
To export the bean as a Hessian service, we use the Hessianserviceexporter
To export the bean as a burlap service, we use the Burlapserviceexporter
Then export the HTTP invoker service using Httpinvokerserviceexporter
The configuration process is identical to the Hessian, burlap
Service side:
Webconfig.java (add httpinvokerserviceexporter configuration and bind URL mappings)
@Bean Publichandlermapping Mapping () {System. out. println ("-->mapping"); Simpleurlhandlermapping Mapping=Newsimpleurlhandlermapping (); Properties Mappings=NewProperties (); //mappings.setproperty ("/burlap.ser", "Burlapservice"); //the name of the Url,bean to which the bean is bound (burlapservice) must correspond to the//mappings.setproperty ("/hessian.ser", "Hessianservice");Mappings.setproperty ("/httpinvoker.ser","Httpinvokerserver"); Mapping.setmappings (mappings); returnmapping; } @Bean (Name="Httpinvokerserver") Publichttpinvokerserviceexporter httpinvokerserver (personserver personserver) {System. out. println ("-->httpinvokerserver"); Httpinvokerserviceexporter Invoker=NewHttpinvokerserviceexporter (); Invoker.setserviceinterface (personserver.class); Invoker.setservice (Personserver); returnInvoker; }
Client:
Package Com.mvc.wzy;import Org.springframework.context.annotation.bean;import Org.springframework.context.annotation.configuration;import Org.springframework.remoting.httpinvoker.httpinvokerproxyfactorybean;import com.mvc.server.PersonServer;@ Configuration Public classHttpinvokercontext {@Bean PublicHttpinvokerproxyfactorybean Httpproxyfactorybean () {Httpinvokerproxyfactorybean B=NewHttpinvokerproxyfactorybean (); B.setserviceurl ("Http://localhost:8080/Springmvc/httpInvoker.ser"); B.setserviceinterface (personserver.class); returnb; }}
Test:
// spring load applicationcontext app = // new Annotationconfigapplicationco ntext (com.mvc.wzy.HessianContext.class); // new Annotationconfigapplicationcontext (com.mvc.wzy.BurlapContext.class); new Annotationconfigapplicationcontext (Com.mvc.wzy.httpinvokercontext. Class ); Personserver p = App.getbean (Personserver. Class ); System. out .println (P.getmsg ()); System. out . println (P.getperson ());
Results:
Spring Remote Call Technology <3>-spring HTTP Invoker