Index: xwiki-core/src/main/java/com/xpn/xwiki/web/Utils.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/web/Utils.java (revision 25210) +++ xwiki-core/src/main/java/com/xpn/xwiki/web/Utils.java (working copy) @@ -50,7 +50,6 @@ import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin; -import com.xpn.xwiki.xmlrpc.XWikiXmlRpcRequest; public class Utils { @@ -268,9 +267,7 @@ context.setDatabase(dbname); int mode = 0; - if (request instanceof XWikiXmlRpcRequest) { - mode = XWikiContext.MODE_XMLRPC; - } else if (request instanceof XWikiServletRequest) { + if (request instanceof XWikiServletRequest) { mode = XWikiContext.MODE_SERVLET; } else if (request instanceof XWikiPortletRequest) { mode = XWikiContext.MODE_PORTLET; Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java (revision 25211) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiImpl.java (working copy) @@ -45,7 +45,8 @@ import org.xwiki.xmlrpc.model.XWikiPage; import org.xwiki.xmlrpc.model.XWikiPageHistorySummary; import org.xwiki.xmlrpc.model.XWikiPageSummary; - +import org.xwiki.context.Execution; +import org.xwiki.context.ExecutionContext; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.api.Document; @@ -70,13 +71,20 @@ private com.xpn.xwiki.api.XWiki xwikiApi; - public XWikiXmlRpcApiImpl(XWikiContext xwikiContext, com.xpn.xwiki.XWiki xwiki, com.xpn.xwiki.api.XWiki xwikiApi) + public XWikiXmlRpcApiImpl() { - this.xwikiContext = xwikiContext; - this.xwiki = xwiki; - this.xwikiApi = xwikiApi; + this.xwikiContext = getContext(); + this.xwiki = this.xwikiContext.getWiki(); + this.xwikiApi = new com.xpn.xwiki.api.XWiki(this.xwiki, this.xwikiContext); } + protected XWikiContext getContext() + { + Execution execution = Utils.getComponent(Execution.class); + ExecutionContext executionContex = execution.getContext(); + return (XWikiContext) executionContex.getProperty("xwikicontext"); + } + /** * Login. * Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiInvocationHandler.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiInvocationHandler.java (revision 25211) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcApiInvocationHandler.java (working copy) @@ -1,174 +0,0 @@ -package com.xpn.xwiki.xmlrpc; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Formatter; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.xmlrpc.XmlRpcException; -import org.xwiki.container.Container; -import org.xwiki.container.servlet.ServletContainerException; -import org.xwiki.container.servlet.ServletContainerInitializer; -import org.xwiki.context.Execution; - -import com.xpn.xwiki.XWiki; -import com.xpn.xwiki.XWikiContext; -import com.xpn.xwiki.web.Utils; -import com.xpn.xwiki.web.XWikiRequest; -import com.xpn.xwiki.web.XWikiResponse; -import com.xpn.xwiki.web.XWikiServletContext; -import com.xpn.xwiki.web.XWikiURLFactory; - -/** - * This is the invocation handler used by the proxy object that will provide the implementation of the XML RPC API. This - * handler performs component initialization and cleanup at each method call. - * - * @version $Id$ - */ -public class XWikiXmlRpcApiInvocationHandler implements InvocationHandler -{ - private ServletContext servletContext; - - private HttpServletRequest request; - - private HttpServletResponse response; - - public XWikiXmlRpcApiInvocationHandler(ServletContext servletContext, HttpServletRequest request) - { - this.servletContext = servletContext; - this.request = request; - - /* Mock the response */ - response = - (HttpServletResponse) Proxy.newProxyInstance(HttpServletResponse.class.getClassLoader(), - new Class[] {HttpServletResponse.class}, new InvocationHandler() - { - public Object invoke(Object object, Method method, Object[] args) throws Throwable - { - /* Just return null for everything */ - return null; - } - }); - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable - { - XWikiContext context = null; - - try { - /* - * Here we prepare the XWikiXmlRpcContext object and we put it in the config object so that XMLRPC methods - * can get it. The config object is the same that is passed to the XWikiXmlRpcHandler when it is - * initialized. So modifications made here are reflected in the config object that is available to XMLRPC - * methods through the field XWikiXmlRpcHandler.xwikiXmlRpcHttpRequestConfig. - */ - XWikiRequest xwikiRequest = new XWikiXmlRpcRequest(request); - XWikiResponse xwikiResponse = new XWikiXmlRpcResponse(response); - XWikiServletContext xwikiServletContext = new XWikiServletContext(servletContext); - - context = Utils.prepareContext("", xwikiRequest, xwikiResponse, xwikiServletContext); - - /* Initialize new Container subsystem */ - initializeContainerComponent(context); - - XWiki xwiki = XWiki.getXWiki(context); - XWikiURLFactory urlf = xwiki.getURLFactoryService().createURLFactory(context.getMode(), context); - context.setURLFactory(urlf); - - /* Create the implementation object and initialize it with relevant XWiki objects */ - XWikiXmlRpcApiImpl xwikiXmlRpcApiImpl = - new XWikiXmlRpcApiImpl(context, xwiki, new com.xpn.xwiki.api.XWiki(xwiki, context)); - Method m = xwikiXmlRpcApiImpl.getClass().getMethod(method.getName(), method.getParameterTypes()); - - return m.invoke(xwikiXmlRpcApiImpl, args); - } catch (Exception e) { - /* - * Here we cannot pass exceptions through XMLRPC. So, in order to have a dump on the client side of what - * happened we use the stacktrace dump as the exception message. - */ - throw new Exception(getExceptionMessage(e.getCause())); - } finally { - // Cleanup code - if (context != null) { - cleanupComponents(); - } - } - } - - /** - *

- * Format a message containing the server side stack trace to be used as the message of the exception sent to the - * client. - *

- *

- * The message is in the following format:
- * - *

-     * Exception message (1 line)
-     * [START] Server stacktrace (1 line)
-     * Actual server stacktrace (n lines)
-     * [END] Server stacktrace (1 line)
-     * 
- * - *

- * - * @param throwable - * @return A string containing the stack trace of the exception passed as parameter. - */ - private String getExceptionMessage(Throwable throwable) - { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - - Formatter f = new Formatter(pw); - f.format("%s\n", throwable.getMessage()); - f.format("[START] Server stacktrace\n"); - throwable.printStackTrace(pw); - f.format("[END] Server stacktrace\n"); - pw.flush(); - pw.close(); - - return sw.toString(); - } - - private void initializeContainerComponent(XWikiContext context) throws XmlRpcException - { - /* - * Initialize the Container fields (request, response, session). Note that this is a bridge between the old core - * and the component architecture. In the new component architecture we use ThreadLocal to transport the - * request, response and session to components which require them. - */ - ServletContainerInitializer containerInitializer = - (ServletContainerInitializer) Utils.getComponent(ServletContainerInitializer.class); - - try { - containerInitializer.initializeRequest(context.getRequest().getHttpServletRequest(), context); - containerInitializer.initializeResponse(context.getResponse().getHttpServletResponse()); - containerInitializer.initializeSession(context.getRequest().getHttpServletRequest()); - } catch (ServletContainerException e) { - throw new XmlRpcException("Failed to initialize request/response or session", e); - } - } - - private void cleanupComponents() - { - Container container = (Container) Utils.getComponent(Container.class); - Execution execution = (Execution) Utils.getComponent(Execution.class); - - /* - * We must ensure we clean the ThreadLocal variables located in the Container and Execution components as - * otherwise we will have a potential memory leak. - */ - container.removeRequest(); - container.removeResponse(); - container.removeSession(); - execution.removeContext(); - } - -} Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcHttpRequestConfig.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcHttpRequestConfig.java (revision 25211) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcHttpRequestConfig.java (working copy) @@ -1,56 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - * - */ -package com.xpn.xwiki.xmlrpc; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; - -import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl; - -/** - * This is an helper class for storing the current HTTP request coming from an XMLRPC client interacting with the XMLRPC - * endpoint servlet. - * - * @version $Id$ - */ -public class XWikiXmlRpcHttpRequestConfig extends XmlRpcHttpRequestConfigImpl -{ - private ServletContext servletContext; - - private HttpServletRequest request; - - public XWikiXmlRpcHttpRequestConfig(ServletContext servletContext, HttpServletRequest request) - { - this.servletContext = servletContext; - this.request = request; - } - - public ServletContext getServletContext() - { - return servletContext; - } - - public HttpServletRequest getRequest() - { - return request; - } - -} Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcRequest.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcRequest.java (revision 25211) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcRequest.java (working copy) @@ -1,36 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - * - */ -package com.xpn.xwiki.xmlrpc; - -import javax.servlet.http.HttpServletRequest; - -import com.xpn.xwiki.web.XWikiServletRequest; - -/** - * @version $Id$ - */ -public class XWikiXmlRpcRequest extends XWikiServletRequest -{ - public XWikiXmlRpcRequest(HttpServletRequest request) - { - super(request); - } -} Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcResponse.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcResponse.java (revision 25211) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcResponse.java (working copy) @@ -1,50 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - * - */ -package com.xpn.xwiki.xmlrpc; - -import java.io.IOException; -import java.io.PrintWriter; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; - -import com.xpn.xwiki.web.XWikiServletResponse; - -/** - * @version $Id$ - */ -public class XWikiXmlRpcResponse extends XWikiServletResponse -{ - public XWikiXmlRpcResponse(HttpServletResponse response) - { - super(response); - } - - public PrintWriter getWriter() throws IOException - { - return null; - } - - public ServletOutputStream getOutputStream() throws IOException - { - return null; - } -} Index: xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcServlet.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcServlet.java (revision 25211) +++ xwiki-core/src/main/java/com/xpn/xwiki/xmlrpc/XWikiXmlRpcServlet.java (working copy) @@ -21,7 +21,6 @@ package com.xpn.xwiki.xmlrpc; import java.io.IOException; -import java.lang.reflect.Proxy; import java.net.URL; import javax.servlet.ServletConfig; @@ -35,7 +34,6 @@ import org.apache.xmlrpc.server.RequestProcessorFactoryFactory.RequestSpecificProcessorFactoryFactory; import org.apache.xmlrpc.webserver.XmlRpcServlet; import org.apache.xmlrpc.webserver.XmlRpcServletServer; -import org.xwiki.xmlrpc.XWikiXmlRpcApi; /** * This is the XMLRPC Servlet that is used as a gateway for serving XMLRPC requests. @@ -56,22 +54,6 @@ @Override protected Object getRequestProcessor(Class class1, XmlRpcRequest request) throws XmlRpcException { - XWikiXmlRpcHttpRequestConfig config = (XWikiXmlRpcHttpRequestConfig) request.getConfig(); - - /* - * Here we check that the requested class is the interface XWikiXmlRpcApi. In this case we return a - * proxy object that provides an implementation of this interface. If the requested class is of another - * type, we call the superclass method. This allows other handlers to be specified and used. - */ - if (XWikiXmlRpcApi.class.equals(class1)) { - XWikiXmlRpcApi proxy = - (XWikiXmlRpcApi) Proxy.newProxyInstance(XWikiXmlRpcApi.class.getClassLoader(), - new Class[] {XWikiXmlRpcApi.class}, new XWikiXmlRpcApiInvocationHandler(config - .getServletContext(), config.getRequest())); - - return proxy; - } - return super.getRequestProcessor(class1, request); } }; @@ -80,21 +62,4 @@ mapping.load(Thread.currentThread().getContextClassLoader(), url); return mapping; } - - @Override - protected XmlRpcServletServer newXmlRpcServer(ServletConfig config) throws XmlRpcException - { - XmlRpcServletServer server = new XmlRpcServletServer() - { - - @Override - protected XmlRpcHttpRequestConfigImpl newConfig(HttpServletRequest request) - { - return new XWikiXmlRpcHttpRequestConfig(XWikiXmlRpcServlet.this.getServletContext(), request); - } - - }; - - return server; - } } Index: xwiki-core/src/main/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties =================================================================== --- xwiki-core/src/main/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties (revision 25210) +++ xwiki-core/src/main/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties (working copy) @@ -1,2 +1,2 @@ -confluence1=org.xwiki.xmlrpc.XWikiXmlRpcApi -org.xwiki.xmlrpc.XWikiXmlRpcApi=org.xwiki.xmlrpc.XWikiXmlRpcApi \ No newline at end of file +confluence1=com.xpn.xwiki.xmlrpc.XWikiXmlRpcApiImpl +org.xwiki.xmlrpc.XWikiXmlRpcApi=com.xpn.xwiki.xmlrpc.XWikiXmlRpcApiImpl \ No newline at end of file Index: xwiki-webdav/src/main/java/com/xpn/xwiki/plugin/webdav/utils/XWikiDavContext.java =================================================================== --- xwiki-webdav/src/main/java/com/xpn/xwiki/plugin/webdav/utils/XWikiDavContext.java (revision 25210) +++ xwiki-webdav/src/main/java/com/xpn/xwiki/plugin/webdav/utils/XWikiDavContext.java (working copy) @@ -58,7 +58,7 @@ import com.xpn.xwiki.web.XWikiServletContext; import com.xpn.xwiki.web.XWikiServletRequest; import com.xpn.xwiki.web.XWikiURLFactory; -import com.xpn.xwiki.xmlrpc.XWikiXmlRpcResponse; +import com.xpn.xwiki.web.XWikiServletResponse; /** * Holds context information about a webdav request. @@ -126,10 +126,10 @@ try { XWikiEngineContext xwikiEngine = new XWikiServletContext(servletContext); XWikiRequest xwikiRequest = new XWikiServletRequest(request); - XWikiResponse xwikiResponse = new XWikiXmlRpcResponse(response); + XWikiResponse xwikiResponse = new XWikiServletResponse(response); xwikiContext = Utils.prepareContext("", xwikiRequest, xwikiResponse, xwikiEngine); - xwikiContext.setMode(XWikiContext.MODE_GWT); + xwikiContext.setMode(XWikiContext.MODE_SERVLET); xwikiContext.setDatabase("xwiki"); ServletContainerInitializer containerInitializer = Index: xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java =================================================================== --- xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java (revision 25210) +++ xwiki-xmlrpc/xwiki-xmlrpc-model/src/main/java/org/xwiki/xmlrpc/XWikiXmlRpcApi.java (working copy) @@ -106,5 +106,4 @@ public List/* List */getModifiedPagesHistory(String token, Date date, int numberOfResults, int start, boolean fromLatest) throws Exception; - }