Hessian是由caucho提供的一个基于binary-RPC实现的远程通讯library,支持多种语言,包括c++,java,c#等,还支持flash/flex     Jetty 是一个开源的servlet容器,它是作为一个可以嵌入到其他的Java代码中的servlet容器而设计的。     通过结合jetty和hessian结合,就可以通过一个普通的java工程来提供远程通信服务,而不需要建立一个web工程     首先编写接口和服务类

public interface Hello {

String sayHello(String name);
}
import com.caucho.hessian.server.HessianServlet;

/**
 * @author cjj
*
*/
public class HelloImpl extends HessianServlet implements Hello {

/**

*

*/

private static final long serialVersionUID = 1464625224364842441L;

@Override

public String sayHello(String name) {

return"hello:"+name;

}

}

HelloImpl 继承 HessianServlet 服务启动类:

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 class OneServletContext {

public static void main(String[] args) throws Exception {

Server server = );

ServletContextHandler context = new ServletContextHandler(

ServletContextHandler.SESSIONS);

context.setContextPath("/");

server.setHandler(context);

context.addServlet(new ServletHolder(new HelloImpl()),"/hello");

server.start();

server.join();

}

}

客户端代码为:

import java.net.MalformedURLException;

import org.prime.jerryhessian.service.Hello;

import com.caucho.hessian.client.HessianProxyFactory;

/**
 * @author cjj
*
*/
public class HelloTest {

/**

 * @param args

 * @throws MalformedURLException 

*/

public static void main(String[] args) throws MalformedURLException {

HessianProxyFactory factory = new HessianProxyFactory();

Hello hello = (Hello) factory.create(Hello.class,

"http://127.0.0.1:8080/hello");

System.out.println(hello.sayHello("cjj"));

}

}

运行结果:

jetty与hessian结合的更多相关文章

  1. Hessian 初探

    Hessian 是一个序列化协议, 他的优点在于比 Java 原生的对象序列化/反序列化速度更快, 序列化出来以后的数据更小. 序列化协议跟应用层协议无关, 可以将 Hessian 序列化以后的数据放 ...

  2. 配置jetty 远程调试

    该调试不支持hessian 接口调用 1.配置远程jetty 服务器的 bin/jetty.sh JAVA_OPTIONS+=("-Xdebug -Xrunjdwp:server=y,tra ...

  3. maven + hessian 简单样例

    项目结构例如以下: pom.xml 内容: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&quo ...

  4. dubbo_实现Hessian的远程调用协议

    1.优点 连接个数:多连接 连接方式:短连接 传输协议:HTTP 传输方式:同步传输 序列化:Hessian二进制序列化 适用范围:传入传出参数数据包较大,提供者比消费者个数多,提供者压力较大,可传文 ...

  5. Dubbo服务 上传文件解决方案以及Hessian协议

    ​ 协议支持 Dubbo支持多种协议,如下所示: Dubbo协议 Hessian协议 HTTP协议 RMI协议 WebService协议 Thrift协议 Memcached协议 Redis协议 在通 ...

  6. spring remoting源码分析--Hessian分析

    1. Caucho 1.1 概况 spring-remoting代码的情况如下: 本节近分析caucho模块. 1.2 分类 其中以hession为例,Hessian远程服务调用过程: Hessian ...

  7. No plugin found for prefix ‘jetty’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories

    maven配置文件(最大的那个)的<pluginGroups></pluginGroups>增加一行如下<pluginGroups><pluginGroup& ...

  8. sorl6.0+jetty+mysql搭建solr服务

    1.下载solr 官网:http://lucene.apache.org/solr/ 2.目录结构如下 3.启动solr(默认使用jetty部署) 在path路径下将 bin文件夹对应的目录加入,然后 ...

  9. 嵌入式服务器jetty,让你更快开发web

    概述 jetty是什么? jetty是轻量级的web服务器和servlet引擎. 它的最大特点是:可以很方便的作为嵌入式服务器. 它是eclipse的一个开源项目.不用怀疑,就是你常用的那个eclip ...

随机推荐

  1. 利用dedecms autoindex让文章列表加上序列号

    有些时候我们在制作模板的需要在文章标题前面加上序列号,可以通过织梦自带的autoindex属性来实现,实现方法很简单,只需要在序号递增的地方加上 这段代码就行,[field:global runphp ...

  2. Linux下搭建svn服务器(转)

    原文地址:http://blog.163.com/longsu2010@yeah/blog/static/173612348201202114212933/ 安装步骤如下: 1.yum install ...

  3. C语言or和and运算

    #include <stdio.h> void main () { printf( | ); printf( | ); printf( | ); printf( | ); printf( ...

  4. spingMVC<1>-xml文件配置

    ---恢复内容开始---

  5. How can I style a JavaFX SplitMenuButton in CSS

    0 down vote favorite I try to style a SplitMenuButton in JavaFX. I've got a menuButton and a SplitMe ...

  6. ios7开发学习笔记-包括c oc 和ios介绍

    请查看我的新浪资料分享 http://iask.sina.com.cn/u/2430843520

  7. Linux时间不准确的问题![转]

    Linux时间不准确的问题![转] 安装完系统发现时间与现实时间相差+8小时,经分析由以下产生.我们在安装时选择的是上海,而centos5把bios时间认为是utc时间,所以+8小时给我们.这个时候的 ...

  8. 繁华模拟赛 David与阶乘

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...

  9. 基于网页内容数据采集 PHP开发学习笔记

    jQuery数字的截取: str.toFixed(num);//小数的截取 toFixed() <script type="text/javascript">  var ...

  10. win7 64位安装redis 及Redis Desktop Manager使用

    写基于dapper的一套自动化程序,看到 mgravell的另一个项目,StackExchange.Redis,之前在.NET上用过一段时间redis,不过一直是其它的驱动开发包,这个根据作者介绍,是 ...