今天在弄那个Hessian,想用它实现web服务,于是按官方网站的document的例子做了一个简单的hello程序,报了一堆错误,刚接触这个,实在不知道原因何在.
请教一下们,在此先谢了!!
程序完整代码:
1,对外暴露的业务接口
[code]package com.neoman.hession;
public interface BasicAPI {
public String hello();
}
[/code]
2,服务器端实现
[code]package com.neoman.hession;
import com.caucho.hessian.server.HessianServlet;
public class BasicService extends HessianServlet implements BasicAPI {
private String str="Hello World";
public void setStr(String str) {
this.str = str;
}
public String hello() {
// TODO Auto-generated method stub
return str;
}
}
[/code]
3,客户端测试代码
[code]package com.neoman.hession;
import java.net.MalformedURLException;
import com.caucho.hessian.client.HessianProxyFactory;
public class Test {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String url = "http://localhost:8080/HessionTest/hello";
HessianProxyFactory factory = new HessianProxyFactory();
BasicAPI basic=(BasicAPI) factory.create(BasicAPI.class, url);
System.out.println("hello(): " + basic.hello());
}
}[/code]
4, web.xml配置
[code]<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-class</param-name>
<param-value>com.neoman.hession.BasicService</param-value>
</init-param>
<init-param>
<param-name>home-api</param-name>
<param-value>com.neoman.hession.BasicAPI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
[/code]
报的错误:[i]Exception in thread "main" com.caucho.hessian.client.HessianRuntimeException: com.caucho.hessian.io.HessianProtocolException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:183)
at $Proxy0.hello(Unknown Source)
at com.neoman.hession.Test.main(Test.java:21)
Caused by: com.caucho.hessian.io.HessianProtocolException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:167)
... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1227)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1221)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:910)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:149)
... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1174)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:367)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:140)
... 2 more
[/i]
请教一下们,在此先谢了!!
程序完整代码:
1,对外暴露的业务接口
[code]package com.neoman.hession;
public interface BasicAPI {
public String hello();
}
[/code]
2,服务器端实现
[code]package com.neoman.hession;
import com.caucho.hessian.server.HessianServlet;
public class BasicService extends HessianServlet implements BasicAPI {
private String str="Hello World";
public void setStr(String str) {
this.str = str;
}
public String hello() {
// TODO Auto-generated method stub
return str;
}
}
[/code]
3,客户端测试代码
[code]package com.neoman.hession;
import java.net.MalformedURLException;
import com.caucho.hessian.client.HessianProxyFactory;
public class Test {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String url = "http://localhost:8080/HessionTest/hello";
HessianProxyFactory factory = new HessianProxyFactory();
BasicAPI basic=(BasicAPI) factory.create(BasicAPI.class, url);
System.out.println("hello(): " + basic.hello());
}
}[/code]
4, web.xml配置
[code]<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-class</param-name>
<param-value>com.neoman.hession.BasicService</param-value>
</init-param>
<init-param>
<param-name>home-api</param-name>
<param-value>com.neoman.hession.BasicAPI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
[/code]
报的错误:[i]Exception in thread "main" com.caucho.hessian.client.HessianRuntimeException: com.caucho.hessian.io.HessianProtocolException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:183)
at $Proxy0.hello(Unknown Source)
at com.neoman.hession.Test.main(Test.java:21)
Caused by: com.caucho.hessian.io.HessianProtocolException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:167)
... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1227)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1221)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:910)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:149)
... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/HessionTest/hello
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1174)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:367)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:140)
... 2 more
[/i]