1.1. Hessian Introduction
Hessian:hessian is a lightweight remoting onhttp tool that provides RMI functionality in a simple way, simpler and faster than Webservice,hessian. The use of the binary RPC protocol, because the use of binary protocol, it is very suitable for sending binary data, Hessian mainly for object-oriented message communication.
1.2. Development step 1.2.1. Importing JAR Packages
Go to the official website to download http://hessian.caucho.com/
1.2.2. Writing a remote interface
Ihello.java |
Package Cn.tempus.hessian; Public interface Ihello { Public String SayHello (string name); } |
1.2.3. Writing a remote interface implementation class
Helloimpl.java need to inherit Hessianservlet |
Package Cn.tempus.hessian; import Com.caucho.hessian.server.HessianServlet; Public class Helloimpl extends hessianservlet implements Ihello { private static final long serialversionuid =- 6448991611447150108L; Public String SayHello (string name) { return "Hello:"+name; } } |
1.2.4 Configuring a servlet in a. web. xml file
Xml |
<? XML version="1.0" encoding="UTF-8"?> < web-app < Span style= "Color:rgb (127,0,127)" >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 > Hessiandemo</display-name> < servlet > < Servlet-name > Hello</servlet-name> < Servlet-class >com.caucho.hessian.server.HessianServlet</servlet-class> < Init-param > < Param-name >home-class</param-name> < Param-value >cn.tempus.hessian.HelloImpl</param-value> </ Init-param > < Init-param > < Param-name >home-API</param-name> < Param-value >cn.tempus.hessian.IHello</param-value> </ Init-param > < Load-on-startup >1</load-on-startup> </ servlet > < servlet-mapping > < Servlet-name > Hello</servlet-name> < Url-pattern >/hello</url-pattern> </ servlet-mapping > </ Web-app > |
1.2.5. Writing a client
Client.java |
Package Cn.tempus.hessian; import java.net.MalformedURLException; import com.caucho.hessian.client.HessianProxyFactory; Public class Client { Public static String URL = "Http://127.0.0.1:8080/HessianDemo/Hello"; Public static void main (string[] args) { Hessianproxyfactory Factory = new hessianproxyfactory (); Try { Ihello Ihello = (Ihello) factory. Create (Ihello. Class, URL); System. out. println (Ihello. SayHello ("Morris")); } Catch (malformedurlexception e) { e. Printstacktrace (); } } } |
1.2.6. Publish Project to Jetty
Jetty Background Printing |
Running Jetty 6.1.26 2014-12-29 16:09:27.234:info::logging to STDERR via Org.mortbay.log.StdErrLog Parentloaderpriority enabled Context Path:/hessiandemo Projectclassloader:entry=d:\morris\javaprj\hessiandemo\build\classes Projectclassloader:entry=d:\morris\javaprj\hessiandemo\webcontent\web-inf\lib\hessian-4.0.37.jar 2014-12-29 16:09:27.500:info::jetty-6.1.26 2014-12-29 16:09:29.328:info::started [Email protected]:8080 |
1.2.7. Running the client
The results are as follows:
Hello:morris
Hessian Introductory case