读书人

Apache xml-rpc与spring的调整

发布时间: 2012-06-29 15:48:46 作者: rapoo

Apache xml-rpc与spring的整合
  之前在项目中使用了Apache xml-rpc,遇到了一个麻烦的问题。spring没有提供对xml-rpc的支持,在处理webservice请求的时候,没有办法使用spring容器中管理的各种各样的bean对象。显然,这是不能接受的。

  使用Apache xml-rpc,一般只需要在web.xml中定义一个servlet (XmlRpcServlet), 再实现用于处理webservice请求的组件类就可以了。
  比如定义一个Servlet:

public class CustomXmlRpcServlet extends XmlRpcServlet{    private static final long serialVersionUID = 8615627610262194L;    protected static ApplicationContext ctx = null;    public CustomXmlRpcServlet()    {        super();    }    public void init()    {        if (ctx == null)        {            ctx = WebApplicationContextUtils                    .getRequiredWebApplicationContext(this.getServletContext());        }    }    protected XmlRpcHandlerMapping newXmlRpcHandlerMapping()            throws XmlRpcException    {        PropertyHandlerMapping mapping = new PropertyHandlerMapping();                CustomWebServiceHandler service = (CustomWebServiceHandler) ctx.getBean("customWebServiceHandler");                mapping.setRequestProcessorFactoryFactory(new CustomRequestProcessorFactoryFactory(service));        mapping.addHandler("CustomWebServiceHandler", CustomWebServiceHandler.class);        return mapping;    }}

  这样扩展以后,之前提到的XmlRpcServlet.properties文件也不再需要了。

读书人网 >Apache

热点推荐