java hessian 协议_hessian 协议 版本 兼容

环境 :

服务端:  hessian 4.0.38 , spring 4.3.6 ; spring文档指出spring4.0以上的版本只能使用hessian 4.0以上的版本

客户端: hessian3.1.5

异常 :

服务端没有异常 ,客户端请求服务端抛出以下异常,无法获取请求结果。

Caused by : com.caucho.hessian.io.HessianProtocolException: expected hessian reply at 0x48(H)

at com.caucho.hessian.io.Hessian2Input.error(Hessian2Input.java:2701)

at com.caucho.hessian.io.Hessian2Input.startReply(Hessian2Input.java:405)

at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:218)

分析 : 从异常可以看出服务端使用的是hessian2协议(Hessian2Input可以看出) ,客户端使用hessian1协议无法解析结果。

处理 : 让服务端和客户端使用同一版本的jar包;不能换包可以使用一下方法,重写org.springframework.remoting.caucho.HessianServiceExporter的doInvoke方法,实例如下:

importjava.io.IOException;importjava.io.InputStream;importjava.io.OutputStream;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.springframework.remoting.caucho.HessianServiceExporter;importcom.caucho.hessian.io.AbstractHessianInput;importcom.caucho.hessian.io.AbstractHessianOutput;importcom.caucho.hessian.io.Hessian2Input;importcom.caucho.hessian.io.Hessian2Output;importcom.caucho.hessian.io.HessianInput;importcom.caucho.hessian.io.HessianOutput;importcom.caucho.hessian.server.HessianSkeleton;public class ExporterService extendsHessianServiceExporter {//是否使用hessian2协议

private booleanenableHessian2;public booleanisEnableHessian2() {returnenableHessian2;

}public void setEnableHessian2(booleanenableHessian2) {this.enableHessian2 =enableHessian2;

}

@Overridepublic voidhandleRequest(HttpServletRequest request, HttpServletResponse response)throwsServletException, IOException {//可以进行权限拦截

super.handleRequest(request, response);

}

@Overrideprotected void doInvoke(HessianSkeleton skeleton, InputStream is, OutputStream os) throwsThrowable {//使用 hessian1协议

AbstractHessianInput in = newHessianInput(is);

AbstractHessianOutput out= newHessianOutput(os);//使用hessian2协议

if(isEnableHessian2()) {

in= newHessian2Input(is);

out= newHessian2Output(os);

}

skeleton.invoke(in, out);

}

}

参考 : http://blog.csdn.net/chjttony/article/details/6567511

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值