web.xml:
<servlet>
<servlet-name>testService</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-api</param-name>
<param-value>com.caucho.hessian.test.TestService</param-value>
</init-param>
<init-param>
<param-name>home-class</param-name>
<param-value>com.caucho.hessian.test.TestServiceImpl</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>testService</servlet-name>
<url-pattern>/testService</url-pattern>
</servlet-mapping>
java服务类:
public class TestServiceImpl implements TestService{
public String say(){
return "test:" + TestServiceImpl.class.getName();
}
public TestObject getTestObject(){
return new TestObject("123456");
}
}
public interface TestService {
String say();
TestObject getTestObject();
}
public class TestObject {
private Object _value;
客户端:
public class Main {
public static void main(String[] arg) throws Exception{
String urlString = "http://localhost/hessian/testService";
HessianProxyFactory factory = new HessianProxyFactory();
TestService testService = (TestService)factory.create(TestService.class,urlString);
System.out.println(testService.say());
System.out.println(testService.getTestObject());
}
}