Hessian is a BINARY-RPC-based remote communications library provided by Caucho, which supports multiple languages, including c++,java,c#, and also supports Flash/flex Jetty as an open-source servlet container. It is designed as a servlet container that can be embedded in other Java code. By combining jetty and Hessian, you can provide remote communication services through a common Java project, without having to build a Web project to first write interfaces and service classes
Public Interface Hello {string SayHello (string name);}
import Com.caucho.hessian.server.HessianServlet;/** * @author cjj**/ Public classHelloimpl extends Hessianservlet implements Hello {/****/Private StaticFinalLongSerialversionuid =1464625224364842441L; @Override Publicstring SayHello (string name) {return"Hello:"+name;}}
Helloimpl Inherit Hessianservlet service startup class:
Import Org.eclipse.jetty.server.server;import Org.eclipse.jetty.servlet.servletcontexthandler;import Org.eclipse.jetty.servlet.servletholder;import Org.prime.jerryhessian.service.HelloImpl;/** * @author cjj**/ Public classOneservletcontext { Public Static voidMain (string[] args) throws Exception {Server server=NewServer (8080); Servletcontexthandler Context=NewServletcontexthandler (servletcontexthandler.sessions); Context.setcontextpath ("/"); Server.sethandler (context); Context.addservlet (NewServletholder (NewHelloimpl ()),"/hello"); Server.start (); Server.join ();}}
The client code is:
Import Java.net.malformedurlexception;import Org.prime.jerryhessian.service.hello;import Com.caucho.hessian.client.HessianProxyFactory;/** * @author cjj**/ Public classHellotest {/** * @param args * @throws malformedurlexception*/ Public Static voidMain (string[] args) throws Malformedurlexception {Hessianproxyfactory Factory=Newhessianproxyfactory (); Hello Hello= (hello) factory.create (hello).class,"Http://127.0.0.1:8080/hello"); System. out. println (Hello.sayhello ("CJJ"));}}
Operation Result:
Combination of jetty and Hessian