writing hessian service

帅比萌擦擦* 提交于 2019-12-07 10:43:34

问题


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


回答1:


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>



回答2:


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");


来源:https://stackoverflow.com/questions/4753852/writing-hessian-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!