InitializationHandler (vs InstantiationHandler)
Hi! After some work I managed to get 3.0b1 up and running just fine. However, I have a question about / some input on the inner-workings of ReflectiveXmlRpcHandler that I saw when I checked the code. I have a state-less instance, but it needs to be initalized with some objects initally. This might not be state-less in a technical term, but it is something that I find useful (and hopefully others as well). In my case the instance needs access to the underlying data storage. I don't want the instance to be created over-and-over again which seems to be the case if I use the InitializationHandler: 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; } } The problem, as I see it, is that just because the InitializationHandler exists a new instance is created each time. Are pInstanceIsStateless and InitializationHandler really meant to be mutual exclusive? A) If not, then I propose that an easy fix would be to change the constructor so that the InitializationHandler is run. Hence, change the constructur from theInstance ? pInstanceIsStateless ? newInstance() : null; to theInstance ? pInstanceIsStateless ? this.getInstance() : null; B) If they are mutual exclusive I propose a instantiationHandler/ConstructorHandler This handler will then, if it exists (!= null) in the ReflectiveXmlRpcHandler, instantiate the class and allows for a non-default constructor to be run when the instance is created. It might only happen once (if pInstanceIsStateless == true), whileas the InitializationHandler (if it exists) would be run everytime getInstance is called. I gladly provide a patch for either solution if you find it interesting. Will it be able to make the 3.0 final then? Regards, Jimisola -- View this message in context: http://www.nabble.com/InitializationHandler-%28vs-InstantiationHandler%29-tf1963850.html#a5388986 Sent from the Apache Xml-RPC - Dev forum at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[jira] Created: (XMLRPC-96) Dynamic proxy implementation throws NullPointerException if called methods doesn't have any parameters
Dynamic proxy implementation throws NullPointerException if called methods doesn't have any parameters -- Key: XMLRPC-96 URL: http://issues.apache.org/jira/browse/XMLRPC-96 Project: XML-RPC Issue Type: Bug Affects Versions: 3.0b1 Reporter: Jimisola Laursen I'm using the Dynamic Proxy solution and created an interface with a method that doesn't take any parameters. When I call it I get a NPE: "java.lang.NullPointerException: The parameter list must not be null.". If I add a parameter, e.g. an int, to the method it works without and doesn't throw this exception. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
svn commit: r423227 - /webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/PropertyHandlerMapping.java
Author: jochen Date: Tue Jul 18 13:06:13 2006 New Revision: 423227 URL: http://svn.apache.org/viewvc?rev=423227&view=rev Log: Added the suggestion to use the ServletWebServer and not the raw WebServer, if more detailed request information is required. Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/PropertyHandlerMapping.java 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=423227&r1=423226&r2=423227&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 Tue Jul 18 13:06:13 2006 @@ -26,19 +26,14 @@ import org.apache.xmlrpc.common.TypeConverterFactory; -/** A handler mapping based on a property file. The property file +/** + * A handler mapping based on a property file. The property file * contains a set of properties. The property key is taken as the * handler name. The property value is taken as the name of a * class being instantiated. For any non-void, non-static, and * public method in the class, an entry in the handler map is - * generated. - * The following constrains apply to the classes: - * - * The classes must be stateless. In other words, any - * instance of the class must be completely thread safe. - * - * A typical use would be, to specify interface names as the - * property keys and implementations as the values. + * generated. A typical use would be, to specify interface names + * as the property keys and implementations as the values. */ public class PropertyHandlerMapping extends AbstractReflectiveHandlerMapping { /** Creates a new instance, loading the property file - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
svn commit: r423226 - in /webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver: ServletWebServer.java WebServer.java XmlRpcServlet.java
Author: jochen Date: Tue Jul 18 13:05:46 2006 New Revision: 423226 URL: http://svn.apache.org/viewvc?rev=423226&view=rev Log: Improved docs of WebServer and ServletWebServer classes. Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/ServletWebServer.java webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/WebServer.java webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.java Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/ServletWebServer.java URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/ServletWebServer.java?rev=423226&r1=423225&r2=423226&view=diff == --- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/ServletWebServer.java (original) +++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/ServletWebServer.java Tue Jul 18 13:05:46 2006 @@ -26,12 +26,35 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; +import org.apache.xmlrpc.server.PropertyHandlerMapping; import org.apache.xmlrpc.server.XmlRpcStreamServer; import org.apache.xmlrpc.util.ThreadPool; -/** A subclass of [EMAIL PROTECTED] WebServer}, which emulates a servlet - * container. Mainly useful for debugging. +/** + * This is a subclass of the [EMAIL PROTECTED] WebServer}, which offers a minimal + * servlet API. It is recommended to use this class, rather than the + * [EMAIL PROTECTED] WebServer}, because it offers you a smooth migration path to + * a full blown servlet engine. + * Use of the [EMAIL PROTECTED] ServletWebServer} goes like this: First of all, + * create a servlet. It may be an instance of [EMAIL PROTECTED] XmlRpcServlet} or + * a subclass thereof. Note, that servlets are stateless: One servlet + * may be used by multiple threads (aka requests) concurrently. In + * other words, the servlet must not have any instance variables, + * other than those which are read only after the servlets + * initialization. + * The XmlRpcServlet is by default using a property file named + * org/apache/xmlrpc/server/webserver/XmlRpcServlet.properties. + * See the [EMAIL PROTECTED] PropertyHandlerMapping} for details on the property + * file. + * + * final int portNumber = 8088; + * + * ClassLoader cl = Thread.currentThread().getContextClassLoader(); + * XmlRpcServlet servlet = new XmlRpcServlet(); + * ServletWebServer webServer = new ServletWebServer(servlet, port); + * webServer.start(); + * */ public class ServletWebServer extends WebServer { /** This exception is thrown by the request handling classes, Modified: webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/WebServer.java URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/WebServer.java?rev=423226&r1=423225&r2=423226&view=diff == --- webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/WebServer.java (original) +++ webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/WebServer.java Tue Jul 18 13:05:46 2006 @@ -32,7 +32,45 @@ import org.apache.xmlrpc.util.ThreadPool; -/** A minimal web server that exclusively handles XML-RPC requests. +/** + * The [EMAIL PROTECTED] WebServer} is a minimal HTTP server, that might be used + * as an embedded web server. + * Use of the [EMAIL PROTECTED] WebServer} has grown very popular amongst users + * of Apache XML-RPC. Why this is the case, can hardly be explained, + * because the [EMAIL PROTECTED] WebServer} is at best a workaround, compared to + * full blown servlet engines like Tomcat or Jetty. For example, under + * heavy load it will almost definitely be slower than a real servlet + * engine, because it does neither support proper keepalive (multiple + * requests per physical connection) nor chunked mode (in other words, + * it cannot stream requests). + * If you still insist in using the [EMAIL PROTECTED] WebServer}, it is + * recommended to use its subclass, the [EMAIL PROTECTED] ServletWebServer} instead, + * which offers a minimal subset of the servlet API. In other words, + * you keep yourself the option to migrate to a real servlet engine + * later. + * Use of the [EMAIL PROTECTED] WebServer} goes roughly like this: First of all, + * create a property file (for example "MyHandlers.properties") and + * add it to your jar file. The property keys are handler names and + * the property values are the handler classes. Once that is done, + * create an instance of WebServer: + * + * final int portNumber = 8088; + * final String propertyFile = "MyHandler.properties"; + * + * ClassLoader cl = Thread.currentThread().getContextClassLoader(); + *
[jira] Closed: (XMLRPC-95) Client hangs on execute
[ http://issues.apache.org/jira/browse/XMLRPC-95?page=all ] Jochen Wiedmann closed XMLRPC-95. - Resolution: Invalid Ok, here is your fault: The class you give to the DynamicHandlerMapping is no other than your own RpcServer(). Now, when a request comes in, an instance of RpcServer is created, in order to call its method "loginUser". In other words: The constructor of RpcServer is executed before the loginUser method. In particular, a new instance of WebServer with port 3099 is created. However, this port is no longer free: A first instance of WebServer was already created (the instance, which is currently accepting the request), thus the port 3099 is blocked and the constructor waits ... and waits ... until the port might be free or a timeout occurs. Fix: Create a new class (for example "LoginHandler") with a default constructor, move the "loginUser" method to that class and replace the RpcServer.class in the handler mapping with "LoginHandler". That's all. > Client hangs on execute > --- > > Key: XMLRPC-95 > URL: http://issues.apache.org/jira/browse/XMLRPC-95 > Project: XML-RPC > Issue Type: Bug > Components: Releases >Affects Versions: 3.0b1 > Environment: Win XP > Java 1.5.0_06 >Reporter: Bit Buzzer > > Problem description: > When this server is running and the client is executed, nothing happens. > The client hangs on the "execute" statement, and neither of them throws > any exception or message. > No indication what goes wrong or were the problem exists. > Server code: > ### > import java.io.IOException; > import org.apache.xmlrpc.XmlRpcException; > import org.apache.xmlrpc.common.TypeConverterFactoryImpl; > import org.apache.xmlrpc.server.DynamicHandlerMapping; > import org.apache.xmlrpc.server.XmlRpcServerConfigImpl; > import org.apache.xmlrpc.webserver.WebServer; > public class RpcServer { > static int port = 3099; > private WebServer server; > > public static void main(String[] args) { > new RpcServer(); > } > > public RpcServer(){ > try { > server = new WebServer(port); > XmlRpcServerConfigImpl config = new > XmlRpcServerConfigImpl(); > config.setEnabledForExtensions(true); > config.setContentLengthOptional(true); > > DynamicHandlerMapping dhm = new > DynamicHandlerMapping(new TypeConverterFactoryImpl(), false); > dhm.addHandler("Start", this.getClass()); > > server.getXmlRpcServer().setConfig(config); > server.getXmlRpcServer().setHandlerMapping(dhm); > > server.start(); > > System.out.println("RPC server running. "); > } > catch (XmlRpcException e) { > System.out.println("RPC EXcep"); > e.printStackTrace(); > } > catch (IOException e) { > System.out.println("IO EXcep"); > e.printStackTrace(); > } > } > > public int loginUser(String userId ) { > System.out.println("In de method"); > return 0; >} > } > ### > Server includes following jars: > - commons-logging-1.1.jar > - ws-commons-util-1.0-SNAPSHOT.jar > - xmlrpc-common-3.0b1.jar > - xmlrpc-server-3.0b1.jar > Client code: > ### > import java.net.URL; > import java.util.List; > import java.util.Vector; > import org.apache.xmlrpc.client.XmlRpcClient; > import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; > public class RpcClient { > static XmlRpcClient xmlrpc; > > public static void main( String args[] ) { > try { > List params = new Vector(); > params.add( "48504852" ); > > XmlRpcClientConfigImpl config = new > XmlRpcClientConfigImpl(); > config.setServerURL(new > URL("http://192.168.1.1:3099/";)); > config.s
[jira] Created: (XMLRPC-95) Client hangs on execute
Client hangs on execute --- Key: XMLRPC-95 URL: http://issues.apache.org/jira/browse/XMLRPC-95 Project: XML-RPC Issue Type: Bug Components: Releases Affects Versions: 3.0b1 Environment: Win XP Java 1.5.0_06 Reporter: Bit Buzzer Problem description: When this server is running and the client is executed, nothing happens. The client hangs on the "execute" statement, and neither of them throws any exception or message. No indication what goes wrong or were the problem exists. Server code: ### import java.io.IOException; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.common.TypeConverterFactoryImpl; import org.apache.xmlrpc.server.DynamicHandlerMapping; import org.apache.xmlrpc.server.XmlRpcServerConfigImpl; import org.apache.xmlrpc.webserver.WebServer; public class RpcServer { static int port = 3099; private WebServer server; public static void main(String[] args) { new RpcServer(); } public RpcServer(){ try { server = new WebServer(port); XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl(); config.setEnabledForExtensions(true); config.setContentLengthOptional(true); DynamicHandlerMapping dhm = new DynamicHandlerMapping(new TypeConverterFactoryImpl(), false); dhm.addHandler("Start", this.getClass()); server.getXmlRpcServer().setConfig(config); server.getXmlRpcServer().setHandlerMapping(dhm); server.start(); System.out.println("RPC server running. "); } catch (XmlRpcException e) { System.out.println("RPC EXcep"); e.printStackTrace(); } catch (IOException e) { System.out.println("IO EXcep"); e.printStackTrace(); } } public int loginUser(String userId ) { System.out.println("In de method"); return 0; } } ### Server includes following jars: - commons-logging-1.1.jar - ws-commons-util-1.0-SNAPSHOT.jar - xmlrpc-common-3.0b1.jar - xmlrpc-server-3.0b1.jar Client code: ### import java.net.URL; import java.util.List; import java.util.Vector; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; public class RpcClient { static XmlRpcClient xmlrpc; public static void main( String args[] ) { try { List params = new Vector(); params.add( "48504852" ); XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setServerURL(new URL("http://192.168.1.1:3099/";)); config.setEnabledForExtensions(true); config.setContentLengthOptional(true); xmlrpc = new XmlRpcClient(); xmlrpc.setConfig(config); Integer r = (Integer) xmlrpc.execute ("Start.loginUser", params); System.out.println(r); } catch (Exception e) { e.printStackTrace(); } } } ### Client includes following jars: - ws-commons-util-1.0-SNAPSHOT.jar - xmlrpc-common-3.0b1.jar - xmlrpc-client-3.0b1.jar -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira -