欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Hessian,輕量級的Java Remoting方案

系統 1866 0

項目里遇到一個問題:由于安全性的需要,必須由一個程序專門負責查詢某一數據庫,然后通過安全的信道(例如HTTP)將查詢結果傳到安全區域之外的application。為了解決這個小小的remoting問題,我們差點要動用EJB。不過幸虧朋友推薦,找到了Hessian這個輕量級的remoting on http工具。

Hessian其實很像web service,只不過它的協議不是SOAP,而是它自己規定的binary協議。Hessian的server端提供一個servlet基類,client端獲得一個service接口(也就是stub)之后調用上面的方法,stub將方法調用marshal之后通過HTTP傳到server,server借助reflection調用service方法。

簡單、輕量。對付普通的remoting問題,Hessian足夠了。我們又可以暫時忘掉EJB和RMI了。

——————————

Hessian is a simple binary protocol for connecting web services. The com.caucho.hessian.client and com.caucho.hessian.server packages do not require any other Resin classes, so can be used in smaller clients, like applets.

Because Hessian is a small protocol, J2ME devices like cell-phones can use it to connect to Resin servers. Because it's powerful, it can be used for EJB services.

The Hessian home page contains the latest information about Hessian including the Hessian specification .

  1. Hessian Client
  2. Hessian Service
  3. Hessian Client for a cell-phone
  4. Hessian Serialization

Hessian Client
Using a Hessian service from a Java client is like calling a method. The HessianProxyFactory creates proxies which act like normal Java objects, with possibility that the method might throw a protocol exception if the remote connection fails. Using HessianProxyFactory requires JDK?1.3.

Each service will have a normal Java interface describing the service. The trivial hello, world example just returns a string. Because the Hessian services support Java serialization, any Java type can be used.

API for Basic service
              package hessian.test;public interface Basic {  public String hello();}
            

The following is an example of a standalone Hessian client. The client creates a HessianProxyFactory. The client uses the factory to create client stubs with the given target URL and a Java interface for the API. The returned object is a stub implementing the API.

Hessian Client for Basic service
              package hessian.test;import com.caucho.hessian.client.HessianProxyFactory;public class BasicClient {  public static void main(String []args)    throws Exception  {    String url = "http://www.caucho.com/hessian/test/basic";    HessianProxyFactory factory = new HessianProxyFactory();    Basic basic = (Basic) factory.create(Basic.class, url);    System.out.println("Hello: " + basic.hello());  }}
            
That's it! There are no more complications to using the client. The service can add methods and use any Java type for parameters and results.

Hessian Service
While most Hessian services will use Resin-CMP or Resin-EJB, to take advantage of the benefits of EJB, the Hessian library makes it possible to write services by extending HessianServlet.

Any public method is treated as a service method. So adding new methods is as easy as writing a normal Java class.

Because the service is implemented as a Servlet, it can use all the familiar servlet data in the ServletContext, just like a normal servlet.

Hello Service
              package hessian.test;import com.caucho.hessian.server.HessianServlet;public class BasicService extends HessianServlet implements Basic {  public String hello()  {    return "Hello, world";  }}
            

Hessian Client for a cell-phone
Hessian can be used for even small Java devices. The following classes from com.caucho.hessian.client can be extracted into a J2ME jar:
  • MicroHessianInput
  • MicroHessianOutput
  • HessianRemote
  • HessianServiceException
  • HessianProtocolException
The following example shows the code for using a cell phone as a client. It's a bit more complicated than using the proxy, since the client is responsible for creating the connection and writing the data.

Hello, world
              import javax.microedition.io.Connector;import javax.microedition.io.HttpConnection;...MicroHessianInput in = new MicroHessianInput();String url = "http://www.caucho.com/hessian/test/basic";HttpConnection c = (HttpConnection) Connector.open(url);c.setRequestMethod(HttpConnection.POST);OutputStream os = c.openOutputStream();MicroHessianOutput out = new MicroHessianOutput(os);out.call("hello", null);os.flush();is = c.openInputStream();MicroHessianInput in = new MicroHessianInput(is);Object value = in.readReply(null);
            

Hessian Serialization
The Hessian classes can be used for serialization and deserialization.

Serialization
              Object obj = ...;OutputStream os = new FileOutputStream("test.xml");HessianOutput out = new HessianOutput(os);out.writeObject(obj);os.close();
            

Deserialization
              InputStream is = new FileInputStream("test.xml");HessianInput in = new HessianInput(is);Object obj = in.readObject(null);is.close();
            



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2436


Hessian,輕量級的Java Remoting方案


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲综合国产一区二区三区 | 日韩欧美一区二区三区视频 | 亚洲视频在线观看 | 色综合久久88中文字幕 | 麻豆精品传媒一二三区在线视频 | 成人深夜视频在线观看 | 色综合久久综合欧美综合 | 亚洲无线视频 | 68久久久久欧美精品观看 | 人人干人人爱 | 香蕉视频在线观看免费 | 久久婷婷av | 国产91精品黄网在线观看 | 哥斯拉大战金刚2在线观看免费完整版 | 日本精品一区二区三区在线 | 欧美日韩在线播放一区二区三区 | 成年人xxxx | 成人性生免费视频 | 日日摸夜夜摸狠狠摸日日碰夜夜做 | 久久1区 | 日本高清香蕉色视频在线观看 | 成年人在线免费 | 九九热视 | 日本欧美中文字幕人在线 | 日本娇小xxxxhd | 亚洲成年网站在线777 | 成年人国产网站 | 精品久久久久久久人人人人传媒 | 国产中文字幕在线 | 亚洲视频欧美视频 | 亚洲一区免费看 | 国产精品成人一区二区 | 精品一区二区三区不卡 | 黄色av片在线观看 | 国产午夜精品理论片影院 | 国产成人手机在线好好热 | 亚洲精品欧美视频 | 久久亚| 青娱乐精品在线 | 欧洲a老妇女黄大片 | 加勒比婷婷色综合久久 |