daydreamer
daydreamer

Reputation: 91969

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

Upvotes: 5

Views: 4152

Answers (3)

Pino
Pino

Reputation: 9303

The question is very old and the most voted answer became obsolete: Spring's HessianServiceExporter was deprecated in Spring 5.3 and removed in Spring 6.

Currently the steps for implementing a Hessian-callable service are:

  1. Create a Java interface defining methods to be called by clients.

  2. Write a Java class implementing this interface.

  3. Extend HessianServlet to implement the same interface and delegate the business logic to the Java class created at step #2 (implementing this logic directly in the servlet is possible but not recommended).

  4. Use Spring's ServletRegistrationBean to enable the servlet.

hessian-demo provides a working example of a Hessian-based web service in a Spring Boot application without HessianServiceExporter. You can even use the Jakarta-based Spring Boot 3 (in this case you need hessian-jakarta).

Upvotes: 2

Chin Huang
Chin Huang

Reputation: 13820

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>

Upvotes: 7

Konsumierer
Konsumierer

Reputation: 1304

The client has to create a proxy of the remote interface. You could simply write a JUnit-Test:

HessianProxyFactory proxyFactory = new HessianProxyFactory();
        proxyFactory.setHessian2Reply(false);
        proxyFactory.setHessian2Request(false);
        com.example.echo.EchoService service = proxyFactory.create(
                com.example.echo.EchoService, "http://localhost:8080/<optional-context/>remoting/EchoService");

Assert.equals(service.echoString("test"), "test");

Upvotes: 4

Related Questions