提交 8417bd21 编写于 作者: W william.liangf

DUBBO-39 增加hessian异常code的测试

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@272 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 81ad2786
......@@ -15,6 +15,8 @@
*/
package com.alibaba.dubbo.rpc.protocol.hessian;
import java.net.SocketTimeoutException;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
......@@ -25,8 +27,10 @@ import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.dubbo.rpc.protocol.AbstractInvoker;
import com.caucho.hessian.HessianException;
import com.caucho.hessian.client.HessianConnectionException;
import com.caucho.hessian.client.HessianConnectionFactory;
import com.caucho.hessian.client.HessianProxyFactory;
import com.caucho.hessian.io.HessianMethodSerializationException;
/**
* hessian rpc invoker.
......@@ -65,16 +69,37 @@ public class HessianRpcInvoker<T> extends AbstractInvoker<T> {
if (e != null) {
String name = e.getClass().getName();
if (name.startsWith(HESSIAN_EXCEPTION_PREFIX)) {
throw new RpcException("Failed to invoke remote service: " + getInterface() + ", method: "
RpcException re = new RpcException("Failed to invoke remote service: " + getInterface() + ", method: "
+ invocation.getMethodName() + ", cause: " + e.getMessage(), e);
throw setRpcExceptionCode(e, re);
}
}
return result;
} catch (RpcException e) {
throw e;
throw setRpcExceptionCode(e.getCause(), e);
} catch (HessianException e) {
throw setRpcExceptionCode(e, new RpcException("Failed to invoke remote service: " + getInterface() + ", method: "
+ invocation.getMethodName() + ", cause: " + e.getMessage(), e));
} catch (Throwable e) {
return new RpcResult(e);
}
}
private RpcException setRpcExceptionCode(Throwable e, RpcException re) {
if (e != null) {
if (e instanceof HessianConnectionException) {
re.setCode(RpcException.NETWORK_EXCEPTION);
if (e.getCause() != null) {
Class<?> cls = e.getCause().getClass();
if (SocketTimeoutException.class.equals(cls)) {
re.setCode(RpcException.TIMEOUT_EXCEPTION);
}
}
} else if (e instanceof HessianMethodSerializationException) {
re.setCode(RpcException.SERIALIZATION_EXCEPTION);
}
}
return re;
}
}
\ No newline at end of file
......@@ -80,9 +80,10 @@ public class HessianProtocolTest {
Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
HessianService client = proxyFactory.getProxy(invoker);
try {
client.timeOut(100000);
client.timeOut(6000);
fail();
} catch (RpcException expected) {
Assert.assertEquals(true, expected.isTimeout());
}finally{
invoker.destroy();
exporter.unexport();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册