The simplest Hessian code example of a binary Web service framework
Passed the resin3.1 Test
Hessian version: hessian-3.1.6.jar
Official Address:
Http://hessian.caucho.com/#Java
Http://hessian.caucho.com/
The procedure is as follows:
1. Interface Definition
Package com. yanek. study. hessian;
Public interface Hello {
Public String hello (String name );
}
2. Interface implementation
Package com. yanek. study. hessian;
Public class HelloImpl implements Hello {
Public String hello (String name)
{
Return "hello" + name + "welcome study Hessian ";
}
}
3. web. xml configuration
Configure HessianServlet and configure the class that provides the service
<Servlet>
<Servlet-name> hessianService </servlet-name>
<Servlet-class> com. caucho. hessian. server. HessianServlet </servlet-class>
<Load-on-startup> 1 </load-on-startup>
<Init-param>
<Param-name> service-class </param-name>
<Param-value> com. yanek. study. hessian. HelloImpl </param-value>
</Init-param>
</Servlet>
<Servlet-mapping>
<Servlet-Name> hessianservice </servlet-Name>
<URL-pattern>/hessianservice </url-pattern>
</Servlet-mapping>
4. Client test class:
Package com. Yanek. Study. Hessian;
Import java.net. malformedurlexception;
Import com. Caucho. Hessian. Client. hessianproxyfactory;
Public class hessianclient {
/**
* @ Param ARGs
*/
Public static void main (String [] args ){
// Hessian service url
String url = "http://study.myweb.com/hessianService ";
// Create a HessianProxyFactory instance
HessianProxyFactory factory = new HessianProxyFactory ();
// Obtain the remote reference of the Hessian Service
Hello d;
Try {
D = (Hello) factory. create (Hello. class, url );
// Call the remote service.
System. out. println ("the Hessian service is called below:" + d. hello ("yanek "));
} Catch (MalformedURLException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
}
}