package com.xpn.p2pxwiki.communication.xmlrpc; import java.io.IOException; import java.net.URL; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.server.PropertyHandlerMapping; import org.apache.xmlrpc.server.RequestProcessorFactoryFactory; import org.apache.xmlrpc.webserver.XmlRpcServlet; import org.apache.xmlrpc.XmlRpcRequest; import com.xpn.p2pxwiki.P2PXWikiException; import com.xpn.p2pxwiki.communication.InitializableHandler; public class P2PXWikiXmlRpcServlet extends XmlRpcServlet { private static final long serialVersionUID = 6747820509952424789L; protected PropertyHandlerMapping newPropertyHandlerMapping(URL url) throws IOException, XmlRpcException { // PropertyHandlerMapping mapping = super.newPropertyHandlerMapping(url); // does not work right PropertyHandlerMapping mapping = new PropertyHandlerMapping(); mapping.setTypeConverterFactory(getXmlRpcServletServer().getTypeConverterFactory()); RequestProcessorFactoryFactory factory = new RequestProcessorFactoryFactory.RequestSpecificProcessorFactoryFactory() { protected Object getRequestProcessor(Class pClass, XmlRpcRequest pRequest) throws XmlRpcException { Object proc = super.getRequestProcessor(pClass, pRequest); if (proc instanceof InitializableHandler) { InitializableHandler initProc = (InitializableHandler) proc; try { initProc.init(P2PXWikiXmlRpcServlet.this); } catch (P2PXWikiException ex) { throw new XmlRpcException("Initialization Error", ex); } } return proc; } }; // first assign a RequestProcessorFactoryFactory to the mapping mapping.setRequestProcessorFactoryFactory(factory); // only then load it mapping.load(Thread.currentThread().getContextClassLoader(), url); return mapping; } }