Combination of jetty and Hessian

Source: Internet
Author: User

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

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.