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 ...
随机推荐
- Apache配置默认首页
操作系统:CentOS 6.5 Apache默认主页为index.html,如果要修改为index.php或其它,需要修改httpd.conf文件 用vim或其它编辑器打开httpd.conf 在上图 ...
- 自定义NSLog无时间
#define SXLog(FORMAT, ...) fprintf(stderr,"file --\t%s\nline --\t%d\nmethd --\t%s\noutput --\t\ ...
- NoClassDefFoundError:aspectj/weaver/reflect/ReflectionWorld$Reflection
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: ...
- php的urlencode()URL编码函数浅析
URLEncode:是指针对网页url中的中文字符的一种编码转化方式,最常见的就是Baidu.Google等搜索引擎中输入中文查询时候,生成经过Encode过的网页URL. URLEncode的方 ...
- 繁华模拟赛 Vicent与游戏
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...
- 用firebug给firefox添加信任链接
在前文“firefox查看微信公众平台的数据分析时就出现不信任链接怎么办?”我们使用了导入证书的方法添加信任链接,有网友反映说证书导入不成功,这里用另外一种方法来实现:用firebug给firefox ...
- Ubuntu nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
在Ubuntu 12中启动刚安装好的Nginx,报错: nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 原因如下: ...
- poj3295
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10453 Accepted: 3967 Descri ...
- Linux Haproxy 安装和部署
一.Haproxy 安装 下载地址 http://pan.baidu.com/s/1mggViXE cd /usr/local tar xzvf haproxy-.tar.gz cd haproxy- ...
- Linux 磁盘的组成
基本结构 磁道,扇区,柱面和磁头数 硬盘最基本的组成部分是由坚硬金属材料制成的涂以磁性介质的盘片,不同容量硬盘的盘片数不等.每个盘片有两面,都可记录信息. 每个磁道被分成许多扇形的区域,每个区域叫一个 ...