Degrees Niang said:
Hessian is a lightweight remoting onhttp tool that provides RMI functionality using simple methods. Simpler and quicker than Webservice,hessian. The binary RPC protocol is used because the binary protocol is used, so it is ideal for sending binary data.
Learn with an example:
1. A new Web project, used to do the service side, here is named: HessianServer1;
2. Put jar bag into web-inf/lib, use hessian-4.0.7.jar here;
3. Modify the Web.xml configuration as follows:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http:// Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "> <display-name>hessainserver1 </display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome- File>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file> Default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file> Default.jsp</welcome-file> </welcome-file-list> <!--not integrated spring--> <servlet> <se Rvlet-name>hessian-service</servlet-name> <servlet-class> Com.caucho.hessian.server.hessianservlet</servlet-class> <init-param> <param-name>home-class≪/param-name> <param-value> <!--service Implementation class--> Com.cmsz.upay.hessian.service.impl.HelloServi Ceimpl </param-value> </init-param> <init-param> <param-name>home-api</p Aram-name> <param-value> <!--service Implementation Interface--> Com.cmsz.upay.hessian.service.HelloService & lt;/param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>hes sian-service</servlet-name> <url-pattern>/hessian</url-pattern> </servlet-mapping> </w Eb-app>
3. Create a new interface, Helloservice.java:
Public interface HelloService {public
string HelloWorld (String msg);
4. Create a new implementation class, Helloserviceimpl.java
public class Helloserviceimpl implements HelloService {
@Override public
string HelloWorld (String msg) {
Return "Hello" + msg;
}
5. Create a new Java Project, used to do the client, here named HessianClient1;
6. The jar package required to import hessian, here with Hessian-4.0.7.jar;
7. The introduction of services to provide services to the class (accurate interface, interface-oriented programming), So you need to put the server-side Helloservice.java code on the client, you can use the server Helloservice.java packaged into a jar package, you can also copy Helloservice.java code to the client, you can directly refer to the server side of the project (This method is limited to server-side client code in the same workspace), where the last method is suggested, using the first two methods;
8. Write Test class:
public class Servicetest {
@Test public
void Testhelloservice () {
try {
String url = ' http://localhost : 28080/hessianserver1/hessian ";
System.out.println (URL);
Hessianproxyfactory factory = new Hessianproxyfactory ();
HelloService service = (HelloService) factory.create (helloservice.class, url);
System.out.println (Service.helloworld ("test!"));
} catch (Exception e) {
e.printstacktrace ();}}}
9. Deploy HessianServer1 to Tomcat, start Tomcat, test the client, and the results are as follows:
Summarize:
A few places to note:
1. The author's Tomcat port is 28080, so
String url = "Http://localhost:28080/HessianServer1/hessian";
2. The service-side project name is HessionServer1, so
String url = "Http://localhost:28080/HessianServer1/hessian";
3. The service-side web.xml are as follows:
<url-pattern>/hessian</url-pattern>
So
String url = "Http://localhost:28080/HessianServer1/hessian";
Code path: CSDN