Hessian service letter

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

I want to write a small Hello World program that clearly shows how this service works.

I use Maven to describe and dependencies of the list of projects.

Resources for hessian available on the Internet are not a complete walkthrough.

I would be grateful if I would get help from someone who worked on writing hessian services

+3
source share
2 answers

The steps for implementing a service enabling Hesse are:

  • Create a Java interface that defines the methods that will be called by clients.
  • Write a Java class that implements this interface.
  • Configure the servlet to handle Hessian HTTP requests.
  • HessianServiceExporter Hessian , Java-, .

. Java:

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

Java, :

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

web.xml :

<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>

Spring:

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

Spring. bean .

<bean
    name="/EchoService"
    class="org.springframework.remoting.caucho.HessianServiceExporter">
  <property name="service" ref="echoService"/>
  <property name="serviceInterface" value="com.example.echo.EchoService"/>
</bean>
+7

. 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");
+4

Source: https://habr.com/ru/post/1786803/


All Articles