You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by dl...@apache.org on 2002/10/10 04:36:40 UTC

cvs commit: jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/xmlrpc TurbineXmlRpcService.java

dlr         2002/10/09 19:36:40

  Modified:    src/java/org/apache/fulcrum/xmlrpc TurbineXmlRpcService.java
  Log:
  Enhancements to support Apache XML-RPC versions 1.2 alpha 1 and 2.
  
  TurbineXmlRpcService.java:
  
  o Added an isModernVersion flag to support the more explicit start up
  semantics present versions > 1.1.
  
  o Made instance fields protected for easy sub-classing.
  
  o Added an address field of type InetAddress to support binding to
  specific network interfaces.
  
  o Acquired the configuration for the address field in init() and used
  the appropriate ctor.
  
  o Determined whether modern version by querying class loader for new
  XML-RPC class, and implemented explicit call to WebServer.start() for
  modern versions.
  
  o In shutdown(), only employ old "connect-to-close" work-around for
  old versions.  I've fixed this tricky shutdown problem in CVS.
  
  Fulcrum.master:
  
  o Added new services.XmlRpcService.address property, defaulted to
  127.0.0.1 (which Java's InetAddress.getByName(String) happily resolves
  on Linux).
  
  o Clarified comment and used more realistic port for the
  services.XmlRpcService.port property.
  
  Revision  Changes    Path
  1.2       +66 -19    jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/xmlrpc/TurbineXmlRpcService.java
  
  Index: TurbineXmlRpcService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/xmlrpc/TurbineXmlRpcService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- TurbineXmlRpcService.java	30 May 2002 02:27:40 -0000	1.1
  +++ TurbineXmlRpcService.java	10 Oct 2002 02:36:39 -0000	1.2
  @@ -59,6 +59,7 @@
   import java.io.InputStream;
   import java.net.InetAddress;
   import java.net.Socket;
  +import java.net.UnknownHostException;
   import java.net.URL;
   import java.util.Iterator;
   import java.util.Vector;
  @@ -106,14 +107,26 @@
       extends BaseService
       implements XmlRpcService
   {
  +    /**
  +     * Whether a version of Apache's XML-RPC library greater than 1.1
  +     * is available.
  +     */
  +    protected boolean isModernVersion = false;
  +
       /** The standalone xmlrpc server. */
  -    private WebServer webserver = null;
  +    protected WebServer webserver = null;
   
       /** The encapsulated xmlrpc server. */
  -    private XmlRpcServer server = null;
  +    protected XmlRpcServer server = null;
  +
  +    /**
  +     * The address to listen on.  The default of <code>null</code>
  +     * indicates all network interfaces on a multi-homed host.
  +     */
  +    private InetAddress address = null;
   
       /** The port to listen on. */
  -    private int port = 0;
  +    protected int port = 0;
   
       /**
        * This function initializes the XmlRpcService.
  @@ -130,18 +143,28 @@
                   getConfiguration().subset("secure.server.option");
               setSystemPropertiesFromConfiguration(secureServerOptions);
   
  -            // Set the port for the service
  +            // Host and port information for the WebServer
  +            String addr = getConfiguration().getString("address", null);
               port = getConfiguration().getInt("port", 0);
   
               if(port != 0)
               {
  +                try
  +                {
  +                    address = InetAddress.getByName(addr);
  +                }
  +                catch (UnknownHostException useDefault)
  +                {
  +                    address = null;
  +                }
  +
                   if (getConfiguration().getBoolean("secure.server", false))
                   {
  -                    webserver = new SecureWebServer(port);
  +                    webserver = new SecureWebServer(port, address);
                   }
                   else
                   {
  -                    webserver = new WebServer(port);
  +                    webserver = new WebServer(port, address);
                   }
               }
   
  @@ -211,6 +234,24 @@
                       }
                   }
               }
  +
  +            // If we have a XML-RPC JAR whose version is greater than the
  +            // 1.1 series, the WebServer must be explicitly start()'d.
  +            try
  +            {
  +                Class.forName("org.apache.xmlrpc.XmlRpcRequest");
  +                isModernVersion = true;
  +                webserver.start();
  +            }
  +            catch (ClassNotFoundException ignored)
  +            {
  +                // XmlRpcRequest does not exist in versions 1.1 and lower.
  +                // Assume that our WebServer was already started.
  +            }
  +            getCategory().debug(XmlRpcService.SERVICE_NAME + ": Using " +
  +                                "Apache XML-RPC version " +
  +                                (isModernVersion ?
  +                                 "greater than 1.1" : "1.1 or lower"));
           }
           catch (Exception e)
           {
  @@ -626,20 +667,26 @@
        */
       public void shutdown()
       {
  -        // Stop the XML RPC server.  org.apache.xmlrpc.WebServer blocks in a call to
  -        // ServerSocket.accept() until a socket connection is made.
  +        // Stop the XML RPC server.
           webserver.shutdown();
  -        try
  -        {
  -            Socket interrupt = new Socket(InetAddress.getLocalHost(), port);
  -            interrupt.close();
  -        }
  -        catch (Exception notShutdown)
  +
  +        if (!isModernVersion)
           {
  -            // Remotely possible we're leaving an open listener socket around.
  -            getCategory().warn(XmlRpcService.SERVICE_NAME +
  -                "It's possible the xmlrpc server was not shutdown: " + 
  -                notShutdown.getMessage());
  +            // org.apache.xmlrpc.WebServer used to block in a call to
  +            // ServerSocket.accept() until a socket connection was made.
  +            try
  +            {
  +                Socket interrupt = new Socket(address, port);
  +                interrupt.close();
  +            }
  +            catch (Exception notShutdown)
  +            {
  +                // It's remotely possible we're leaving an open listener
  +                // socket around.
  +                getCategory().warn(XmlRpcService.SERVICE_NAME +
  +                                   "It's possible the xmlrpc server was not " +
  +                                   "shutdown: " + notShutdown.getMessage());
  +            }
           }
   
           setInit(false);
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>