Java Jetty 结合 hessian 使用小例子

来源:互联网 发布:淘宝哪家店羊绒布料好 编辑:程序博客网 时间:2024/05/18 00:42
Servercode:import org.eclipse.jetty.server.Server;import org.eclipse.jetty.servlet.ServletContextHandler;import org.eclipse.jetty.servlet.ServletHolder;public class HessianTest {public static void main(String[] args) throws Exception {Server server = new Server(8080);ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);server.setHandler(context);ServletHolder servletHolder = new ServletHolder(new BasicService());context.addServlet(servletHolder, "/test");server.start();server.join();}}Basic interface:public interface Basic {public String hello();}Basic implementation:public class BasicService extends HessianServlet implements Basic {public String hello() {return "Hello! It works!";}}Client application:import com.caucho.hessian.client.HessianProxyFactory;public class HessianClient {public static void main(String[] args) throws Exception {HessianProxyFactory factory = new HessianProxyFactory();Basic basic = (Basic) factory.create(Basic.class,"http://myhost:8080/test");System.out.println("Hello: " + basic.hello());}}

0 0
原创粉丝点击