hessian 3.1.5的bug及相关例子

作者:lizongbo 发表于:10:26 下午. 星期六, 4月 12th, 2008
版权声明:可以任意转载,转载时请务必以超链接形式标明文章和作者信息及本版权声明

hessian 3.1.5的下载地址在:
http://hessian.caucho.com/download/hessian-3.1.5.jar
http://hessian.caucho.com/download/hessian-3.1.5-src.jar
http://hessian.caucho.com/download/hessian-test.jar

来源: http://hessian.caucho.com/#Java

假如客户端以Hessian2协议进行传输数据,以HessianMetaInfoAPI接口方式调用_hessian_getAttribute方法。
那么com.caucho.hessian.server.HessianSkeleton.java里, 在调用的 第  160行的地方,缺少一句  out.close();

其它几个return的地方,也缺少 out.close();

否则会遇到如下的错误信息

Caused by: com.caucho.hessian.io.HessianProtocolException: expected hessian reply at end of file
?
at com.caucho.hessian.io.Hessian2Input.error(Hessian2Input.java:2701)
at com.caucho.hessian.io.Hessian2Input.startReply(Hessian2Input.java:405)
at com.lizongbo.hessian.client.HessianProxy.invoke(HessianProxy.java:65)

独立使用 HessianSkeleton进行处理的时候,

//HessianSkeleton hs=null;
//Hessian2Input h2i=null;

try {
h2i.readCall(); //这行代码非常重要,否则无法正确调用invokeHessianServlet里有类似的调用
// 对应的是   int code = in.read();
//     int major = in.read();
//      int minor = in.read();

//如果不调用该行代码,则Hessian2Input无法解析出数据包
hs.invoke(h2i, h2o);
} catch (Exception e) {
e.printStackTrace();
}

HessianDebugOutputStream存在bug,如果在HessianServlet开启调试模式,则会抛出异常。

调用出错的接口方法是这样定义的:

public java.sql.Date getDay();
HessianDebugOutputStream的代码比较复杂,由于对hessian协议定义不够熟悉,没找到修正bug的方法。

下面是用mina封装后以TCP方式调用hessian的例子
————–

[code]
package com.lizongbo.hessian.server.handlers;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

import org.apache.mina.common.IoSession;

import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
import com.caucho.hessian.server.HessianSkeleton;
import com.lizongbo.hessian.HessianPacketHandler;
import com.lizongbo.hessian.message.HessianCall;
import com.lizongbo.hessian.message.HessianCallResp;
import com.lizongbo.hessian.message.HessianPacket;
import com.lizongbo.hessian.test.Mytest;
import com.lizongbo.hessian.test.Test;
import com.caucho.hessian.io.HessianDebugInputStream;
import java.io.PrintWriter;
import com.caucho.hessian.io.HessianDebugOutputStream;
import com.lizongbo.hessian.BadCommandIDException;

public class HessianCallhandler implements HessianPacketHandler {
private Map<String, HessianSkeleton> hsmap = new HashMap();

public void process(IoSession session, HessianPacket packet) throws
BadCommandIDException {
HessianCall msg = (HessianCall) packet;
if (hsmap.get(msg.getUrl()) == null) {
Test t = new Mytest();
HessianSkeleton hs = new HessianSkeleton(t, Test.class);
hsmap.put(msg.getUrl(), hs);
}

HessianSkeleton hs = hsmap.get(msg.getUrl());
InputStream bai = new ByteArrayInputStream(msg.getCallData());
PrintWriter dbg = new PrintWriter(System.out);
bai = new HessianDebugInputStream(bai, dbg); //增加调试输出,如果不需要调试,则屏蔽该行即可。
Hessian2Input h2i = new Hessian2Input(bai);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
////OutputStream bao2 = new HessianDebugOutputStream(bao, dbg); //增加调试输出,如果不需要调试,则屏蔽该行即可。
Hessian2Output h2o = new Hessian2Output(bao);
try {
h2i.readCall();
hs.invoke(h2i, h2o);
} catch (Exception e) {
e.printStackTrace();
}
HessianCallResp callRes = new HessianCallResp();
callRes.setResData(bao.toByteArray());
session.write(callRes);

}

}

[/code]

Tags: , apache mina, Hessian, RPC

Related posts

Tags: , , ,

recent related 12 searches :

本文发表于 on 星期六, 4月 12th, 2008 at 10:26 下午 and is filed under Hessian, RPC. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

One Response to “hessian 3.1.5的bug及相关例子”

  1. 飞飞 说:

    hessian 3.1.5的bug及相关例子 这个例子当用有一些package这里没有啊,可以把整个project给我一份么,谢谢啊!yolandasun2008@gmail.com
    import com.lizongbo.hessian.HessianPacketHandler;
    import com.lizongbo.hessian.message.HessianCall;
    import com.lizongbo.hessian.message.HessianCallResp;
    import com.lizongbo.hessian.message.HessianPacket;
    import com.lizongbo.hessian.test.Mytest;
    import com.lizongbo.hessian.test.Test;
    import com.lizongbo.hessian.BadCommandIDException;

    [Reply]

Leave a Reply