jetty与hessian结合
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结合的更多相关文章
- Hessian 初探
Hessian 是一个序列化协议, 他的优点在于比 Java 原生的对象序列化/反序列化速度更快, 序列化出来以后的数据更小. 序列化协议跟应用层协议无关, 可以将 Hessian 序列化以后的数据放 ...
- 配置jetty 远程调试
该调试不支持hessian 接口调用 1.配置远程jetty 服务器的 bin/jetty.sh JAVA_OPTIONS+=("-Xdebug -Xrunjdwp:server=y,tra ...
- maven + hessian 简单样例
项目结构例如以下: pom.xml 内容: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&quo ...
- dubbo_实现Hessian的远程调用协议
1.优点 连接个数:多连接 连接方式:短连接 传输协议:HTTP 传输方式:同步传输 序列化:Hessian二进制序列化 适用范围:传入传出参数数据包较大,提供者比消费者个数多,提供者压力较大,可传文 ...
- Dubbo服务 上传文件解决方案以及Hessian协议
协议支持 Dubbo支持多种协议,如下所示: Dubbo协议 Hessian协议 HTTP协议 RMI协议 WebService协议 Thrift协议 Memcached协议 Redis协议 在通 ...
- spring remoting源码分析--Hessian分析
1. Caucho 1.1 概况 spring-remoting代码的情况如下: 本节近分析caucho模块. 1.2 分类 其中以hession为例,Hessian远程服务调用过程: Hessian ...
- 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& ...
- sorl6.0+jetty+mysql搭建solr服务
1.下载solr 官网:http://lucene.apache.org/solr/ 2.目录结构如下 3.启动solr(默认使用jetty部署) 在path路径下将 bin文件夹对应的目录加入,然后 ...
- 嵌入式服务器jetty,让你更快开发web
概述 jetty是什么? jetty是轻量级的web服务器和servlet引擎. 它的最大特点是:可以很方便的作为嵌入式服务器. 它是eclipse的一个开源项目.不用怀疑,就是你常用的那个eclip ...
随机推荐
- 初学structs2,结果类型简单示例
一.自定义结果处理类,structs.xml中package节点下加result-types节点,在result-types节点下配置result-type的属性.然后在配置的action中的resu ...
- DataFrame转矩阵Np-Array
DataFrame.as_matrix(columns=None)¶ Convert the frame to its Numpy-array representation.
- Iterator&Vector应用实例
public class test1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-gene ...
- HTTP协议详解(一直在用可是这篇太好了转一下)
引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...
- 电子技术中的dB
(所有内容来自网络: http://www.mscbsc.com/askpro/question13066) dB是功率增益的单位,表示一个相对值 分贝是用来表示 "功率"的数量对 ...
- linux在所有文件中查找某一个字符
# find <directory> -type f -name "*.c" | xargs grep "<strings>" < ...
- HDOJ 1524 A Chess Game
A Chess Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- CKEditor使用笔记
相关资源 1. 首页地址:http://ckeditor.com/ 2. 下载地址:http://ckeditor.com/download 3. SDK地址:http://sdk.ckeditor. ...
- PHP日期格式转时间戳
PHP 提供了函数可以方便的将各种形式的日期转换为时间戳,该类函数主要是: strtotime():将任何英文文本的日期时间描述解析为时间戳. mktime():从日期取得时间戳. strtotime ...
- Nginx图片剪裁模块探究 http_image_filter_module
官方地址:http://nginx.org/en/docs/http/ngx_http_image_filter_module.html 煮酒品茶:前半部安装和官方说明,后半部分实践 #yum ins ...