Spring + Hessian 入门

Spring + Hessian 入门

Hessian是一个优秀的二进制远程过程调用框架,那么学习一下。

写了个Hello World,感觉还好,集成到Spring中没有发生过多的变化,顶多就是配置几个bean,然而就是跑不成功,折腾了几个小时,发生了PageNotFound错误,好,我去看看url mapping的配置,不管是使用默认的bean name url映射,还是明确指定都出现那个错误,现在想想主要的原因是没有手动mvn clean package,对于这个问题,我将刻骨铭心。

今天重新审视这个小小的demo,遇到了新的错误。server端没有报出错信息,client访问该服务的URL的时候垮了, java.io.IOException: Server returned HTTP response code: 500 for URL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Exception in thread "main" org.springframework.remoting.RemoteConnectFailureException: Cannot connect to Hessian remote service at [http://localhost:8080/hessian/remote/helloService.htm]; nested exception is com.caucho.hessian.client.HessianConnectionException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/hessian/remote/helloService.htm
at org.springframework.remoting.caucho.HessianClientInterceptor.convertHessianAccessException(HessianClientInterceptor.java:289)
at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:257)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy2.sayHi(Unknown Source)
at com.vonzhou.hello.TestHessianClient.main(TestHessianClient.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: com.caucho.hessian.client.HessianConnectionException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/hessian/remote/helloService.htm
at com.caucho.hessian.client.HessianURLConnection.sendRequest(HessianURLConnection.java:142)
at com.caucho.hessian.client.HessianProxy.sendRequest(HessianProxy.java:283)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:170)
at com.sun.proxy.$Proxy1.sayHi(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:248)
... 9 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/hessian/remote/helloService.htm
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1890)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1885)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1884)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1457)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at com.caucho.hessian.client.HessianURLConnection.sendRequest(HessianURLConnection.java:122)
... 17 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/hessian/remote/helloService.htm
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at com.caucho.hessian.client.HessianURLConnection.sendRequest(HessianURLConnection.java:109)
... 17 more

但是server没有错啊,而且通过浏览器访问至少是有效果的。

然后Google了一些,说道移除spring remoting依赖。好吧,果真凑效,那么内部到底是为何呢?

示例代码 hello-hessian-spring, hello-hessian-spring-client

参阅:

HessianConnectionException: (HTTP) 500 error when using Hessian 4.0.7 & Spring 3.1.1