|
配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>HessianCallSample</display-name>
<servlet>
<description>A sample of hessian call.</description>
<display-name>HessianCallSample</display-name>
<servlet-name>HessianCallSample</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<description>
</description>
<param-name>home-class</param-name>
<param-value>com.justep.hessian.SampleImpl</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>home-api</param-name>
<param-value>com.justep.hessian.Sample</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HessianCallSample</servlet-name>
<url-pattern>/HessianCallSample</url-pattern>
</servlet-mapping>
<servlet>
<description>A sample of hessian call.</description>
<display-name>HessianServletName</display-name>
<servlet-name>HessianServletName</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<description>
</description>
<param-name>home-class</param-name>
<param-value>com.justep.hessian.SampleName</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>home-api</param-name>
<param-value>com.justep.hessian.Sample</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HessianServletName</servlet-name>
<url-pattern>/HessianServletName</url-pattern>
</servlet-mapping>
</web-app>
操作如下:
com.justep.hessian.SampleName是我自己定义的一个类实现论坛提供的例子中的Sample接口,源文件如下:
package com.justep.hessian;
public class SampleName
implements Sample
{
public SampleName()
{
}
public String helloWorld()
{
return "Hello world!";
}
public int add(int a, int b)
{
return a + b;
}
public OutParameter objectParamterCall(InParameter in)
{
OutParameter r = new OutParameter();
r.intField = in.intField;
r.stringField = in.stringField;
return r;
}
}
在平台中通过配置文件里提供的<url-pattern>/HessianServletName</url-pattern>远程调用接口可以访问到SampleName里面的方法。
疑问一:com.caucho.hessian.server.HessianServlet类中与com.justep.hessian.Sample接口和com.justep.hessian.SampleImp实现类有什么关系?我看了HessianServlet的源代码,但是没有发现他们之间有什么联系,只是在配置文件里有相关的参数配置。
<init-param>
<description>
</description>
<param-name>home-class</param-name>
<param-value>com.justep.hessian.SampleImpl</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>home-api</param-name>
<param-value>com.justep.hessian.Sample</param-value>
</init-param>
疑问二:论坛地址:http://bbs.justep.com/forum.php?mod=viewthread&tid=16495, 我根据12楼的回话做了下测试,我自己写了一个java类,然后在配置文件里把Home-class改成自定义的类,但是调用不了。
疑问三:但是我把下面的去掉,重启Tomcat,在X3上依然可以调用例子中com.justep.hessian.SampleImpl类的方法。
init-param>
<description>
</description>
<param-name>home-class</param-name>
<param-value>com.justep.hessian.SampleImpl</param-value>
</init-param>
<init-param>
<description>
</description>
<param-name>home-api</param-name>
<param-value>com.justep.hessian.Sample</param-value>
</init-param>
疑问四:我自定义的一个Servlet Extends HttpServlet,接口类与实现类跟例子中的一样,但是通过我自定义的Sertvlet接口,在X3里调用不了。如果要自定义一个Servlet的话,是不是必须要按照例子里的方法Extends GenericServlet ?
疑问五:我做了下测试,直接调用com.caucho.hessian.server.HessianServlet类下面的方法,但是调用不了? |
|