diff --git a/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HelloImpl.java b/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HelloImpl.java index 53128fe..3c71f0e 100644 --- a/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HelloImpl.java +++ b/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HelloImpl.java @@ -13,6 +13,14 @@ public void say() { } public void exception(){ + try { + throwException(); + }catch(RuntimeException e) { + throw new UnsupportedOperationException("unsupported",e); + } + } + + private void throwException() { throw new RuntimeException("server error"); } } \ No newline at end of file diff --git a/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HessianTest.java b/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HessianTest.java index dc24a89..c989e3d 100644 --- a/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HessianTest.java +++ b/rapid-core/src/test/java/cn/org/rapid_framework/hessian/HessianTest/HessianTest.java @@ -1,20 +1,18 @@ package cn.org.rapid_framework.hessian.HessianTest; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.servlet.http.HttpServletRequest; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import org.apache.commons.lang.RandomStringUtils; -import org.apache.commons.lang.math.RandomUtils; import org.junit.Test; import cn.org.rapid_framework.distributed.threadlocal.DistributedThreadLocal; import cn.org.rapid_framework.distributed.threadlocal.hessian.DistributedThreadLocalHessianConnectionFactory; -import com.caucho.hessian.client.HessianConnection; import com.caucho.hessian.client.HessianProxyFactory; +import com.caucho.hessian.io.Hessian2Input; +import com.caucho.hessian.io.Hessian2Output; +import com.caucho.hessian.io.SerializerFactory; public class HessianTest { @@ -28,10 +26,31 @@ public void test() throws Exception { HessianProxyFactory factory = new HessianProxyFactory(); factory.setConnectionFactory(new DistributedThreadLocalHessianConnectionFactory( factory.getConnectionFactory())); - + factory.setSerializerFactory(new SerializerFactory(){ + }); Hello hello = (Hello) factory.create(Hello.class, url); hello.say(); -// hello.exception(); + try { + hello.exception(); + }catch(UnsupportedOperationException e) { + System.out.println("error:"+e); + e.printStackTrace(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + Hessian2Output out = new Hessian2Output(bos); + out.startMessage(); + out.writeObject(e); + out.completeMessage(); + out.close(); + + Hessian2Input in = new Hessian2Input(new ByteArrayInputStream(bos.toByteArray())); + in.startMessage(); + Exception fromInput = (Exception)in.readObject(); + in.completeMessage(); + in.close(); + + fromInput.printStackTrace(); + } // JettyServer.stop(); }