Archive for 4月 12th, 2008

hessian 3.1.5的bug及相关例子

星期六, 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

Openfire 3.5.0 提供了支持QQtransport的gateway

星期六, 4月 12th, 2008

http://618119.com/archives/2008/04/08/79.html

已经提到了 Openfire的相关链接。

http://www.igniterealtime.org/projects/openfire/plugins/gateway.jar

http://www.igniterealtime.org/projects/openfire/plugins.jsp

gateway的版本是 1.2.3,更新时间为: Apr 7, 2008

刚才经过测试是基本可用 的(只有基本的登录和文本聊天功能)。

不保证sparkopenfireQQtransport功能一定可用,有兴趣的可到openfire官方下载源码自行修改。

Tags: OpenFire, QQ, spark, xmpp

Related posts