pier        01/07/19 16:59:15

  Added:       catalina/src/share/org/apache/catalina/connector/warp
                        Constants.java WarpConfigurationHandler.java
                        WarpLogger.java
  Log:
  New WARP classes.
  
  Revision  Changes    Path
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/Constants.java
  
  Index: Constants.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "Tomcat",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
   * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
   * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  package org.apache.catalina.connector.warp;
  
  public class Constants {
      /** Our package name. */
      public static final String PACKAGE="org.apache.catalina.connector.warp";
  
      /** Compile-in debug flag. */
      public static final boolean DEBUG=false;
  
      /**
       * The WARP protocol major version.
       */
      public static final int VERS_MAJOR=0;
  
      /**
       * The WARP protocol minor version.
       */
      public static final int VERS_MINOR=9;
  
      /**
       * INVALID: The packet type hasn't been set yet.
       */
      public static final int TYPE_INVALID=-1;
  
      /**
       * ERROR: The last operation didn't completed correctly.
       * <br>
       * Payload description:<br>
       * [string] An error message.<br>
       */
      public static final int TYPE_ERROR=0x00;
  
      /**
       * DISCONNECT: The connection is being closed.
       * <br>
       * No payload:<br>
       */
      public static final int TYPE_DISCONNECT=0xfe;
  
      /**
       * FATAL: A protocol error occourred, the connection must be closed.
       * <br>
       * Payload description:<br>
       * [string] An error message.<br>
       */
      public static final int TYPE_FATAL=0xff;
  
      /**
       * CONF_WELCOME: The server issues this packet when a connection is
       * opened. The server awaits for configuration information.
       * <br>
       * Payload description:<br>
       * [ushort] Major protocol version.<br>
       * [ushort] Minor protocol version.<br>
       * [integer] The server unique-id.<br>
       */
      public static final int TYPE_CONF_WELCOME=0x01;
  
      /**
       * CONF_DEPLOY: The client attempts deploy a web application.
       * <br>
       * Payload description:<br>
       * [string] The application name.<br>
       * [string] The virtual host name.<br>
       * [ushort] The virtual host port.<br>
       * [string] The web-application URL path.<br>
       */
      public static final int TYPE_CONF_DEPLOY=0x02;
  
      /**
       * CONF_APPLIC: The server replies to a CONF_DEPLOY message with the web
       * application identifier of the configured application.
       * <br>
       * Payload description:<br>
       * [integer] The web application unique id for this server.<br>
       * [string] The web application real path (where it's expanded).<br>
       */
      public static final int TYPE_CONF_APPLIC=0x03;
  
      /**
       * CONF_DONE: Client issues this message when all configurations have been
       * processed.
       * <br>
       * No payload:<br>
       */
      public static final int TYPE_CONF_DONE=0x04;
  
      /**
       * CONF_PROCEED: Server issues this message in response to a CONF_DONE
       * message, to acknowledge its readiness to accept requests.
       * <br>
       * No payload:<br>
       */
      public static final int TYPE_CONF_PROCEED=0x05;
      
      public static final int TYPE_REQ_INIT=0x10;
      public static final int TYPE_REQ_CONTENT=0x11;
      public static final int TYPE_REQ_SCHEME=0x12;
      public static final int TYPE_REQ_AUTH=0x13;
      public static final int TYPE_REQ_HEADER=0x14;
      public static final int TYPE_REQ_PROCEED=0x1f;
      
      public static final int TYPE_RES_STATUS=0x20;
      public static final int TYPE_RES_HEADER=0x21;
      public static final int TYPE_RES_COMMIT=0x2f;
      public static final int TYPE_RES_BODY=0x30;
      public static final int TYPE_RES_DONE=0x3f;
  
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConfigurationHandler.java
  
  Index: WarpConfigurationHandler.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "Tomcat",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
   * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
   * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  package org.apache.catalina.connector.warp;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.URL;
  
  import org.apache.catalina.Container;
  import org.apache.catalina.Context;
  import org.apache.catalina.Deployer;
  import org.apache.catalina.Host;
  import org.apache.catalina.core.StandardHost;
  import org.apache.catalina.core.StandardContext;
  
  public class WarpConfigurationHandler {
  
      /* ==================================================================== */
      /* Constructor                                                          */
      /* ==================================================================== */
  
      public WarpConfigurationHandler() {
          super();
      }
  
      public boolean handle(WarpConnection connection, WarpPacket packet)
      throws IOException {
          WarpLogger logger=new WarpLogger(this);
          logger.setContainer(connection.getConnector().getContainer());
  
          // Prepare the Welcome packet
          packet.setType(Constants.TYPE_CONF_WELCOME);
          packet.writeUnsignedShort(Constants.VERS_MAJOR);
          packet.writeUnsignedShort(Constants.VERS_MINOR);
          packet.writeInteger(connection.getConnector().uniqueId);
          connection.send(packet);
  
          // Loop for configuration packets
          while (true) {        
              connection.recv(packet);
              
              switch (packet.getType()) {
  
                  case Constants.TYPE_CONF_DEPLOY: {
                      String appl=packet.readString();
                      String host=packet.readString();
                      int port=packet.readUnsignedShort();
                      String path=packet.readString();
                      Context context=null;
                      packet.reset();
  
                      if (Constants.DEBUG) 
                          logger.log("Deploying web application \""+appl+"\" "+
                                     "under <http://"+host+":"+port+path+";>");
                      try {
                          context=deploy(connection,logger,appl,host,path);
                      } catch (Exception e) {
                          logger.log(e);
                      }
                      if (context==null) {
                          String msg="Error deploying web application \""+appl+
                                     "\" under <http://"+host+":"+port+path+";>";
                          logger.log(msg);
                          packet.setType(Constants.TYPE_ERROR);
                          packet.writeString(msg);
                          connection.send(packet);
                      } else {
                          int k=connection.getConnector().applicationId(context);
                          packet.setType(Constants.TYPE_CONF_APPLIC);
                          packet.writeInteger(k);
                          packet.writeString(context.getDocBase());
                          connection.send(packet);
                          if (Constants.DEBUG)
                              logger.debug("Application \""+appl+"\" deployed "+
                                           "under <http://"+host+":"+port+path+
                                           "> with root="+context.getDocBase()+
                                           " ID="+k);
                      }
                      break;
                  }
  
                  case Constants.TYPE_CONF_DONE: {
                      return(true);
                  }
  
                  case Constants.TYPE_DISCONNECT: {
                      return(false);
                  }
  
                  default: {
                      String msg="Invalid packet with type "+packet.getType();
                      logger.log(msg);
                      packet.reset();
                      packet.setType(Constants.TYPE_FATAL);
                      packet.writeString(msg);
                      connection.send(packet);
                      return(false);
                  }
              }
          }        
      }
      
      /** Deploy a web application */
      private Context deploy(WarpConnection connection, WarpLogger logger,
                             String applName, String hostName, String applPath)
      throws IOException {
          synchronized (connection.getConnector()) {
  
          Container container=connection.getConnector().getContainer();
  
          Host host=(Host)container.findChild(hostName);
          if (host==null) {
              WarpHost whost=new WarpHost();
              whost.setName(hostName);
              whost.setParent(container);
              whost.setAppBase(connection.getConnector().getAppBase());
              whost.setDebug(connection.getConnector().getDebug());
              container.addChild(whost);
              host=whost;
              if (Constants.DEBUG)
                  logger.debug("Created new host "+host.getName());
          } else if (Constants.DEBUG) {
              logger.debug("Reusing instance of Host \""+host.getName()+"\"");
          }
  
          // TODO: Set up mapping mechanism for performance
          
          if (applPath.endsWith("/"))
              applPath=applPath.substring(0,applPath.length()-1);
  
          Context appl=(Context)host.findChild(applPath);
  
          if (appl==null) {
  
              if (Constants.DEBUG)
                  logger.debug("No application for \""+applPath+"\"");
  
              Deployer deployer=(Deployer)host;
              File file=new File(host.getAppBase()+File.separator+applName);
              if (!file.isAbsolute()) {
                  file=new File(System.getProperty("catalina.home"),
                                host.getAppBase()+File.separator+applName);
              }
  
              if (!file.exists()) {
                  logger.log("Cannot find \""+file.getPath()+"\" for appl. \""+
                             applName);
                  return(null);
              }
  
              String path=file.getCanonicalPath();
              URL url=new URL("file",null,path);
              if (path.toLowerCase().endsWith(".war"))
                  url=new URL("jar:"+url.toString()+"!/");
  
              if (Constants.DEBUG)
                  logger.debug("Application URL \""+url.toString()+"\"");
  
              deployer.install(applPath, url);
              StandardContext context=null;
              context=(StandardContext)deployer.findDeployedApp(applPath);
              context.setDebug(connection.getConnector().getDebug());
              return(context);
          } else {
              if (Constants.DEBUG)
                  logger.debug("Found application for \""+appl.getName()+"\"");
              return(appl);
          }
          }
      }
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpLogger.java
  
  Index: WarpLogger.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "Tomcat",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
   * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
   * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  package org.apache.catalina.connector.warp;
  
  import org.apache.catalina.Container;
  import org.apache.catalina.Logger;
  
  public class WarpLogger {
  
      /* ==================================================================== */
      /* Variables                                                            */
      /* ==================================================================== */
  
      /* -------------------------------------------------------------------- */
      /* Bean variables */
  
      /** The <code>Container</code> instance processing requests. */
      private Container container=null;
      /** The source of log messages for this logger. */
      private Object source=null;
  
      /* ==================================================================== */
      /* Constructor                                                          */
      /* ==================================================================== */
  
      /** Deny empty construction. */
      private WarpLogger() {
          super();
      }
  
      /**
       * Construct a new instance of a <code>WarpConnector</code>.
       */
      public WarpLogger(Object source) {
          super();
          this.source=source;
      }
  
      /* ==================================================================== */
      /* Bean methods                                                         */
      /* ==================================================================== */
  
      /**
       * Return the <code>Container</code> instance which will process all
       * requests received by this <code>Connector</code>.
       */
      public Container getContainer() {
          return(this.container);
      }
  
      /**
       * Set the <code>Container</code> instance which will process all requests
       * received by this <code>Connector</code>.
       *
       * @param container The new Container to use
       */
      public void setContainer(Container container) {
          this.container=container;
      }
  
      /* ==================================================================== */
      /* Logging and debugging methods                                        */
      /* ==================================================================== */
  
      /** Log to the container logger with the specified level or to stderr */
      private void log(String msg, Exception exc, int lev) {
          if (this.container==null) {
              dump(msg,exc);
              return;
          }
  
          Logger logg=this.container.getLogger();
          if (logg==null) {
              dump(msg,exc);
              return;
          }
  
          String cls="["+this.source.getClass().getName()+"] ";
          if (msg==null) msg=cls;
          else msg=cls.concat(msg);
  
          if (exc==null) logg.log(msg,lev);
          else logg.log(msg,exc,lev);
      }
  
      /** Invoked when we can't get a hold on the logger, dump to stderr */
      private void dump(String message, Exception exception) {
          String cls="["+this.source.getClass().getName()+"] ";
  
          if (message!=null) {
              System.err.print(cls);
              System.err.println(message);
          }
          if (exception!=null) {
              System.err.print(cls);
              exception.printStackTrace(System.err);
          }
      }
  
      /**
       * If Constants.DEBUG was set true at compilation time, dump a debug
       * message to Standard Error.
       *
       * @param message The message to dump.
       */
      protected void debug(String message) {
          if (Constants.DEBUG) this.log(message,null,Logger.DEBUG);
      }
  
      /**
       * If Constants.DEBUG was set true at compilation time, dump an exception
       * stack trace to Standard Error.
       *
       * @param exception The exception to dump.
       */
      protected void debug(Exception exception) {
          if (Constants.DEBUG) this.log(null,exception,Logger.DEBUG);
      }
  
      /**
       * If Constants.DEBUG was set true at compilation time, dump a debug
       * message and a related exception stack trace to Standard Error.
       *
       * @param exception The exception to dump.
       * @param message The message to dump.
       */
      protected void debug(String message, Exception exception) {
          if (Constants.DEBUG) this.log(message,exception,Logger.DEBUG);
      }
  
      /**
       * Log a message.
       *
       * @param message The message to log.
       */
      protected void log(String message) {
          this.log(message,null,Logger.ERROR);
      }
  
      /**
       * Log an exception.
       *
       * @param exception The exception to log.
       */
      protected void log(Exception exception) {
          this.log(null,exception,Logger.ERROR);
      }
  
      /**
       * Log an exception and related message.
       *
       * @param exception The exception to log.
       * @param message The message to log.
       */
      protected void log(String message, Exception exception) {
          this.log(message,exception,Logger.ERROR);
      }
  }
  
  
  

Reply via email to