Spring Remote Call on the seventh day

Source: Internet
Author: User
Tags stock prices wsdl

RMI Remote Call
Rmi_spring (remote is not inherited in the interface and can be associated here). You can set it in three places.
1. config. XML (associated with RMI settings)
<Bean id = "userservice" class = "example. chapter8.userserviceimpl"/> object class Association
<Bean id = "rmiservice" class = "org. springframework. remoting. RMI. rmiserviceexporter">
<Property name = "servicename" value = "userservice"/> used by the customer
<Property name = "service" ref = "userservice"/> RMI and class Association
<Property name = "serviceinterface" value = "example. chapter8.userservice"/> interface Association
<Property name = "registryport" value = "1099"/> used by the customer
</Bean>

2. Start RMI
Public class main {
Public static void main (string [] ARGs ){
New classpathxmlapplicationcontext ("config. xml ");
}
}

3. Client usage
Package example. chapter8.client;
Import org. springframework. remoting. RMI. rmiproxyfactorybean;
Import example. chapter8.userservice;
Public class client {
Public static void main (string [] ARGs) throws exception {
Rmiproxyfactorybean factory = new rmiproxyfactorybean ();
Factory. setserviceinterface (userservice. Class );
Factory. setserviceurl ("RMI: // localhost: 1099/userservice ");
Factory. afterpropertiesset ();
Userservice = (userservice) Factory. GetObject ();
Userservice. Create ("test", "password ");
System. Out. println (userservice. login ("test", "password "));
Try {
Userservice. login ("test", "Bad-Password ");
}
Catch (exception e ){
System. Out. println (E. getmessage ());
}
}
}

 

 

 

 

The biggest drawback of RMI is that the specific jrmp (Java remote method protocol, Java remote
Method protocol) binary protocol, it is difficult to penetrate the firewall, public is suitable for use in the enterprise intranet. If a firewall call is required, the HTTP protocol is almost the only choice.
Spring supports three types of HTTP remote calls: Hessian, burlap, and HTTP invoker.
Hessian and burlap are integrated in the Resin server and can be directly used.
Hessian is a binary protocol (highly efficient but hard to understand), while burlap is an XML-based protocol. Other languages can use bulap to communicate with Java programs as long as they can parse XML. These two protocols are private protocols and have not become a standard. Therefore, they are only suitable for calling through firewalls in Java systems.

Remote Call of the HTTP protocol (take Hessian for example, other methods are similar)
Server (including timeservice interface and timeserviceimpl class)
1 Join
<Bean id = "timeservice" class = "example. chapter8.timeserviceimpl"/>
<Bean name = "/hessianservice" class = "org. springframework. remoting. Caucho. hessianserviceexporter">
<Property name = "service" ref = "timeservice"/>
<Property name = "serviceinterface" value = "example. chapter8.timeservice"/>
</Bean>

Web. XML (URL style defined as/remote /*)
<Web-app>
<Servlet>
<Servlet-Name> dispatcher </servlet-Name>
<Servlet-class> org. springframework. Web. servlet. dispatcherservlet </servlet-class>
<Load-on-startup> 0 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-Name> dispatcher </servlet-Name>
<URL-pattern>/remote/* </url-pattern>
</Servlet-mapping>
</Web-app>
2. Have you not started RMI? (This step is not used for HTTP remote calls .)
Client
2. Use config. xml
<Bean id = "hessianservice" class = "org. springframework. remoting. Caucho. hessianproxyfactorybean">
<Property name = "serviceurl" value = "http: // localhost: 8080/remote/hessianservice"/> // It consists of the style definition on the server side and bean name.
<Property name = "serviceinterface" value = "example. chapter8.timeservice"/>
</Bean>

Timeservice service = (timeservice) Context. getbean ("hessianservice ");
Service. gettime ();

 

 

 

Web Services
One is the technical standard for cross-platform remote calls, that is, the application exposes an API interface that can be remotely called through the Web to the outside world, the client can call this service interface to implement the corresponding functions.
We can regard web services as Internet-based remote calls. With Web Services, Web websites and web websites are no longer simply linked, but Web applications that can call each other.
Web services are a service-oriented architecture technology. XML is a platform-independent descriptive language. Therefore, XML is used to describe how to transmit data in Web Services. In this way, both parties can be any heterogeneous platform.

2. Web services can be applied in the following fields:
1. enterprise-oriented web services, including the integration of various ERP systems within the enterprise and systems of inter-enterprise partners. Because large enterprises often use heterogeneous platforms, it is very appropriate to use web services to implement system integration.
2. Consumption-oriented web services, especially B2C websites. Through Web Services, third-party desktop applications can provide users with more convenient services. For example, personal financial software can obtain the latest stock prices through Web Services.
3. Web Services for terminal devices. Various mobile terminals, including mobile phones and PDAs, can easily implement weather forecasts, hotel reservations, and other services through services.

Three implementations:
Web Service caller <------- (obtain the wdsl file) WSDL file <------- (publish the WSDL file) web service publisher
-------------------------------------------------------------> (Send a SOAP request)
(Return SOAP request) <---------------------------------------------------------

The WSDL file, Web Services Description Language, defines all information about calling the Web Service, including the ing of all method names, parameter types, return types, and data types.

The Web Service caller can generate client support classes based on the WSDL file as long as the WSDL file.

4. To implement web services in Java, you must also obtain a specific implementation. Axis and xfire both implement the complete Web Server
Service Agreement library. It can be used to access and publish Web Services.

1. axis (Exercise callamozonws on the network and check the composition of the WSDL file)
To call a web service, you must know the URL of the WSDL file (including all the information for calling the Web service), and use
Wsdl2java automatically generates client support classes based on WSDL.

Conclusion: It is only used in the enterprise intranet, and both parties are Java platforms. You can consider using RMI. For example, you need to call it over the Internet or the two parties are heterogeneous systems, web services are almost the only choice.

 

 

 

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.