Spring Remote Call Technology <3>-spring HTTP Invoker

Source: Internet
Author: User
Tags object serialization serialization

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; }


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; }}


 // 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 ()); 


Spring Remote Call Technology <3>-spring HTTP Invoker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.