You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by jo...@apache.org on 2006/07/21 01:39:10 UTC
svn commit: r424115 - in /webservices/xmlrpc/trunk:
server/src/main/java/org/apache/xmlrpc/metadata/
server/src/main/java/org/apache/xmlrpc/server/
server/src/main/java/org/apache/xmlrpc/webserver/ src/site/apt/
src/site/fml/ tests/src/test/java/org/ap...
Author: jochen
Date: Thu Jul 20 16:39:09 2006
New Revision: 424115
URL: http://svn.apache.org/viewvc?rev=424115&view=rev
Log:
Replaced the InitializableHandler with the RequestProcessorFactoryFactory,
as discussed with Jimisola Laursen who requested an additional InstantiationHandler.
Removed:
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/DynamicHandlerMapping.java
Modified:
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/ReflectiveXmlRpcMetaDataHandler.java
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/Util.java
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/AbstractReflectiveHandlerMapping.java
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/PropertyHandlerMapping.java
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.java
webservices/xmlrpc/trunk/src/site/apt/advanced.apt
webservices/xmlrpc/trunk/src/site/apt/contributing.apt
webservices/xmlrpc/trunk/src/site/apt/server.apt
webservices/xmlrpc/trunk/src/site/fml/faq.fml
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/BaseTest.java
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/DynamicProxyTest.java
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java
Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/ReflectiveXmlRpcMetaDataHandler.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/ReflectiveXmlRpcMetaDataHandler.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/ReflectiveXmlRpcMetaDataHandler.java (original)
+++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/ReflectiveXmlRpcMetaDataHandler.java Thu Jul 20 16:39:09 2006
@@ -21,6 +21,7 @@
import org.apache.xmlrpc.common.TypeConverterFactory;
import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping;
import org.apache.xmlrpc.server.ReflectiveXmlRpcHandler;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory.RequestProcessorFactory;
/** Default implementation of {@link XmlRpcMetaDataHandler}.
@@ -36,21 +37,6 @@
* this handler. Typically, this will be the same as
* <pre>pInstance.getClass()</pre>. It is used for diagnostic
* messages only.
- * @param pInstanceIsStateless The handler
- * can operate in either of two operation modes:
- * <ol>
- * <li>The object, which is actually performing the requests,
- * is initialized at startup. In other words, there is only
- * one object, which is performing all the requests.
- * Obviously, this is the faster operation mode. On the
- * other hand, it has the disadvantage, that the object
- * must be stateless.</li>
- * <li>A new object is created for any request. This is slower,
- * because the object needs to be initialized. On the other
- * hand, it allows for stateful objects, which may take
- * request specific configuration like the clients IP address,
- * and the like.</li>
- * </ol>
* @param pMethods The method, which will be invoked for
* executing the handler.
* @param pSignatures The signature, which will be returned by
@@ -60,10 +46,9 @@
*/
public ReflectiveXmlRpcMetaDataHandler(AbstractReflectiveHandlerMapping pMapping,
TypeConverterFactory pTypeConverterFactory,
- Class pClass, boolean pInstanceIsStateless, Method[] pMethods,
- String[][] pSignatures, String pMethodHelp)
- throws XmlRpcException {
- super(pMapping, pTypeConverterFactory, pClass, pInstanceIsStateless, pMethods);
+ Class pClass, RequestProcessorFactory pFactory, Method[] pMethods,
+ String[][] pSignatures, String pMethodHelp) {
+ super(pMapping, pTypeConverterFactory, pClass, pFactory, pMethods);
signatures = pSignatures;
methodHelp = pMethodHelp;
}
Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/Util.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/Util.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/Util.java (original)
+++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/metadata/Util.java Thu Jul 20 16:39:09 2006
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.xmlrpc.XmlRpcException;
import org.w3c.dom.Node;
@@ -201,5 +202,18 @@
}
}
return sb.toString();
+ }
+
+ /**
+ * Creates a new instance of <code>pClass</code>.
+ */
+ public static Object newInstance(Class pClass) throws XmlRpcException {
+ try {
+ return pClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new XmlRpcException("Failed to instantiate class " + pClass.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new XmlRpcException("Illegal access when instantiating class " + pClass.getName(), e);
+ }
}
}
Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/AbstractReflectiveHandlerMapping.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/AbstractReflectiveHandlerMapping.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/AbstractReflectiveHandlerMapping.java (original)
+++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/AbstractReflectiveHandlerMapping.java Thu Jul 20 16:39:09 2006
@@ -27,10 +27,12 @@
import org.apache.xmlrpc.XmlRpcHandler;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.TypeConverterFactory;
+import org.apache.xmlrpc.common.TypeConverterFactoryImpl;
import org.apache.xmlrpc.metadata.ReflectiveXmlRpcMetaDataHandler;
import org.apache.xmlrpc.metadata.Util;
import org.apache.xmlrpc.metadata.XmlRpcListableHandlerMapping;
import org.apache.xmlrpc.metadata.XmlRpcMetaDataHandler;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory.RequestProcessorFactory;
/** Abstract base class of handler mappings, which are
@@ -49,46 +51,37 @@
throws XmlRpcException;
}
- /** An object, which is called for initializing the
- * actual handler object.
+ private TypeConverterFactory typeConverterFactory = new TypeConverterFactoryImpl();
+ protected Map handlerMap = new HashMap();
+ private AuthenticationHandler authenticationHandler;
+ private RequestProcessorFactoryFactory requestProcessorFactoryFactory = new RequestProcessorFactoryFactory.RequestSpecificProcessorFactoryFactory();
+
+ /**
+ * Sets the mappings {@link TypeConverterFactory}.
*/
- public interface InitializationHandler {
- /** Called for initializing the object, which
- * is was returned by {@link ReflectiveXmlRpcHandler#newInstance()}.
- */
- public void init(XmlRpcRequest pRequest, Object pObject)
- throws XmlRpcException;
+ public void setTypeConverterFactory(TypeConverterFactory pFactory) {
+ typeConverterFactory = pFactory;
}
- private final TypeConverterFactory typeConverterFactory;
- private final boolean instanceIsStateless;
- protected Map handlerMap = new HashMap();
- private AuthenticationHandler authenticationHandler;
- private InitializationHandler initializationHandler;
+ /**
+ * Returns the mappings {@link TypeConverterFactory}.
+ */
+ public TypeConverterFactory getTypeConverterFactory() {
+ return typeConverterFactory;
+ }
+
+ /** Sets the mappings {@link RequestProcessorFactoryFactory}.
+ */
+ public void setRequestProcessorFactoryFactory(RequestProcessorFactoryFactory pFactory) {
+ requestProcessorFactoryFactory = pFactory;
+ }
- /** Creates a new instance.
- * @param pInstanceIsStateless The handler
- * can operate in either of two operation modes:
- * <ol>
- * <li>The object, which is actually performing the requests,
- * is initialized at startup. In other words, there is only
- * one object, which is performing all the requests.
- * Obviously, this is the faster operation mode. On the
- * other hand, it has the disadvantage, that the object
- * must be stateless.</li>
- * <li>A new object is created for any request. This is slower,
- * because the object needs to be initialized. On the other
- * hand, it allows for stateful objects, which may take
- * request specific configuration like the clients IP address,
- * and the like.</li>
- * </ol>
- */
- protected AbstractReflectiveHandlerMapping(TypeConverterFactory pTypeConverterFactory,
- boolean pInstanceIsStateless) {
- typeConverterFactory = pTypeConverterFactory;
- instanceIsStateless = pInstanceIsStateless;
+ /** Returns the mappings {@link RequestProcessorFactoryFactory}.
+ */
+ public RequestProcessorFactoryFactory getRequestProcessorFactoryFactory() {
+ return requestProcessorFactoryFactory;
}
-
+
/** Returns the authentication handler, if any, or null.
*/
public AuthenticationHandler getAuthenticationHandler() {
@@ -101,18 +94,6 @@
authenticationHandler = pAuthenticationHandler;
}
- /** Returns the initialization handler, if any, or null.
- */
- public InitializationHandler getInitializationHandler() {
- return initializationHandler;
- }
-
- /** Sets the initialization handler, if any, or null.
- */
- public void setInitializationHandler(InitializationHandler pInitializationHandler) {
- initializationHandler = pInitializationHandler;
- }
-
/** Searches for methods in the given class. For any valid
* method, it creates an instance of {@link XmlRpcHandler}.
* Valid methods are defined as follows:
@@ -126,13 +107,11 @@
* which meet the above conditins, then only the
* first method is valid.</li>
* </ul>
- * @param pMap Handler map, in which created handlers are
- * being registered.
* @param pKey Suffix for building handler names. A dot and
* the method name are being added.
* @param pType The class being inspected.
*/
- protected void registerPublicMethods(Map pMap, String pKey,
+ protected void registerPublicMethods(String pKey,
Class pType) throws XmlRpcException {
Map map = new HashMap();
Method[] methods = pType.getMethods();
@@ -167,7 +146,7 @@
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
Method[] mArray = (Method[]) entry.getValue();
- pMap.put(name, newXmlRpcHandler(pType, mArray));
+ handlerMap.put(name, newXmlRpcHandler(pType, mArray));
}
}
@@ -181,12 +160,13 @@
final Method[] pMethods) throws XmlRpcException {
String[][] sig = getSignature(pMethods);
String help = getMethodHelp(pClass, pMethods);
- if (sig == null || help == null) {
+ RequestProcessorFactory factory = requestProcessorFactoryFactory.getRequestProcessorFactory(pClass);
+ if (sig == null || help == null) {
return new ReflectiveXmlRpcHandler(this, typeConverterFactory,
- pClass, instanceIsStateless, pMethods);
+ pClass, factory, pMethods);
}
return new ReflectiveXmlRpcMetaDataHandler(this, typeConverterFactory,
- pClass, instanceIsStateless, pMethods, sig, help);
+ pClass, factory, pMethods, sig, help);
}
/** Creates a signature for the given method.
Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/PropertyHandlerMapping.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/PropertyHandlerMapping.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/PropertyHandlerMapping.java (original)
+++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/PropertyHandlerMapping.java Thu Jul 20 16:39:09 2006
@@ -17,13 +17,11 @@
import java.io.IOException;
import java.net.URL;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.common.TypeConverterFactory;
/**
@@ -36,78 +34,33 @@
* as the property keys and implementations as the values.
*/
public class PropertyHandlerMapping extends AbstractReflectiveHandlerMapping {
- /** Creates a new instance, loading the property file
- * from the given URL.
- * @param pClassLoader Classloader being used to load the classes.
- * @param pURL The URL, from which the property file is being
- * loaded.
- * @param pInstanceIsStateless The handler
- * can operate in either of two operation modes:
- * <ol>
- * <li>The object, which is actually performing the requests,
- * is initialized at startup. In other words, there is only
- * one object, which is performing all the requests.
- * Obviously, this is the faster operation mode. On the
- * other hand, it has the disadvantage, that the object
- * must be stateless.</li>
- * <li>A new object is created for any request. This is slower,
- * because the object needs to be initialized. On the other
- * hand, it allows for stateful objects, which may take
- * request specific configuration like the clients IP address,
- * and the like.</li>
- * </ol>
+ /**
+ * Reads handler definitions from a resource file.
+ * @paramm pClassLoader The class loader being used to load
+ * handler classes.
+ * @param pResource The resource being used, for example
+ * "org/apache/xmlrpc/webserver/XmlRpcServlet.properties"
* @throws IOException Loading the property file failed.
* @throws XmlRpcException Initializing the handlers failed.
*/
- public PropertyHandlerMapping(ClassLoader pClassLoader, URL pURL,
- TypeConverterFactory pTypeConverterFactory,
- boolean pInstanceIsStateless)
+ public void load(ClassLoader pClassLoader, String pResource)
throws IOException, XmlRpcException {
- super(pTypeConverterFactory, pInstanceIsStateless);
- handlerMap = load(pClassLoader, pURL);
- }
-
- /** Creates a new instance, loading the properties from
- * the given resource.
- * @param pClassLoader Classloader being used to locate
- * the resource.
- * @param pResource Resource being loaded.
- * @param pInstanceIsStateless The handler
- * can operate in either of two operation modes:
- * <ol>
- * <li>The object, which is actually performing the requests,
- * is initialized at startup. In other words, there is only
- * one object, which is performing all the requests.
- * Obviously, this is the faster operation mode. On the
- * other hand, it has the disadvantage, that the object
- * must be stateless.</li>
- * <li>A new object is created for any request. This is slower,
- * because the object needs to be initialized. On the other
- * hand, it allows for stateful objects, which may take
- * request specific configuration like the clients IP address,
- * and the like.</li>
- * </ol>
- * @throws IOException Loading the property file failed.
- * @throws XmlRpcException Initializing the handlers failed.
- */
- public PropertyHandlerMapping(ClassLoader pClassLoader, String pResource,
- TypeConverterFactory pTypeConverterFactory,
- boolean pInstanceIsStateless)
- throws IOException, XmlRpcException {
- this(pClassLoader, asURL(pClassLoader, pResource), pTypeConverterFactory,
- pInstanceIsStateless);
- }
-
- private static URL asURL(ClassLoader pClassLoader, String pResource) throws IOException {
URL url = pClassLoader.getResource(pResource);
if (url == null) {
throw new IOException("Unable to locate resource " + pResource);
}
- return url;
+ load(pClassLoader, url);
}
- private Map load(ClassLoader pClassLoader, URL pURL) throws IOException, XmlRpcException {
- Map map = new HashMap();
+ /**
+ * Reads handler definitions from a property file.
+ * @paramm pClassLoader The class loader being used to load
+ * handler classes.
+ * @param pURL The URL from which to load the property file
+ * @throws IOException Loading the property file failed.
+ * @throws XmlRpcException Initializing the handlers failed.
+ */
+ public void load(ClassLoader pClassLoader, URL pURL) throws IOException, XmlRpcException {
Properties props = new Properties();
props.load(pURL.openStream());
for (Iterator iter = props.entrySet().iterator(); iter.hasNext(); ) {
@@ -115,9 +68,8 @@
String key = (String) entry.getKey();
String value = (String) entry.getValue();
Class c = newHandlerClass(pClassLoader, value);
- registerPublicMethods(map, key, c);
+ registerPublicMethods(key, c);
}
- return map;
}
protected Class newHandlerClass(ClassLoader pClassLoader, String pClassName)
@@ -132,5 +84,25 @@
throw new XmlRpcException(0, "Loading class " + pClassName + " returned null.");
}
return c;
+ }
+
+ /** Adds handlers for the given object to the mapping.
+ * The handlers are build by invoking
+ * {@link #registerPublicMethods(String, Class)}.
+ * @param pKey The class key, which is passed
+ * to {@link #registerPublicMethods(String, Class)}.
+ * @param pClass Class, which is responsible for handling the request.
+ */
+ public void addHandler(String pKey, Class pClass) throws XmlRpcException {
+ registerPublicMethods(pKey, pClass);
+ }
+
+ /** Removes all handlers with the given class key.
+ */
+ public void removeHandler(String pKey) {
+ for (Iterator i = handlerMap.keySet().iterator(); i.hasNext();) {
+ String k = (String)i.next();
+ if (k.startsWith(pKey)) i.remove();
+ }
}
}
Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java (original)
+++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java Thu Jul 20 16:39:09 2006
@@ -26,7 +26,7 @@
import org.apache.xmlrpc.common.XmlRpcNotAuthorizedException;
import org.apache.xmlrpc.metadata.Util;
import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
-import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.InitializationHandler;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory.RequestProcessorFactory;
/** Default implementation of {@link XmlRpcHandler}.
@@ -45,9 +45,9 @@
}
}
private final AbstractReflectiveHandlerMapping mapping;
- private final Class clazz;
private final MethodData[] methods;
- private final Object theInstance;
+ private final Class clazz;
+ private final RequestProcessorFactory requestProcessorFactory;
/** Creates a new instance.
* @param pMapping The mapping, which creates this handler.
@@ -55,46 +55,23 @@
* this handler. Typically, this will be the same as
* <pre>pInstance.getClass()</pre>. It is used for diagnostic
* messages only.
- * @param pInstanceIsStateless The handler
- * can operate in either of two operation modes:
- * <ol>
- * <li>The object, which is actually performing the requests,
- * is initialized at startup. In other words, there is only
- * one object, which is performing all the requests.
- * Obviously, this is the faster operation mode. On the
- * other hand, it has the disadvantage, that the object
- * must be stateless.</li>
- * <li>A new object is created for any request. This is slower,
- * because the object needs to be initialized. On the other
- * hand, it allows for stateful objects, which may take
- * request specific configuration like the clients IP address,
- * and the like.</li>
- * </ol>
* @param pMethods The method, which will be invoked for
* executing the handler.
*/
public ReflectiveXmlRpcHandler(AbstractReflectiveHandlerMapping pMapping,
TypeConverterFactory pTypeConverterFactory,
- Class pClass, boolean pInstanceIsStateless, Method[] pMethods)
- throws XmlRpcException {
+ Class pClass, RequestProcessorFactory pFactory, Method[] pMethods) {
mapping = pMapping;
- clazz = pClass;
+ clazz = pClass;
methods = new MethodData[pMethods.length];
+ requestProcessorFactory = pFactory;
for (int i = 0; i < methods.length; i++) {
methods[i] = new MethodData(pMethods[i], pTypeConverterFactory);
}
- theInstance = pInstanceIsStateless ? newInstance() : null;
}
private Object getInstance(XmlRpcRequest pRequest) throws XmlRpcException {
- final InitializationHandler ih = mapping.getInitializationHandler();
- if (ih == null) {
- return theInstance == null ? newInstance() : theInstance;
- } else {
- final Object instance = newInstance();
- ih.init(pRequest, instance);
- return instance;
- }
+ return requestProcessorFactory.getRequestProcessor(pRequest);
}
public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
@@ -148,14 +125,4 @@
+ t.getMessage(), t);
}
}
-
- protected Object newInstance() throws XmlRpcException {
- try {
- return clazz.newInstance();
- } catch (InstantiationException e) {
- throw new XmlRpcException("Failed to instantiate class " + clazz.getName(), e);
- } catch (IllegalAccessException e) {
- throw new XmlRpcException("Illegal access when instantiating class " + clazz.getName(), e);
- }
- }
}
Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.java (original)
+++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.java Thu Jul 20 16:39:09 2006
@@ -104,9 +104,10 @@
* {@link #newXmlRpcHandlerMapping()}.
*/
protected PropertyHandlerMapping newPropertyHandlerMapping(URL url) throws IOException, XmlRpcException {
- return new PropertyHandlerMapping(getClass().getClassLoader(), url,
- server.getTypeConverterFactory(),
- false);
+ PropertyHandlerMapping mapping = new PropertyHandlerMapping();
+ mapping.setTypeConverterFactory(server.getTypeConverterFactory());
+ mapping.load(Thread.currentThread().getContextClassLoader(), url);
+ return mapping;
}
/** Creates a new instance of {@link org.apache.xmlrpc.webserver.RequestData}
Modified: webservices/xmlrpc/trunk/src/site/apt/advanced.apt
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/site/apt/advanced.apt?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/src/site/apt/advanced.apt (original)
+++ webservices/xmlrpc/trunk/src/site/apt/advanced.apt Thu Jul 20 16:39:09 2006
@@ -7,9 +7,10 @@
Dynamic proxies
Dynamic proxies are an extremely comfortable way of Client programming.
- Basically, the idea is as follows: All handlers on the server side are
- splitted into interface and implementation. The client library contains
- the same interfaces. Now, rather than using the
+ Basically, the idea is as follows: All request processors on the server
+ side are splitted into interface and implementation. The interfaces are
+ shared between client and server, typically within some common jar file.
+ Now, rather than using the
{{{apidocs/org/apache/xmlrpc/client/XmlRpcClient.html}XmlRpcClient}}
directly,
the programmer creates an instance of
@@ -23,7 +24,7 @@
{{{apidocs/org/apache/xmlrpc/client/XmlRpcClient.html}XmlRpcClient}}.
Perhaps some code shows more than words. First of all, let's create
- an interface.
+ a request processor interface.
-----------------------------------------------------------------------------------
package com.foo;
@@ -33,7 +34,7 @@
}
-----------------------------------------------------------------------------------
- The server contains an implementation:
+ The server contains the request processors implementation:
-----------------------------------------------------------------------------------
package com.foo;
Modified: webservices/xmlrpc/trunk/src/site/apt/contributing.apt
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/site/apt/contributing.apt?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/src/site/apt/contributing.apt (original)
+++ webservices/xmlrpc/trunk/src/site/apt/contributing.apt Thu Jul 20 16:39:09 2006
@@ -10,10 +10,17 @@
Submitting Patches
- The preferred patch format is unidiff. Emails containing
- patches should be sent to the mailing list xmlrpc-dev@ws.apache.org, and
- prefix their subject lines with <<[PATCH]>>. Patches are also
- accepted via the {{{http://issues.apache.org/jira/browse/XMLRPC}issue tracker}}.
+ The preferred patch format is unidiff. The best way to generate a patch
+ is by checking out the sources, applying your changes and running
+
+---------------------------------------------------------------------------------
+ svn diff
+---------------------------------------------------------------------------------
+
+ Emails containing patches should be sent to the mailing list
+ xmlrpc-dev@ws.apache.org, and prefix their subject lines with <<[PATCH]>>.
+ Patches are also accepted via the
+ {{{http://issues.apache.org/jira/browse/XMLRPC}issue tracker}}.
The Jakarta project provides a description of
{{{http://jakarta.apache.org/site/source.html}life with ASF source code}}
-- look for the <<Patches>> section.
Modified: webservices/xmlrpc/trunk/src/site/apt/server.apt
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/site/apt/server.apt?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/src/site/apt/server.apt (original)
+++ webservices/xmlrpc/trunk/src/site/apt/server.apt Thu Jul 20 16:39:09 2006
@@ -22,8 +22,9 @@
The XML-RPC Servlet
- The easiest of creating an XML-RPC Server is the XmlRpcServlet. This
- servlet allows you to create a server within 10 minutes or so:
+ The easiest way to create an XML-RPC Server is the XmlRpcServlet, which
+ has an automatically embedded instance of XmlRpcServer. This servlet allows
+ you to create a server within 10 minutes or so:
[[1]] Create a class, or a set of classes, which are implementing
the remote procedure calls. Here's an example of such a class:
@@ -41,10 +42,7 @@
-----------------------------------------------------------------------------------
This class has two public, non-static methods, which should
- be available to the clients. The only important thing to
- consider is: The class must be stateless. In other words,
- it must not contain any non-final fields. (The same restriction
- applies, for example, to servlet classes.)
+ be available to the clients.
[[2]] Create a property file, which contains at least one property.
The property name is arbitrary, and the property value is the
Modified: webservices/xmlrpc/trunk/src/site/fml/faq.fml
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/site/fml/faq.fml?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/src/site/fml/faq.fml (original)
+++ webservices/xmlrpc/trunk/src/site/fml/faq.fml Thu Jul 20 16:39:09 2006
@@ -1,17 +1,4 @@
<faqs title="FAQ">
- <part id="general">
- <faq id="state">
- <question>What is the state of Apache XML-RPC, version 3?</question>
- <answer>
- <p>It is alpha software. In other words, it is not yet
- sufficiently mature. Most possibly, lots of details
- will change in the near future. Give it a try, if
- you like, but do not expect to use it without
- modifications in the medium term.</p>
- </answer>
- </faq>
- </part>
-
<part id="client">
<faq id="compression_request">
<question>How do I enable request compression?</question>
@@ -105,57 +92,44 @@
</faq>
<faq id="basic_authentication">
- <question>How do I enable streaming mode?</question>
+ <question>How do I configure the server for basic authentication?</question>
<answer>
- <p>Set the property "enabledForExtensions". Note, that enabling
- the streaming mode doesn't mean, that all responses are served
- in streaming mode. It depends on the clients:</p>
- <ul>
- <li>If a client sends a content-length header, then the server
- assumes, that the client is a traditional XML-RPC application
- and doesn't support the vendor extensions from Apache XML-RPC.
- Consequently, the server assumes, that it needs to set the
- content-length header itself and disables the streaming mode
- for that particular request.</li>
- <li>However, if the client doesn't send a content-length header,
- then the server assumes that it will be able to accept any
- standard HTTP/1.1 request and enable the streaming mode.
- Streaming mode means, in particular, that the response will
- not contain a content-length header.</li>
- </ul>
+ <p>Basically you've got to provide an AuthenticationHandler.
+ See the {{{server.html}server documentation}} for an example.</p>
</answer>
</faq>
<faq id="handler_initialization">
- <question>How do I initalize the handler objects?</question>
+ <question>How do I initalize the request processors?</question>
<answer>
- <p>The PropertyHandlerMapping assumes, that handlers are POJO's
- (plain old java objects). However, this is not always desirable.
- For example, sometimes it is assumed that handlers need to
- be initialized by the servlet, which is configured through
+ <p>The PropertyHandlerMapping assumes, that request processors are
+ POJO's (plain old java objects). However, this is not always
+ desirable. For example, sometimes it is assumed that handlers
+ need to be initialized by the servlet, which is configured through
parameters.</p>
- <p>The recommended solution is to create a subclass of the
- XmlRpcServlet, which in turn uses a subclass of the
- PropertyHandlerMapping:</p>
- <source><![CDATA[
-public interface InitializableHandler {
+ <p>The recommended solution is to configure your server with a
+ special request processor factory.</p>
+<source>
+public interface InitializableRequestProcessor {
void init(HttpServlet pServlet) throws XmlRpcException;
}
public class MyXmlRpcServlet extends XmlRpcServlet {
protected PropertyHandlerMapping newPropertyHandlerMapping(URL url) throws IOException, XmlRpcException {
- return new PropertyHandlerMapping(getClass().getClassLoader(), url){
- protected Object newHandlerObject(ClassLoader pClassLoader, String pClassName)
- throws XmlRpcException {
- Object o = super.newHandlerObject(pClassLoader, pClassName);
- ((InitializableHandler) o).init(MyXmlRpcServlet.this);
- return o;
- }
- };
+ PropertyHandlerMapping mapping = super.newPropertyHandlerMapping(url);
+ RequestProcessorFactoryFactory factory = new RequestSpecificProcessorFactoryFactory(){
+ protected Object newRequestProcessor(Class pClass, XmlRpcRequest pRequest) {
+ InitializableRequestProcessor proc = super.newRequestProcessor(pClass, pRequest);
+ proc.init(MyXmlRpcServlet.this);
+ return proc;
+ }
+ };
+ mapping.setRequestProcessorFactoryFactory(mapping);
+ return mapping;
}
}
- ]]></source>
+</source>
</answer>
</faq>
@@ -180,7 +154,7 @@
}
}
-public interface RequestInitializableHandler {
+public interface RequestInitializableRequestProcessor {
public void init(MyConfig pConfig);
}
@@ -196,14 +170,17 @@
};
}
protected PropertyHandlerMapping newPropertyHandlerMapping(URL url) throws IOException, XmlRpcException {
- PropertyHandlerMapping result = super.newPropertyHandlerMapping(url);
- result.setInitializableHandler(new InitializableHandler(){
- public void init(XmlRpcRequest pRequest, Object pObject)
- throws XmlRpcException {
- ((RequestInitializableHandler) pObject).init((MyConfig) pRequest.getConfig());
- }
- });
- return result;
+ PropertyHandlerMapping mapping = super.newPropertyHandlerMapping(url);
+ RequestProcessorFactoryFactory factory = new RequestSpecificProcessorFactoryFactory(){
+ protected Object newRequestProcessor(Class pClass, XmlRpcRequest pRequest) {
+ RequestInitializableRequestProcessor proc =
+ (RequestInitializableRequestProcessor) super.newRequestProcessor(pClass, pRequest);
+ proc.init(pRequest.getConfig());
+ return proc;
+ }
+ };
+ mapping.setRequestProcessorFactoryFactory(mapping);
+ return mapping;
}
}
]]></source>
Modified: webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/BaseTest.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/BaseTest.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/BaseTest.java (original)
+++ webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/BaseTest.java Thu Jul 20 16:39:09 2006
@@ -32,7 +32,6 @@
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.common.XmlRpcExtensionException;
-import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -280,10 +279,7 @@
}
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
- return new PropertyHandlerMapping(getClass().getClassLoader(),
- getClass().getResource("BaseTest.properties"),
- getTypeConverterFactory(),
- true);
+ return getHandlerMapping("BaseTest.properties");
}
/** Test, whether we can invoke a method, passing a byte value.
Modified: webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/DynamicProxyTest.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/DynamicProxyTest.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/DynamicProxyTest.java (original)
+++ webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/DynamicProxyTest.java Thu Jul 20 16:39:09 2006
@@ -20,7 +20,6 @@
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.util.ClientFactory;
-import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
@@ -46,10 +45,7 @@
}
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
- return new PropertyHandlerMapping(getClass().getClassLoader(),
- getClass().getResource("DynamicProxyTest.properties"),
- getTypeConverterFactory(),
- true);
+ return getHandlerMapping("DynamicProxyTest.properties");
}
private ClientFactory getClientFactory(ClientProvider pProvider) throws Exception {
Modified: webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java (original)
+++ webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java Thu Jul 20 16:39:09 2006
@@ -26,7 +26,6 @@
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.util.ClientFactory;
-import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
@@ -96,10 +95,7 @@
protected XmlRpcHandlerMapping getHandlerMapping() throws IOException,
XmlRpcException {
- return new PropertyHandlerMapping(getClass().getClassLoader(),
- getClass().getResource("JiraTest.properties"),
- getTypeConverterFactory(),
- true);
+ return getHandlerMapping("JiraTest.properties");
}
/**
Modified: webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java?rev=424115&r1=424114&r2=424115&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java (original)
+++ webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java Thu Jul 20 16:39:09 2006
@@ -22,6 +22,7 @@
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.common.TypeConverterFactory;
import org.apache.xmlrpc.common.TypeConverterFactoryImpl;
+import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
import junit.framework.TestCase;
@@ -42,6 +43,13 @@
XmlRpcClientConfigImpl config = getConfig(pProvider);
config.setEnabledForExtensions(true);
return config;
+ }
+
+ protected XmlRpcHandlerMapping getHandlerMapping(String pResource) throws IOException, XmlRpcException {
+ PropertyHandlerMapping mapping = new PropertyHandlerMapping();
+ mapping.load(getClass().getClassLoader(), getClass().getResource(pResource));
+ mapping.setTypeConverterFactory(getTypeConverterFactory());
+ return mapping;
}
public void setUp() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-dev-help@ws.apache.org