Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing hessian service

I am new to Spring and Hessian and never used them before.

I want to write a small Hello World Program which clearly shows how this service works.

I am using Maven for list project details and dependencies.

The resources for hessian available online are not complete step-by-step guide.

would appreciate if I get help form someone who has worked writing hessian services

like image 396
daydreamer Avatar asked Dec 22 '22 18:12

daydreamer


1 Answers

The steps for implementing a Hessian-callable service are:

  • Create a Java interface defining methods to be called by clients.
  • Write a Java class implementing this interface.
  • Configure a servlet to handle HTTP Hessian service requests.
  • Configure a HessianServiceExporter to handle Hessian service requests from the servlet by delegating service calls to the Java class implementing this interface.

Let's go through an example. Create a Java interface:

public interface EchoService {
    String echoString(String value);
}

Write a Java class implementing this interface:

public class EchoServiceImpl implements EchoService {
    public String echoString(String value) {
        return value;
    }
}

In the web.xml file, configure a servlet:

<servlet>
  <servlet-name>/EchoService</servlet-name>
  <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>  
</servlet>

<servlet-mapping>
  <servlet-name>/EchoService</servlet-name>
  <url-pattern>/remoting/EchoService</url-pattern>
</servlet-mapping>

Configure an instance of the service class in the Spring application context:

<bean id="echoService" class="com.example.echo.EchoServiceImpl"/>

Configure the exporter in the Spring application context. The bean name must match the servlet name.

<bean
    name="/EchoService"
    class="org.springframework.remoting.caucho.HessianServiceExporter">
  <property name="service" ref="echoService"/>
  <property name="serviceInterface" value="com.example.echo.EchoService"/>
</bean>
like image 130
Chin Huang Avatar answered Dec 29 '22 22:12

Chin Huang