The simplest Hessian code example of a binary web service framework

Source: Internet
Author: User

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 ();
}

 

}

}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.