CVS: plexus-components/xmlrpc/src/java/org/apache/plexus/xmlrpc DefaultXmlRpcComponent.java,1.2,1.3 XmlRpcComponent.java,1.1.1.1,1.2
[email protected] Sun, 27 Apr 2003 20:54:45 -0500
| Newsgroups | gmane.comp.java.plexus.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/plexus/plexus-components/xmlrpc/src/java/org/apache/plexus/xmlrpc In directory eng.werken.com:/tmp/cvs-serv10907/src/java/org/apache/plexus/xmlrpc Modified Files: DefaultXmlRpcComponent.java XmlRpcComponent.java Log Message: o Conversion to plexus 0.4. Index: DefaultXmlRpcComponent.java =================================================================== RCS file: /cvsroot/plexus/plexus-components/xmlrpc/src/java/org/apache/plexus/xmlrpc/DefaultXmlRpcComponent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- DefaultXmlRpcComponent.java 24 Feb 2003 18:21:56 -0000 1.2 +++ DefaultXmlRpcComponent.java 28 Apr 2003 01:54:39 -0000 1.3 @@ -56,54 +56,45 @@ * ---------------------------------------------------------------------------- */ -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.Socket; -import java.net.URL; -import java.util.Iterator; -import java.util.Vector; -import java.util.List; -import java.util.ArrayList; - -import org.apache.plexus.xmlrpc.handler.FileHandler; -import org.apache.plexus.xmlrpc.handler.DirectFileHandler; - -import org.apache.xmlrpc.WebServer; -import org.apache.xmlrpc.XmlRpc; -import org.apache.xmlrpc.XmlRpcClient; -import org.apache.xmlrpc.XmlRpcException; -import org.apache.xmlrpc.XmlRpcServer; -import org.apache.xmlrpc.secure.SecureWebServer; -import org.apache.xmlrpc.secure.SecurityTool; - import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.activity.Startable; -import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; -import org.apache.avalon.framework.logger.Logger; -import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.avalon.framework.context.Context; +import org.apache.avalon.framework.context.ContextException; +import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.xmlrpc.WebServer; +import org.apache.xmlrpc.XmlRpc; +import org.apache.xmlrpc.XmlRpcClient; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.secure.SecureWebServer; -import org.apache.plexus.service.ServiceBroker; -import org.apache.plexus.service.Serviceable; - +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; /** * * @author <a href="mailto:[email protected]">Jason van Zyl</a> * @version $Id$ - * @task Handle XmlRpc.setDebug(boolean) + * @todo Handle XmlRpc.setDebug(boolean) */ public class DefaultXmlRpcComponent - extends AbstractLogEnabled - implements XmlRpcComponent, Configurable, Startable, Disposable, Serviceable + extends org.apache.plexus.logging.AbstractLogEnabled + implements Contextualizable,Configurable, Initializable, Startable, Disposable, Serviceable, XmlRpcComponent { - /** The service broker for this component. */ - private ServiceBroker broker; + /** The service manager for this component. */ + private ServiceManager manager; /** The standalone xmlrpc server. */ private WebServer webserver; @@ -111,9 +102,6 @@ /** The port to listen on. */ private int port; - /** Configuration */ - private Configuration configuration; - /** Secure server state. */ private boolean isSecureServer; @@ -135,23 +123,29 @@ /** Message Listeners. */ private List listeners; + /** ClassLoader */ + private ClassLoader classLoader; + /** Default Constructor. */ public DefaultXmlRpcComponent() { listeners = new ArrayList(); } - // ------------------------------------------------------------------------ - // C O N F I G U R A T I O N - // ------------------------------------------------------------------------ - + // ---------------------------------------------------------------------- + // Lifecylce Management + // ---------------------------------------------------------------------- + + /** @see Contextualizable#contextualize */ + public void contextualize( Context context ) + throws ContextException + { + classLoader = (ClassLoader) context.get( "common.classloader" ); + } + public void configure(Configuration configuration) throws ConfigurationException { - this.configuration = configuration; - - getLogger().debug( "Configuring the DefaultXmlRpcComponent" ); - // Set system properties. These are required if you're // using SSL. setSystemPropertiesFromConfiguration(configuration); @@ -180,20 +174,21 @@ // Set the list of clients that can connect // to the xmlrpc server. The accepted client list // will only be consulted if we are paranoid. - Configuration[] acceptedClients = configuration.getChildren("acceptedClients"); + acceptedClients = configuration.getChildren("acceptedClients"); // Set the list of clients that can connect // to the xmlrpc server. The denied client list // will only be consulted if we are paranoid. - Configuration[] deniedClients = configuration.getChildren("deniedClients"); + deniedClients = configuration.getChildren("deniedClients"); } /* (non-Javadoc) * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) */ - public void service(ServiceBroker broker) throws ServiceException + public void service(ServiceManager manager) + throws ServiceException { - this.broker = broker; + this.manager = manager; } /** @@ -229,17 +224,21 @@ // S T A R T A B L E // ------------------------------------------------------------------------ + public void start() + throws Exception + { + } + /** * This function initializes the XmlRpcService. */ - public void start() + public void initialize() throws Exception { - getLogger().debug( "Attempting to initialize the server" ); + //getLogger().info( "Attempting to start the XML-RPC server." ); + System.out.println( "Attempting to start the XML-RPC server." ); - try - { - + // Need a default value here. if (isSecureServer) { @@ -290,14 +289,6 @@ } } } - } - catch (Exception e) - { - e.printStackTrace(); - - throw new ComponentException - ("Failed to initialize", e); - } } /** @@ -311,6 +302,9 @@ { Configuration[] handlers = handlerConfiguration.getChildren("handler"); + getLogger().info( "We have " + handlers.length + " to configure." ); + System.out.println( "We have " + handlers.length + " to configure." ); + for (int i = 0; i < handlers.length; i++) { Configuration c = handlers[i]; @@ -377,8 +371,8 @@ * Register an Object as a default handler for the service. * * @param handler The handler to use. - * @exception XmlRpcException. - * @exception IOException. + * @exception XmlRpcException + * @exception IOException */ public void registerHandler(Object handler) throws XmlRpcException, IOException @@ -391,8 +385,8 @@ * * @param handlerName The name the handler is registered under. * @param handler The handler to use. - * @exception XmlRpcException. - * @exception IOException. + * @throws XmlRpcException If an XmlRpcException occurs. + * @throws IOException If an IOException occurs. */ public void registerHandler(String handlerName, Object handler) @@ -416,15 +410,9 @@ { try { - Object handler = Class.forName(handlerClass).newInstance(); - - if (handler instanceof DirectFileHandler) - { - ((DirectFileHandler)handler).setReceptor(this); - } - + Object handler = classLoader.loadClass( handlerClass ).newInstance(); webserver.addHandler(handlerName,handler); - getLogger().debug("registered: " + handlerName + " with class: " + handlerClass); + getLogger().info("registered: " + handlerName + " with class: " + handlerClass); } // those two errors must be passed to the VM @@ -439,8 +427,7 @@ catch( Throwable t ) { - throw new ComponentException - ("Failed to instantiate " + handlerClass, t); + throw new Exception ("Failed to instantiate " + handlerClass, t); } } @@ -450,14 +437,13 @@ * * @param handlerName The name to register this handle as. * @param handlerRole The role of the component serving as the handler. - * @exception If the component could not be looked up. + * @exception Exception If the component could not be looked up. */ private void registerComponentHandler(String handlerName, String handlerRole) throws Exception { - registerHandler(handlerName, broker.lookup(handlerRole)); - getLogger().debug("registered: " + handlerName + " with component: " + handlerRole); - + registerHandler(handlerName, manager.lookup(handlerRole)); + getLogger().info("registered: " + handlerName + " with component: " + handlerRole); } /** @@ -480,8 +466,8 @@ * @param methodName A String with the method name. * @param params A Vector with the parameters. * @return An Object. - * @exception XmlRpcException. - * @exception IOException. + * @exception XmlRpcException + * @exception IOException */ public Object executeRpc(URL url, String methodName, @@ -495,176 +481,7 @@ } catch (Exception e) { - throw new ComponentException("XML-RPC call failed", e); - } - } - - /** - * Method to allow a client to send a file to a server. - * - * @param serverURL - * @param sourceLocationProperty - * @param sourceFileName - * @param destinationLocationProperty - * @param destinationFileName - */ - public void send(String serverURL, - String sourceLocationProperty, - String sourceFileName, - String destinationLocationProperty, - String destinationFileName) - throws Exception - { - try - { - Vector params = new Vector(); - FileHandler fh = new FileHandler(); - - // FileContents - params.add(fh.readFileContents( - sourceLocationProperty, sourceFileName)); - - // Property in TR.props which refers to the directory - // where the fileContents should land. - params.add(destinationLocationProperty); - - // Name to give the file contents. - params.add(destinationFileName); - - Boolean b = (Boolean) executeRpc( new URL (serverURL), "file.send", params ); - - } - catch (Exception e) - { - getLogger().error("Error sending file to server:", e); - throw new ComponentException(e.toString()); - } - } - - /** - * Method to allow a client to send a file to a server. - * - * @param serverURL - * @param sourceLocation - * @param sourceFileName - * @param destinationLocation - */ - public void send(String serverURL, - String sourceFileName, - String destinationLocation) - throws Exception - { - DirectFileHandler fh = new DirectFileHandler(); - sendMessage(serverURL, fh.readFileContents(sourceFileName), destinationLocation); - } - - /** - * Method to allow a client to send a file to a server. - * - * @param serverURL - * @param sourceLocation - * @param sourceFileName - * @param destinationLocation - */ - public void sendMessage(String serverURL, - String message, - String destinationLocation) - throws Exception - { - try - { - Vector params = new Vector(); - DirectFileHandler fh = new DirectFileHandler(); - - // FileContents - params.add(message); - - // Property in TR.props which refers to the directory - // where the fileContents should land. - params.add(destinationLocation); - - Boolean b = (Boolean) executeRpc( new URL (serverURL), "directfile.send", params ); - - } - catch (Exception e) - { - getLogger().error("Error sending file to server:", e); - throw new ComponentException(e.toString()); - } - } - - /** - * Method to allow a client to get a file from a server. - * - * @param serverURL - * @param sourceLocationProperty - * @param sourceFileName - * @param destinationLocationProperty - * @param destinationFileName - */ - public void get(String serverURL, - String sourceLocationProperty, - String sourceFileName, - String destinationLocationProperty, - String destinationFileName) - throws Exception - { - try - { - Vector params = new Vector(); - FileHandler fh = new FileHandler(); - - // property in TR.props which refers to the directory - // where the fileContents should land. - params.add(sourceLocationProperty); - - // Name to give the file contents. - params.add(sourceFileName); - - String fileContents = (String) executeRpc( new URL (serverURL), "file.get", params ); - - // Now we have the file contents, we can write - // them out to disk. - fh.writeFileContents(fileContents, - destinationLocationProperty, destinationFileName); - } - catch (Exception e) - { - getLogger().error("Error getting file from server:", e); - throw new ComponentException(e.toString()); - } - } - - /** - * Method to allow a client to remove a file from - * the server - * - * @param serverURL - * @param sourceLocationProperty - * @param sourceFileName - */ - public void remove(String serverURL, - String sourceLocationProperty, - String sourceFileName) - throws Exception - { - try - { - Vector params = new Vector(); - - // property in TR.props which refers to the directory - // where the fileContents should land. - params.add(sourceLocationProperty); - - // Name to give the file contents. - params.add(sourceFileName); - - executeRpc(new URL (serverURL), "file.remove", params); - } - catch (Exception e) - { - getLogger().error("Error removing file from server:", e); - throw new ComponentException(e.toString()); + throw new Exception("XML-RPC call failed", e); } } @@ -729,5 +546,4 @@ listener.xmlRpcMessageReceived( message ); } } - } Index: XmlRpcComponent.java =================================================================== RCS file: /cvsroot/plexus/plexus-components/xmlrpc/src/java/org/apache/plexus/xmlrpc/XmlRpcComponent.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- XmlRpcComponent.java 15 Feb 2003 03:56:08 -0000 1.1.1.1 +++ XmlRpcComponent.java 28 Apr 2003 01:54:39 -0000 1.2 @@ -125,62 +125,6 @@ void unregisterHandler(String handlerName); /** - * Method to allow a client to send a file to a server. - * - * @param serverURL - * @param sourceLocationProperty - * @param sourceFileName - * @param destinationLocationProperty - * @param destinationFileName - */ - void send(String serverURL, - String sourceLocationProperty, - String sourceFileName, - String destinationLocationProperty, - String destinationFileName) - throws Exception; - - - void send(String serverURL, - String sourceFileName, - String destinationLocation) - throws Exception; - - void sendMessage(String serverURL, - String message, - String destinationLocation) - throws Exception; - - /** - * Method to allow a client to send a file to a server. - * - * @param serverURL - * @param sourceLocationProperty - * @param sourceFileName - * @param destinationLocationProperty - * @param destinationFileName - */ - void get(String serverURL, - String sourceLocationProperty, - String sourceFileName, - String destinationLocationProperty, - String destinationFileName) - throws Exception; - - /** - * Method to allow a client to remove a file from - * the server - * - * @param serverURL - * @param sourceLocationProperty - * @param sourceFileName - */ - void remove(String serverURL, - String sourceLocationProperty, - String sourceFileName) - throws Exception; - - /** * Switch client filtering on/off. * @see #acceptClient(java.lang.String) * @see #denyClient(java.lang.String)