You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2002/01/23 18:48:51 UTC

cvs commit: jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp Constants.java WarpCertificates.java WarpConfigurationHandler.java WarpConnection.java WarpConnector.java WarpEngine.java WarpHost.java WarpLogger.java WarpPacket.java WarpRequest.java WarpRequestHandler.java WarpResponse.java WarpSSLData.java

remm        02/01/23 09:48:50

  Modified:    webapp   .cvsignore Makefile.in
  Added:       webapp   build.properties.sample build.xml
               webapp/java/org/apache/catalina/connector/warp
                        Constants.java WarpCertificates.java
                        WarpConfigurationHandler.java WarpConnection.java
                        WarpConnector.java WarpEngine.java WarpHost.java
                        WarpLogger.java WarpPacket.java WarpRequest.java
                        WarpRequestHandler.java WarpResponse.java
                        WarpSSLData.java
  Removed:     webapp/java .cvsignore Constants.java.in Makefile.in
                        WarpCertificates.java WarpConfigurationHandler.java
                        WarpConnection.java WarpConnector.java
                        WarpEngine.java WarpHost.java WarpLogger.java
                        WarpPacket.java WarpRequest.java
                        WarpRequestHandler.java WarpResponse.java
                        WarpSSLData.java
  Log:
  - Make the build system of the webapp connector similar to the other j-t-c
    components, at least for the Java side of the connector.
  
  Revision  Changes    Path
  1.5       +1 -0      jakarta-tomcat-connectors/webapp/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/.cvsignore,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- .cvsignore	11 Aug 2001 02:26:14 -0000	1.4
  +++ .cvsignore	23 Jan 2002 17:48:50 -0000	1.5
  @@ -2,6 +2,7 @@
   Makedefs
   Makefile
   apr
  +build
   config.cache
   config.log
   config.status
  
  
  
  1.26      +1 -12     jakarta-tomcat-connectors/webapp/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/Makefile.in,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Makefile.in	22 Jan 2002 11:05:06 -0000	1.25
  +++ Makefile.in	23 Jan 2002 17:48:50 -0000	1.26
  @@ -56,7 +56,7 @@
   # ========================================================================= #
   
   # @author  Pier Fumagalli <ma...@betaversion.org>
  -# @version $Id: Makefile.in,v 1.25 2002/01/22 11:05:06 jfclere Exp $
  +# @version $Id: Makefile.in,v 1.26 2002/01/23 17:48:50 remm Exp $
   
   include @TGTDIR@/Makedefs
   
  @@ -95,12 +95,6 @@
   lib-clean:
   	@$(MAKE) template MFLG="$(MAKEFLAGS)" MDIR="lib" MTGT="clean"
   
  -java-build:
  -	@$(MAKE) template MFLG="$(MAKEFLAGS)" MDIR="java" MTGT="build"
  -
  -java-clean:
  -	@$(MAKE) template MFLG="$(MAKEFLAGS)" MDIR="java" MTGT="clean"
  -
   apache-1.3-build:
   	@$(MAKE) template MFLG="$(MAKEFLAGS)" MDIR="apache-1.3" MTGT="build"
   
  @@ -118,11 +112,6 @@
   	support/scandoc.pl -i support/template.pl -p docs/api-c/ */*.h
   apidocs-c-clean:
   	$(RM) -rf docs/api-c
  -apidocs-java-build:
  -	mkdir docs/api-java
  -	javadoc java/*.java -d docs/api-java
  -apidocs-java-clean:
  -	$(RM) -rf docs/api-java
   
   template:
   	@ { \
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  # -------------------------------------------------------------------
  # build.properties.sample
  #
  # This is an example "build.properties" file, used to customize 
  # building Jakarta Coyote for your local environment.  
  # Make any changes you need, and rename this file to 
  # "build.properties" 
  #
  # $Id: build.properties.sample,v 1.1 2002/01/23 17:48:50 remm Exp $
  # -------------------------------------------------------------------
  
  
  # -------------------------------------------------------------------
  # CONFIGURATION OPTIONS
  # -------------------------------------------------------------------
  
  # 
  
  
  # -------------------------------------------------------------------
  # EXTERNAL DEPENDENCIES 
  # -------------------------------------------------------------------
  
  # catalina.home -- Tomcat 4.x distribution directory
  catalina.home=../../jakarta-tomcat-4.0/build
  
  # tomcat-util.jar -- Tomcat util package
  tomcat-util.jar=../util/build/lib/tomcat-util.jar
  
  # junit.jar -- JUnit classes (http://junit.org)
  junit.jar=/java/junit/junit.jar
  
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="Webapp" default="compile" basedir=".">
  
  
  <!--
          "Coyote" connector framework for Jakarta Tomcat
          $Id: build.xml,v 1.1 2002/01/23 17:48:50 remm Exp $
  -->
  
  
  <!-- ========== Initialize Properties ===================================== -->
  
  
    <property file="build.properties"/>                <!-- Component local   -->
    <property file="../build.properties"/>             <!-- Commons local     -->
    <property file="${user.home}/build.properties"/>   <!-- User local        -->
  
  
  <!-- ========== External Dependencies ===================================== -->
  
  
    <!-- The directories corresponding to your necessary dependencies -->
    <property name="junit.home"              value="/usr/local/junit3.5"/>
  
  
  <!-- ========== Derived Values ============================================ -->
  
  
    <!-- The locations of necessary jar files -->
    <property name="tomcat-util.jar"  value="../util/build/lib/tomcat-util.jar"/>
    <property name="junit.jar"        value="${junit.home}/junit.jar"/>
  
  
  <!-- ========== Component Declarations ==================================== -->
  
  
    <!-- The name of this component -->
    <property name="component.name"          value="webapp"/>
  
    <!-- The title of this component -->
    <property name="component.title"         value="Webapp"/>
  
    <!-- The current version number of this component -->
    <property name="component.version"       value="1.0"/>
  
    <!-- The base directory for compilation targets -->
    <property name="build.home"              value="build"/>
  
    <!-- The base directory for component configuration files -->
    <property name="conf.home"               value="conf"/>
  
    <!-- The base directory for component sources -->
    <property name="source.home"             value="java"/>
  
    <!-- The base directory for unit test sources -->
    <property name="test.home"               value="test"/>
  
  <!-- ========== Compiler Defaults ========================================= -->
  
  
    <!-- Should Java compilations set the 'debug' compiler option? -->
    <property name="compile.debug"           value="true"/>
  
    <!-- Should Java compilations set the 'deprecation' compiler option? -->
    <property name="compile.deprecation"     value="false"/>
  
    <!-- Should Java compilations set the 'optimize' compiler option? -->
    <property name="compile.optimize"        value="true"/>
  
      <!-- default locations -->
      <property name="tomcat33.home" 
  	      location="../../jakarta-tomcat/build/tomcat" />
      <property name="catalina.home" 
  	      location="../../jakarta-tomcat-4.0/build" />
  
    <!-- Construct compile classpath -->
    <path id="compile.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${tomcat-util.jar}"/>
      <pathelement location="${catalina.home}/server/lib/catalina.jar"/>
      <pathelement location="${catalina.home}/common/lib/servlet.jar"/>
    </path>
  
  
  <!-- ========== Test Execution Defaults =================================== -->
  
  
    <!-- Construct unit test classpath -->
    <path id="test.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${build.home}/tests"/>
      <pathelement location="${tomcat-util.jar}"/>
      <pathelement location="${junit.jar}"/>
    </path>
  
    <!-- Should all tests fail if one does? -->
    <property name="test.failonerror"        value="true"/>
  
    <!-- The test runner to execute -->
    <property name="test.runner"             value="junit.textui.TestRunner"/>
    <property name="test.entry" value="org.apache.coyote.TestAll"/>
  
  
  <!-- ========== Detection and Reports ===================================== -->
  
  
      <target name="report-tc4" if="tomcat4.detect" >
  	<echo message="Tomcat4 detected "  />
      </target>
  
      <target name="report" depends="report-tc4" />
  
  
  <!-- ========== Executable Targets ======================================== -->
  
  
    <target name="init"
     description="Initialize and evaluate conditionals">
      <echo message="-------- ${component.title} ${component.version} --------"/>
      <filter  token="name"                  value="${component.name}"/>
      <filter  token="version"               value="${component.version}"/>
    </target>
  
  
    <target name="prepare" depends="init"
     description="Prepare build directory">
      <mkdir dir="${build.home}"/>
      <mkdir dir="${build.home}/classes"/>
      <mkdir dir="${build.home}/conf"/>
      <mkdir dir="${build.home}/docs"/>
      <mkdir dir="${build.home}/docs/api"/>
      <mkdir dir="${build.home}/lib"/>
      <mkdir dir="${build.home}/tests"/>
      <available property="tomcat4.detect" file="${catalina.home}/server/lib/catalina.jar" />
    </target>
  
  
    <target name="static" depends="prepare"
     description="Copy static files to build directory">
      <tstamp/>
      <!--
      <copy  todir="${build.home}/conf" filtering="on">
        <fileset dir="${conf.home}" includes="*.MF"/>
      </copy>
      -->
    </target>
  
  
    <target name="compile"
     depends="static,javadoc,report"
     description="Compile Webapp components">
      <javac  srcdir="${source.home}"
             destdir="${build.home}/classes"
               debug="${compile.debug}"
         deprecation="${compile.deprecation}"
            optimize="${compile.optimize}">
        <classpath refid="compile.classpath"/>
      </javac>
      <copy    todir="${build.home}/classes" filtering="on">
        <fileset dir="${source.home}" excludes="**/*.java"/>
      </copy>
      <jar    jarfile="${build.home}/lib/tomcat-${component.name}.jar"
              basedir="${build.home}/classes" />
    </target>
  
  
    <target name="compile.tests" depends="compile"
     description="Compile unit test cases">
      <javac  srcdir="${test.home}"
             destdir="${build.home}/tests"
               debug="${compile.debug}"
         deprecation="${compile.deprecation}"
            optimize="${compile.optimize}">
        <classpath refid="test.classpath"/>
      </javac>
      <copy    todir="${build.home}/tests" filtering="on">
        <fileset dir="${test.home}" excludes="**/*.java"/>
      </copy>
    </target>
  
  
    <target name="clean"
     description="Clean build and distribution directories">
      <delete    dir="${build.home}"/>
    </target>
  
  
    <target name="all" depends="clean,compile"
     description="Clean and compile all components"/>
  
  
    <target name="javadoc"
     description="Create component Javadoc documentation">
      <javadoc sourcepath="${source.home}"
                  destdir="${build.home}/docs/api"
             packagenames="org.apache.*"
                   author="true"
                  private="true"
                  version="true"
                 doctitle="&lt;h1&gt;${component.title}&lt;/h1&gt;"
              windowtitle="${component.title} (Version ${component.version})"
                   bottom="Copyright (c) 2001-2002 - Apache Software Foundation">
        <classpath refid="compile.classpath"/>
      </javadoc>
    </target>
  
  
  <!-- ========== Unit Test Targets ========================================= -->
  
  
    <target name="test"  depends="compile.tests" if="test.entry"
     description="Run all unit test cases">
        <!--
        <junit printsummary="yes" fork="on" haltonfailure="yes">
        	<formatter type="plain" usefile="false"/>
        	<test name="${test.entry}"/>
          <classpath refid="test.classpath"/>
        </junit>
        -->
  
        <java classname="${test.runner}" fork="yes"
         failonerror="${test.failonerror}">
          <jvmarg value="${java.protocol.handler.pkgs}"/>
          <arg value="${test.entry}"/>
          <classpath refid="test.classpath"/>
        </java>
    </target>
  
  
  </project>
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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=10;
  
      /**
       * 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_ENUM: The client requests to the server to enumerate all
       * web-applications available for a specified virtual host. In response
       * to this request, the server replies with a set of CONF_ENUM messages
       * terminated by a CONF_ENUM_DONE message.
       * <br>
       * Payload description:<br>
       * [string] The virtual host name.<br>
       * [ushort] The virtual host port.<br>
       */
      public static final int TYPE_CONF_ENUM=0x02;
  
      /**
       * CONF_ENUM_APPL: The server specifies the name of a web-application
       * available for deployment in response to a CONF_ENUMERATE message.
       * <br>
       * Payload description:<br>
       * [string] The web-application name.<br>
       */
      public static final int TYPE_CONF_ENUM_APPL=0x03;
  
      /**
       * CONF_ENUM_DONE: The server specifies all web-application names
       * available for deployment for the host specified in the CONF_ENUM
       * message have been transfered.
       * <br>
       * No payload:<br>
       */
      public static final int TYPE_CONF_ENUM_DONE=0x04;
  
      /**
       * 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=0x05;
  
      /**
       * 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=0x06;
  
      /**
       * CONF_MAP: The client requests to the server to enumerate all mappings
       * for a specified web-application. The server replies to this message
       * with a serie of MAP_ALLOW and MAP_DENY packets, terminated by a
       * MAP_DONE packet.
       * <br>
       * Payload description:<br>
       * [integer] The web application unique id for this server.<br>
       */
      public static final int TYPE_CONF_MAP=0x07;
  
      /**
       * CONF_MAP_ALLOW: The server replies to a CONF_MAP message with this
       * packet to indicate a mapping to a static page, or a resource that
       * can be served autonomously by the remote end (the web server).
       * <br>
       * Payload description:<br>
       * [string] An url-pattern as defined by the Servlet specification.
       */
      public static final int TYPE_CONF_MAP_ALLOW=0x08;
  
      /**
       * CONF_MAP_DENY: The server replies to a CONF_MAP message with this
       * packet to indicate a mapping to a resource that must be served by
       * the server (servlet container).
       * <br>
       * Payload description:<br>
       * [string] An url-pattern as defined by the Servlet specification.
       */
      public static final int TYPE_CONF_MAP_DENY=0x09;
  
      /**
       * CONF_MAP_DONE: The server replies to a CONF_MAP message with this
       * packet to indicate that all servlet mappings have been successfully
       * transfered to the other end
       * <br>
       * No payload:<br>
       */
      public static final int TYPE_CONF_MAP_DONE=0x0a;
  
      /**
       * CONF_DONE: Client issues this message when all configurations have been
       * processed.
       * <br>
       * No payload:<br>
       */
      public static final int TYPE_CONF_DONE=0x0e;
  
      /**
       * 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=0x0f;
  
      /**
       * REQ_INIT: The client requests to the WARP server that a request is
       * about to be processed.
       * <br>
       * Payload description:<br>
       * [integer] The web-application unique ID for this server.<br>
       * [string] The HTTP method used for this request.<br>
       * [string] The request URI.<br>
       * [string] The request query arguments.<br>
       * [string] The request protocol (HTTP/1.0, HTTP/1.1...).<br>
       */
      public static final int TYPE_REQ_INIT=0x10;
  
      /**
       * REQ_CONTENT: The mime content type and length of this request.
       * <br>
       * Payload description:<br>
       * [string] The MIME content type of this reques.<br>
       * [integer] The content length of this request.<br>
       */
      public static final int TYPE_REQ_CONTENT=0x11;
  
      /**
       * REQ_SCHEME: The scheme description of this request.
       * <br>
       * Payload description:<br>
       * [string] The scheme (part before :// in the URL) of this request.<br>
       */
      public static final int TYPE_REQ_SCHEME=0x12;
  
      /**
       * REQ_AUTH: Authentication information of the HTTP remote peer.
       * <br>
       * Payload description:<br>
       * [string] The remote-user name.<br>
       * [string] The authentication information.<br>
       */
      public static final int TYPE_REQ_AUTH=0x13;
  
      /**
       * REQ_HEADER: An HTTP request header.
       * <br>
       * Payload description:<br>
       * [string] The header name.<br>
       * [string] The header value.<br>
       */
      public static final int TYPE_REQ_HEADER=0x14;
  
      /**
       * REQ_SERVER: The HTTP server information.
       * <br>
       * Payload description:<br>
       * [string] The HTTP server host name.
       * [string] The HTTP server IP address.
       * [ushort] The port receiving the HTTP request.
       */
      public static final int TYPE_REQ_SERVER=0x15;
  
      /**
       * REQ_CLIENT: The HTTP client (remote peer) information.
       * <br>
       * Payload description:<br>
       * [string] The HTTP client host name.
       * [string] The HTTP client IP address.
       * [ushort] The remote port originating the HTTP request.
       */
      public static final int TYPE_REQ_CLIENT=0x16;
  
      /**
       * REQ_PROCEED: The client finished transmitting the request. The server
       * can now proceed and process the request.
       * <br>
       * No payload.<br>
       */
      public static final int TYPE_REQ_PROCEED=0x1f;
  
      /**
       * RES_STATUS: The server replies with the HTTP response status for the
       * request.
       * <br>
       * Payload description:<br>
       * [ushort] The HTTP status of the response.<br>
       * [string] The HTTP response message.<br>
       */
      public static final int TYPE_RES_STATUS=0x20;
  
      /**
       * RES_HEADER: An HTTP MIME response header to send to the client.
       * <br>
       * Payload description:<br>
       * [string] The MIME header name.<br>
       * [string] The MIME header value.<br>
       */
      public static final int TYPE_RES_HEADER=0x21;
  
      /**
       * RES_COMMIT: The server indicates that the first part of the response
       * (HTTP status line and MIME headers) are to be committed to the client
       * (remote peer).
       * <br>
       * No payload.<br>
       */
      public static final int TYPE_RES_COMMIT=0x2f;
  
      /**
       * RES_BODY: The HTTP response body.
       * <br>
       * Payload description:<br>
       * [raw] A chunk of the response body.<br>
       */
      public static final int TYPE_RES_BODY=0x30;
  
      /**
       * RES_DONE: The server finished transmitting the response.
       * <br>
       * No payload.<br>
       */
      public static final int TYPE_RES_DONE=0x3f;
  
      /**
       * CBK_READ: A request callback. The WARP server queries the WARP client
       * (HTTP server) to transmit a chunk of the request body.
       * <br>
       * Payload description:<br>
       * [ushort] The number of bytes the server needs to transmit.<br>
       */
      public static final int TYPE_CBK_READ=0x40;
  
      /**
       * CBK_DATA: As requested by the WARP server, the WARP client (HTTP
       * server) transmits a chunk of the request body.
       * <br>
       * Payload description:<br>
       * [raw] A chunk of the request body.<br>
       */
      public static final int TYPE_CBK_DATA=0x41;
  
      /**
       * CBK_DATA: The WARP client (HTTP server) informs the WARP server that
       * the request body has been fully transmitted.
       * <br>
       * No payload.<br>
       */
      public static final int TYPE_CBK_DONE=0x42;
  
      /**
       * ASK_SSL: The WARP server (Tomcat) asks the WARP client to
       * transfer the basic SSL information (cypher, keysize and session).
       * <br>
       * No payload.<br>
       */
      public static final int TYPE_ASK_SSL=0x43;
  
      /**
       * ASK_SSL_CLIENT: The WARP server (Tomcat) asks the WARP server to
       * transfer the client certificate.
       * (just the first element of the chain and the webserver should request
       * for it to the browser if possible).
       * <br>
       * No payload.<br>
       */
      public static final int TYPE_ASK_SSL_CLIENT=0x44;
  
      /**
       * REP_SSL_CERT: The client certificate (remote peer).
       * <br>
       * Payload description:<br>
       * [string] The client certificate. (PEM format).
       */
      public static final int TYPE_REP_SSL_CERT=0x52;
   
      /**
       * REP_SSL: SSL information between 
       * <br>
       * Payload description:<br>
       * [string] The cipher_suite.
       * [string] The ssl session. (That is not in the spec's).
       * [ushort] size of the algorithm (56-128).
       */
      public static final int TYPE_REP_SSL=0x53;
   
      /**
       * REP_SSL_NO: Request SSL information is not available.
       * <br>
       * No payload.<br>
       */
      public static final int TYPE_REP_SSL_NO=0x5F;
  }
  
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpCertificates.java
  
  Index: WarpCertificates.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.security.cert.X509Certificate;
  import java.security.cert.CertificateFactory;
   
  import java.io.ByteArrayInputStream;
   
  /*
   * Certificates handling.
   */
   
  public class WarpCertificates {
      X509Certificate jsseCerts[] = null;
      /**
       * Create the certificate using the String.
       */
      public WarpCertificates(String certString) {
          if (certString == null) return;
  
          byte[] certData = certString.getBytes();
          ByteArrayInputStream bais = new ByteArrayInputStream(certData);
   
          // Fill the first element.
          try {
              CertificateFactory cf =
                      CertificateFactory.getInstance("X.509");
              X509Certificate cert = (X509Certificate)
                      cf.generateCertificate(bais);
              jsseCerts =  new X509Certificate[1];
              jsseCerts[0] = cert;
          } catch(java.security.cert.CertificateException e) {
              // Certificate convertion failed.
              return;
          }
      }
      public X509Certificate [] getCertificates() {
          return jsseCerts;
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.Wrapper;
  import org.apache.catalina.core.StandardHost;
  import org.apache.catalina.core.StandardContext;
  import org.apache.catalina.deploy.FilterMap;
  import org.apache.catalina.deploy.SecurityConstraint;
  import org.apache.catalina.deploy.SecurityCollection;
  
  public class WarpConfigurationHandler {
  
      private static final String DEFAULT_SERVLET = 
          "org.apache.catalina.servlets.DefaultServlet";
  
      /* ==================================================================== */
      /* 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);
                          break;
                      }
                      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_MAP: {
                      int id=packet.readInteger();
                      Context context=connection.getConnector()
                                      .applicationContext(id);
  
                      if (context==null) {
                          String msg="Invalid application ID for mappings "+id;
                          logger.log(msg);
                          packet.reset();
                          packet.setType(Constants.TYPE_ERROR);
                          packet.writeString(msg);
                          connection.send(packet);
                          break;
                      }
  
                      String smap[]=context.findServletMappings();
                      if (smap!=null) {
                          for (int x=0; x<smap.length; x++) {
                              Container c=context.findChild(
                                  context.findServletMapping(smap[x]));
                              packet.reset();
                              packet.setType(Constants.TYPE_CONF_MAP_DENY);
                              packet.writeString(smap[x]);
  
                              if (c instanceof Wrapper) {
                                  String servlet=((Wrapper)c).getServletClass();
                                  if (DEFAULT_SERVLET.equals(servlet)) {
                                      packet.setType(
                                          Constants.TYPE_CONF_MAP_ALLOW);
                                      if (Constants.DEBUG)
                                          logger.debug("Servlet mapping \""+
                                                       smap[x]+"\" allowed");
                                  } else if (Constants.DEBUG) {
                                      logger.debug("Servlet mapping \""+smap[x]+
                                                   "\" denied");
                                  }
                              }
                              connection.send(packet);
                          }
                      }
  
                      FilterMap fmap[]=context.findFilterMaps();
                      if (fmap!=null) {
                          logger.log("Filter mappings ("+fmap.length+")");
                          for (int x=0; x<fmap.length; x++) {
                              String map=fmap[x].getURLPattern();
                              if (map!=null) {
                                  if (Constants.DEBUG)
                                      logger.debug("Filter mapping \""+map+
                                                   "\" denied");
                                  packet.reset();
                                  packet.setType(Constants.TYPE_CONF_MAP_DENY);
                                  packet.writeString(map);
                                  connection.send(packet);
                              }
                          }
                      }
  
                      SecurityConstraint scon[]=context.findConstraints();
                      if (scon!=null) {
                          for (int x=0; x<scon.length; x++) {
                              SecurityCollection col[]=scon[x].findCollections();
                              if (col!=null) {
                                  for (int y=0; y<col.length; y++) {
                                      String patt[]=col[y].findPatterns();
                                      if (patt!=null) {
                                          for (int q=0; q<patt.length; q++) {
                                              packet.reset();
                                              packet.setType(
                                                  Constants.TYPE_CONF_MAP_DENY);
                                              packet.writeString(patt[q]);
                                              connection.send(packet);
                                              if (Constants.DEBUG) {
                                                  logger.debug("Seurity "+
                                                      " mapping \""+patt[q]+
                                                      "\"");
                                              }
                                          }
                                      }
                                  }
                              }
                          }
                      }
                      packet.reset();
                      packet.setType(Constants.TYPE_CONF_MAP_DONE);
                      connection.send(packet);
                      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();
  
          // the hostName should be in lowewr case (setName makes a toLowerCase).
          Host host=(Host)container.findChild(hostName.toLowerCase());
          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(applName);
              if (!file.isAbsolute()) {
                  file=new File(host.getAppBase()+File.separator+applName);
                  if (!file.isAbsolute()) {
                 	    file=new File(System.getProperty("catalina.base"),
                                    host.getAppBase()+File.separator+applName);
                  }
              }
  
              if (!file.exists()) {
                  logger.log("Cannot find \""+file.getPath()+"\" for appl. \""+
                             applName+"\" host \""+host.getName()+"\"");
                  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-connectors/webapp/java/org/apache/catalina/connector/warp/WarpConnection.java
  
  Index: WarpConnection.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.Socket;
  
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleEvent;
  import org.apache.catalina.LifecycleListener;
  
  public class WarpConnection implements LifecycleListener, Runnable {
  
      /* ==================================================================== */
      /* Instance variables                                                   */
      /* ==================================================================== */
  
      /* -------------------------------------------------------------------- */
      /* Local variables */
  
      /** Our socket input stream. */
      private InputStream input=null;
      /** Our socket output stream. */
      private OutputStream output=null;
      /** The started flag. */
      private boolean started=false;
      /** The local thread. */
      private Thread thread=null;
      /** Our logger. */
      private WarpLogger logger=null;
  
      /* -------------------------------------------------------------------- */
      /* Bean variables */
  
      /** The socket this connection is working on. */
      private Socket socket=null;
      /** The connector instance. */
      private WarpConnector connector=null;
  
      /* ==================================================================== */
      /* Constructor                                                          */
      /* ==================================================================== */
  
      /**
       * Construct a new instance of a <code>WarpConnection</code>.
       */
      public WarpConnection() {
          super();
          this.logger=new WarpLogger(this);
      }
  
      /* ==================================================================== */
      /* Bean methods                                                         */
      /* ==================================================================== */
  
      /**
       * Set the socket this connection is working on.
       */
      public void setSocket(Socket socket) {
          this.socket=socket;
      }
  
      /**
       * Return the socket this connection is working on.
       */
      public Socket getSocket() {
          return(this.socket);
      }
  
      /**
       * Set the <code>WarpConnector</code> associated with this connection.
       */
      public void setConnector(WarpConnector connector) {
          this.connector=connector;
          this.logger.setContainer(connector.getContainer());
      }
  
      /**
       * Return the <code>WarpConnector</code> associated with this connection.
       */
      public WarpConnector getConnector() {
          return(this.connector);
      }
  
      /* ==================================================================== */
      /* Lifecycle methods                                                    */
      /* ==================================================================== */
  
      /**
       * Get notified of events in the connector.
       */
      public void lifecycleEvent(LifecycleEvent event) {
          if (Lifecycle.STOP_EVENT.equals(event.getType())) this.stop();
      }
  
      /**
       * Start working on this connection.
       */
      public void start() {
          synchronized(this) {
              this.started=true;
              this.thread=new Thread(this);
              this.thread.start();
          }
      }
  
      /**
       * Stop all we're doing on the connection.
       */
      public void stop() {
          synchronized(this) {
              try {
                  this.started=false;
                  this.socket.close();
                  this.getConnector().removeLifecycleListener(this);
              } catch (IOException e) {
                  logger.log("Cannot close socket",e);
              }
          }
      }
  
      /**
       * Process data from the socket.
       */
      public void run() {
          WarpPacket packet=new WarpPacket();
  
          if (Constants.DEBUG) logger.debug("Connection starting");
  
          try {
              this.input=this.socket.getInputStream();
              this.output=this.socket.getOutputStream();
              if (!new WarpConfigurationHandler().handle(this,packet)) {
                  logger.log("Configuration handler returned false");
                  this.stop();
              }
              WarpRequestHandler requestHandler=new WarpRequestHandler();
              while (requestHandler.handle(this,packet));
          } catch (IOException e) {
              logger.log("Exception on socket",e);
          } finally {
              this.stop();
          }
  
          if (Constants.DEBUG) logger.debug("Connection terminated");
      }
  
      /* ==================================================================== */
      /* Public methods                                                       */
      /* ==================================================================== */
  
      /**
       * Send a WARP packet over this connection.
       */
      public void send(WarpPacket packet)
      throws IOException {
          if (Constants.DEBUG) {
              String typ=Integer.toHexString(packet.getType());
              logger.debug(">> TYPE="+typ+" LENGTH="+packet.size);
              //logger.debug(">> "+packet.dump());
          }
  
          this.output.write(packet.getType()&0x0ff);
          this.output.write((packet.size>>8)&0x0ff);
          this.output.write((packet.size>>0)&0x0ff);
          this.output.write(packet.buffer,0,packet.size);
          this.output.flush();
          packet.reset();
      }
  
      /**
       * Receive a WARP packet over this connection.
       */
      public void recv(WarpPacket packet)
      throws IOException {
          int t=this.input.read();
          int l1=this.input.read();
          int l2=this.input.read();
  
          if ((t|l1|l2)==-1)
              throw new IOException("Premature packet header end");
  
          packet.reset();
          packet.setType(t&0x0ff);
          packet.size=(( l1 & 0x0ff ) << 8) | ( l2 & 0x0ff );
  
          if (packet.size>0) {
              int off=0;
              int ret=0;
              while (true) {
                  ret=this.input.read(packet.buffer,off,packet.size-off);
                  if (ret==-1)
                      throw new IOException("Premature packet payload end");
                  off+=ret;
                  if(off==packet.size) break;
              }
          }
  
          if (Constants.DEBUG) {
              String typ=Integer.toHexString(packet.getType());
              logger.debug("<< TYPE="+typ+" LENGTH="+packet.size);
              // logger.debug("<< "+packet.dump());
          }
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpConnector.java
  
  Index: WarpConnector.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.IOException;
  import java.net.InetAddress;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.util.Random;
  import java.util.Vector;
  
  import org.apache.catalina.Connector;
  import org.apache.catalina.Container;
  import org.apache.catalina.Context;
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.LifecycleListener;
  import org.apache.catalina.Logger;
  import org.apache.catalina.Request;
  import org.apache.catalina.Response;
  import org.apache.catalina.Service;
  import org.apache.catalina.net.DefaultServerSocketFactory;
  import org.apache.catalina.net.ServerSocketFactory;
  import org.apache.catalina.util.LifecycleSupport;
  
  public class WarpConnector implements Connector, Lifecycle, Runnable {
  
      /* ==================================================================== */
      /* Instance variables                                                   */
      /* ==================================================================== */
  
      /* -------------------------------------------------------------------- */
      /* Local variables */
  
      /** The running thread accepting connections */
      private Thread thread=null;
      /** The server socket. */
      private ServerSocket server=null;
      /** Our <code>WarpLogger</code>. */
      private WarpLogger logger=null;
      /** Our list of deployed web applications. */
      private Vector applications=new Vector();
      /** The unique ID of this connector instance. */
      protected int uniqueId=-1;
  
      /* -------------------------------------------------------------------- */
      /* Bean variables */
  
      /** The <code>Container</code> instance processing requests. */
      private Container container=null;
      /** The "enable DNS lookups" flag. */
      private boolean enableLookups=false;
      /** The <code>ServerSocketFactory</code> used by this connector. */
      private ServerSocketFactory factory=null;
      /** The redirect port value for SSL requests. */
      private int redirectPort=443;
      /** The request scheme value. */
      private String scheme="warp";
      /** The secure flag of this <code>Connector</code>. */
      private boolean secure=false;
      /** The <code>Service</code> we are associated with (if any). */
      private Service service=null;
      /** Descriptive information of this <code>Connector</code>. */
      private String info=null;
      /** The address we need to bind to. */
      private String address=null;
      /** The port we need to bind to. */
      private int port=8008;
      /** The server socket backlog length. */
      private int acceptCount=10;
      /** The server appBase for hosts created via WARP. */
      private String appBase="webapps";
      /** The debug level. */
      private int debug=0;
  
      /* -------------------------------------------------------------------- */
      /* Lifecycle variables */
  
      /** The lifecycle event support for this component. */
      private LifecycleSupport lifecycle=new LifecycleSupport(this);
      /** The "initialized" flag. */
      private boolean initialized=false;
      /** The "started" flag. */
      private boolean started=false;
  
      /* ==================================================================== */
      /* Constructor                                                          */
      /* ==================================================================== */
  
      /**
       * Construct a new instance of a <code>WarpConnector</code>.
       */
      public WarpConnector() {
          super();
          this.logger=new WarpLogger(this);
          this.uniqueId=new Random().nextInt();
          if (Constants.DEBUG)
              logger.debug("Instance created (ID="+this.uniqueId+")");
      }
  
      /* ==================================================================== */
      /* 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;
          this.logger.setContainer(container);
  
          if (Constants.DEBUG) {
              if (container==null) logger.debug("Setting null container");
              else logger.debug("Setting container "+container.getClass());
          }
      }
  
      /**
       * Return the "enable DNS lookups" flag.
       */
      public boolean getEnableLookups() {
          return(this.enableLookups);
      }
  
      /**
       * Set the "enable DNS lookups" flag.
       *
       * @param enableLookups The new "enable DNS lookups" flag value
       */
      public void setEnableLookups(boolean enableLookups) {
          this.enableLookups=enableLookups;
  
          if (Constants.DEBUG) logger.debug("Setting lookup to "+enableLookups);
      }
  
      /**
       * Return the <code>ServerSocketFactory</code> used by this
       * <code>Connector</code> to generate <code>ServerSocket</code> instances.
       */
      public ServerSocketFactory getFactory() {
          if (this.factory==null) {
              synchronized(this) {
                  if (Constants.DEBUG) logger.debug("Creating factory");
                  this.factory=new DefaultServerSocketFactory();
              }
          }
          return(this.factory);
      }
  
      /**
       * Set the <code>ServerSocketFactory</code> used by this
       * <code>Connector</code> to generate <code>ServerSocket</code> instances.
       *
       * @param factory The new server socket factory
       */
      public void setFactory(ServerSocketFactory factory) {
          if (factory==null) throw new NullPointerException();
          this.factory=factory;
  
          if (Constants.DEBUG)
              logger.debug("Setting factory "+factory.getClass().getName());
      }
  
      /**
       * Return the port number to which a request should be redirected if
       * it comes in on a non-SSL port and is subject to a security constraint
       * with a transport guarantee that requires SSL.
       */
      public int getRedirectPort() {
          return(this.redirectPort);
      }
  
      /**
       * Set the redirect port number.
       *
       * @param redirectPort The redirect port number (non-SSL to SSL)
       */
      public void setRedirectPort(int redirectPort) {
          if ((redirectPort<1) || (redirectPort>65535))
              throw new IllegalArgumentException("Invalid port "+redirectPort);
          this.redirectPort=redirectPort;
  
          if (Constants.DEBUG)
              logger.debug("Setting redirection port to "+redirectPort);
      }
  
      /**
       * Return the scheme that will be assigned to requests received
       * through this connector.  Default value is "warp".
       */
      public String getScheme() {
          return(this.scheme);
      }
  
      /**
       * Set the scheme that will be assigned to requests received through
       * this connector.
       *
       * @param scheme The new scheme
       */
      public void setScheme(String scheme) {
          if (scheme==null) throw new NullPointerException();
          this.scheme=scheme;
  
          if (Constants.DEBUG) logger.debug("Setting scheme to "+scheme);
      }
  
      /**
       * Return the secure connection flag that will be assigned to requests
       * received through this connector.  Default value is "false".
       */
      public boolean getSecure() {
          return(this.secure);
      }
  
      /**
       * Set the secure connection flag that will be assigned to requests
       * received through this connector.
       *
       * @param secure The new secure connection flag
       */
      public void setSecure(boolean secure) {
          this.secure=secure;
  
          if (Constants.DEBUG) logger.debug("Setting secure to "+secure);
      }
  
      /**
       * Return the <code>Service</code> with which we are associated (if any).
       */
      public Service getService() {
  
          return (this.service);
  
      }
  
  
      /**
       * Set the <code>Service</code> with which we are associated (if any).
       *
       * @param service The service that owns this Engine
       */
      public void setService(Service service) {
  
          this.service = service;
  
      }
  
  
      /**
       * Return descriptive information about this <code>Connector</code>.
       */
      public String getInfo() {
          if (this.info==null) {
              synchronized(this) {
                  this.info=this.getClass().getName()+"/"+
                            Constants.VERS_MINOR+Constants.VERS_MAJOR;
              }
          }
          return(this.info);
      }
  
      /**
       * Set descriptive information about this <code>Connector</code>.
       */
      public void setInfo(String info) {
          if (info==null) throw new NullPointerException();
          this.info=info;
  
          if (Constants.DEBUG) logger.debug("Setting info to "+info);
      }
  
      /**
       * Return the IP address to which this <code>Connector</code> will bind to.
       */
      public String getAddress() {
          return(this.address);
      }
  
      /**
       * Set the IP address to which this <code>Connector</code> will bind to.
       *
       * @param address The bind IP address
       */
      public void setAddress(String address) {
          this.address=address;
  
          if (Constants.DEBUG) logger.debug("Setting address to "+address);
      }
  
      /**
       * Return the port to which this <code>Connector</code> will bind to.
       */
      public int getPort() {
          return(this.port);
      }
  
      /**
       * Set the port to which this <code>Connector</code> will bind to.
       * 
       * @param port The bind port
       */
      public void setPort(int port) {
          this.port=port;
      }
  
      /**
       * Set the IP address to which this <code>Connector</code> will bind to.
       *
       * @param address The bind IP address
       */
      public void setAddress(int port) {
          if ((port<1) || (port>65535))
              throw new IllegalArgumentException("Invalid port "+port);
          this.port=port;
  
          if (Constants.DEBUG) logger.debug("Setting port to "+port);
      }
  
      /**
       * Return the accept count for this Connector.
       */
      public int getAcceptCount() {
          return (this.acceptCount);
      }
  
  
      /**
       * Set the accept count for this Connector.
       *
       * @param count The new accept count
       */
      public void setAcceptCount(int count) {
          this.acceptCount = count;
  
          if (Constants.DEBUG) logger.debug("Setting acceptCount to "+count);
      }
  
      /**
       * Get the applications base directory for hosts created via WARP.
       */
      public String getAppBase() {
          return (this.appBase);
      }
  
  
      /**
       * Set the applications base directory for hosts created via WARP.
       *
       * @param appBase The appbase property.
       */
      public void setAppBase(String appBase) {
          this.appBase = appBase;
  
          if (Constants.DEBUG) logger.debug("Setting appBase to "+appBase);
      }
  
      /**
       * Return the debug level.
       */
      public int getDebug() {
          return(this.debug);
      }
  
      /**
       * Set the debug level.
       */
      public void setDebug(int debug) {
          this.debug=debug;
      }
  
      /* ==================================================================== */
      /* Lifecycle methods                                                    */
      /* ==================================================================== */
  
      /**
       * Add a <code>LifecycleEvent</code> listener to this
       * <code>Connector</code>.
       *
       * @param listener The listener to add
       */
      public void addLifecycleListener(LifecycleListener listener) {
          lifecycle.addLifecycleListener(listener);
      }
  
      /**
       * Get the lifecycle listeners associated with this lifecycle. If this 
       * Lifecycle has no listeners registered, a zero-length array is returned.
       */
      public LifecycleListener[] findLifecycleListeners() {
          return null; // FIXME: lifecycle.findLifecycleListeners();
      }
  
      /**
       * Remove a <code>LifecycleEvent</code> listener from this
       * <code>Connector</code>.
       *
       * @param listener The listener to remove
       */
      public void removeLifecycleListener(LifecycleListener listener) {
          lifecycle.removeLifecycleListener(listener);
      }
  
      /**
       * Initialize this connector (create ServerSocket here!)
       */
      public void initialize()
      throws LifecycleException {
          if (initialized)
              throw new LifecycleException("Already initialized");
          this.initialized=true;
  
          // Get a hold on a server socket
          try {
              ServerSocketFactory fact=this.getFactory();
              int port=this.getPort();
              int accc=this.getAcceptCount();
  
              if (this.getAddress()==null) {
                  this.server=fact.createSocket(port,accc);
              } else {
                  InetAddress addr=InetAddress.getByName(this.getAddress());
                  this.server=fact.createSocket(port,accc,addr);
              }
          } catch (Exception e) {
              throw new LifecycleException("Error creating server socket ("+
                  e.getClass().getName()+")",e);
          }
      }
  
      /**
       * Start accepting connections by this <code>Connector</code>.
       */
      public void start() throws LifecycleException {
          if (!initialized) this.initialize();
          if (started) throw new LifecycleException("Already started");
  
          // Can't get a hold of a server socket
          if (this.server==null)
              throw new LifecycleException("Server socket not created");
  
          lifecycle.fireLifecycleEvent(START_EVENT, null);
  
          this.started = true;
  
          this.thread=new Thread(this);
          this.thread.setDaemon(true);
          this.thread.start();
      }
  
      /**
       * Stop accepting connections by this <code>Connector</code>.
       */
      public void stop() throws LifecycleException {
          if (!started) throw new LifecycleException("Not started");
  
          lifecycle.fireLifecycleEvent(STOP_EVENT, null);
  
          this.started = false;
  
          if (this.server!=null) try {
              this.server.close();
          } catch (IOException e) {
              logger.log("Cannot close ServerSocket",e);
          }
      }
  
      /**
       * Check whether this service was started or not.
       */
      public boolean isStarted() {
          return(this.started);
      }
  
      /* ==================================================================== */
      /* Public methods                                                       */
      /* ==================================================================== */
  
      /**
       * Return the application ID for a given <code>Context</code>.
       */
      protected int applicationId(Context context) {
          int id=this.applications.indexOf(context);
          if (id==-1) {
              this.applications.add(context);
              id=this.applications.indexOf(context);
          }
          return(id);
      }
  
      /**
       * Return the application for a given ID.
       */
      protected Context applicationContext(int id) {
          try {
              return((Context)this.applications.elementAt(id));
          } catch (ArrayIndexOutOfBoundsException e) {
              return(null);
          }
      }
  
      /**
       * Create (or allocate) and return a Request object suitable for
       * specifying the contents of a Request to the responsible Container.
       */
      public Request createRequest() {
          return(null);
      }
  
      /**
       * Create (or allocate) and return a Response object suitable for
       * receiving the contents of a Response from the responsible Container.
       */
      public Response createResponse() {
          return(null);
      }
  
      /**
       * Start accepting WARP requests from the network.
       */
      public void run() {
          // Start accepting connections
          try {
              while (this.isStarted()) {
                  Socket sock=this.server.accept();
                  InetAddress raddr=sock.getInetAddress();
                  InetAddress laddr=sock.getLocalAddress();
                  int rport=sock.getPort();
                  int lport=sock.getLocalPort();
                  logger.log("Connection from "+raddr+":"+rport+" to "+laddr+
                             ":"+lport);
                  WarpConnection conn=new WarpConnection();
                  conn.setConnector(this);
                  conn.setSocket(sock);
                  this.addLifecycleListener(conn);
                  conn.start();
              }
          } catch (IOException e) {
              logger.log("Error accepting requests",e);
          }
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpEngine.java
  
  Index: WarpEngine.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.IOException;
  import javax.servlet.ServletException;
  
  import org.apache.catalina.Container;
  import org.apache.catalina.Host;
  import org.apache.catalina.Request;
  import org.apache.catalina.Response;
  import org.apache.catalina.core.StandardEngine;
  
  public class WarpEngine extends StandardEngine {
      public Container map(Request request, boolean update) {
          this.log("Mapping request");
          if (request instanceof WarpRequest) {
              WarpRequest wreq=(WarpRequest)request;
              Host host=wreq.getHost();
              if (update) {
                  request.setServerName(host.getName());
              }
              return(host);
          } else return(super.map(request,update));
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpHost.java
  
  Index: WarpHost.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.IOException;
  import javax.servlet.ServletException;
  
  import org.apache.catalina.Container;
  import org.apache.catalina.Context;
  import org.apache.catalina.Request;
  import org.apache.catalina.Response;
  import org.apache.catalina.core.StandardContext;
  import org.apache.catalina.core.StandardHost;
  
  public class WarpHost extends StandardHost {
      public Container map(Request request, boolean update) {
          Context context=null;
          this.log("Mapping request for Host");
          if (request instanceof WarpRequest)
              context=((WarpRequest)request).getContext();
          else
              context=(Context)super.map(request,update);
  
          return(context);
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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) {
              if (Constants.DEBUG) dump(msg,exc);
              return;
          }
  
          Logger logg=this.container.getLogger();
          if (logg==null) {
              if (Constants.DEBUG) 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);
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpPacket.java
  
  Index: WarpPacket.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.UnsupportedEncodingException;
  
  public class WarpPacket {
  
      /** This packet's data buffer */
      protected byte buffer[]=null;
      /** Number of bytes stored in the buffer */
      protected int size=0;
  
      /* Pointer to the last byte read in the buffer */
      protected int pointer=0;
      /* Type of this packet */
      private int type=-1;
      /* Maximum value for a 16 bit unsigned value (0x0ffff +1) */
      private static final int MAX_LENGTH=65535;
  
      /**
       * Construct a new WarpPacket instance.
       */
      public WarpPacket() {
          super();
          this.buffer=new byte[MAX_LENGTH];
          this.reset();
      }
  
      /**
       * Reset this packet.
       */
      public void reset() {
          this.pointer=0;
          this.size=0;
          this.type=Constants.TYPE_INVALID;
      }
  
      /**
       * Set this packet type.
       *
       * @param type The type of this packet.
       */
      public void setType(int type) {
          this.type=type;
      }
  
      /**
       * Return the type of this packet.
       *
       * @return The type of this packet.
       */
      public int getType() {
          return(this.type);
      }
  
      /**
       * Write an unsigned short value (16 bit) in the packet buffer.
       *
       * @param value The unsigned short value to write.
       * @exception IllegalArgumentException If the value is negative or greater
       *                than 65535.
       * @exception ArrayIndexOutOfBoundsException If the packet buffer cannot
       *                contain the new value.
       */
      public void writeUnsignedShort(int value) {
          if (value<0)
              throw new IllegalArgumentException("Negative unsigned short");
          if (value>65535)
              throw new IllegalArgumentException("Unsigned short is too big");
  
          if ((this.size+2)>=MAX_LENGTH)
              throw new ArrayIndexOutOfBoundsException("Too much data");
  
          this.buffer[this.size++]=(byte) ((value>>8)&0x0ff);
          this.buffer[this.size++]=(byte) ((value>>0)&0x0ff);
      }
  
      /**
       * Write a signed integer value (32 bit) in the packet buffer.
       *
       * @param value The signed integer value to write.
       * @exception ArrayIndexOutOfBoundsException If the packet buffer cannot
       *                contain the new value.
       */
      public void writeInteger(int value) {
          if ((this.size+4)>=MAX_LENGTH)
              throw new ArrayIndexOutOfBoundsException("Too much data");
  
          this.buffer[this.size++]=(byte) ((value>>24)&0x0ff);
          this.buffer[this.size++]=(byte) ((value>>16)&0x0ff);
          this.buffer[this.size++]=(byte) ((value>>8)&0x0ff);
          this.buffer[this.size++]=(byte) ((value>>0)&0x0ff);
      }
  
      /**
       * Write a string into the packet buffer.
       *
       * @param string The string to write into the packet buffer.
       * @exception ArrayIndexOutOfBoundsException If the packet buffer cannot
       *                contain the new value.
       * @exception RuntimeException If the platform doesn't support UTF-8
       *                encoding.
       */
      public void writeString(String string) {
          try {
              if (string==null) string="";
              byte temp[]=string.getBytes("UTF-8");
              if ((this.size+temp.length+2)>MAX_LENGTH)
                  throw new ArrayIndexOutOfBoundsException("Too much data");
  
              this.writeUnsignedShort(temp.length);
              System.arraycopy(temp,0,this.buffer,this.size,temp.length);
              this.size+=temp.length;
          } catch (UnsupportedEncodingException s) {
              throw new RuntimeException("Unsupported encoding UTF-8");
          }
      }
  
      /**
       * Read an unsigned short value (16 bit) from the packet buffer.
       *
       * @return The unsigned short value as an integer.
       * @exception ArrayIndexOutOfBoundsException If no data is left in the
       *                packet buffer to be read.
       */
      public int readUnsignedShort() {
          if ((this.pointer+2)>this.size)
              throw new ArrayIndexOutOfBoundsException("No data available");
  
          int k=(this.buffer[this.pointer++])&0xff;
          k=(k<<8)+((this.buffer[this.pointer++])&0xff);
  
          return(k);
      }
  
      /**
       * Read a signed integer value (32 bit) from the packet buffer.
       *
       * @return The signed integer value.
       * @exception ArrayIndexOutOfBoundsException If no data is left in the
       *                packet buffer to be read.
       */
      public int readInteger() {
          if ((this.pointer+4)>this.size)
              throw new ArrayIndexOutOfBoundsException("No data available");
  
          int k=(this.buffer[this.pointer++])&0xff;
          k=(k<<8)+((this.buffer[this.pointer++])&0xff);
          k=(k<<8)+((this.buffer[this.pointer++])&0xff);
          k=(k<<8)+((this.buffer[this.pointer++])&0xff);
  
          return(k);
      }
  
      /**
       * Read a string from the packet buffer.
       *
       * @return The string red from the packet buffer.
       * @exception ArrayIndexOutOfBoundsException If no data is left in the
       *                packet buffer to be read.
       */
      public String readString() {
          int length=this.readUnsignedShort();
          try {
              String ret=new String(this.buffer,this.pointer,length,"UTF-8");
              this.pointer+=length;
              return(ret);
          } catch (UnsupportedEncodingException s) {
              throw new RuntimeException("Unsupported encoding UTF-8");
          }
      }
  
      public String dump() {
          StringBuffer buf=new StringBuffer("DATA=");
          for (int x=0; x<this.size; x++) {
              if ((this.buffer[x]>32)&&(this.buffer[x]<127)) {
                  buf.append((char)this.buffer[x]);
              } else {
                  buf.append("0x");
                  String digit=Integer.toHexString((int)this.buffer[x]);
                  if (digit.length()<2) buf.append('0');
                  if (digit.length()>2) digit=digit.substring(digit.length()-2);
                  buf.append(digit);
              }
              buf.append(" ");
          }
          return(buf.toString());
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpRequest.java
  
  Index: WarpRequest.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.*;
  
  import org.apache.catalina.Context;
  import org.apache.catalina.Host;
  import org.apache.catalina.connector.HttpRequestBase;
  
  public class WarpRequest extends HttpRequestBase {
      /** The local stream */
      private Stream localstream;
  
      /** The connection to which we are associated */
      private WarpConnection connection;
  
      private Host host=null;
  
      public WarpRequest() {
          super();
          this.localstream=new Stream(this);
          this.setStream(this.localstream);
      }
  
      /** Process the SSL attributes */
      public Object getAttribute(String name) {
  
          /* Use cached values */
          Object object = super.getAttribute(name);
  	if (object != null)
              return object;
  
  	/* Fill the cache and return value if possible */
          if (!localstream.request.isSecure()) return null;
  
          /* Client Certificate */
          if (name.equals("javax.servlet.request.X509Certificate")) {
              WarpCertificates cert = null;
              try {
                  cert = new WarpCertificates(localstream.getX509Certificates());
              } catch (IOException e) {
                  return null;
              }
              super.setAttribute("javax.servlet.request.X509Certificate",
                  cert.getCertificates());
          }
  
          /* other ssl parameters */
          if (name.equals("javax.servlet.request.cipher_suite") ||
              name.equals("javax.servlet.request.key_size") ||
              name.equals("javax.servlet.request.ssl_session")) {
              WarpSSLData ssldata = null;
              try {
                  ssldata = localstream.getSSL();
              } catch (IOException e) {
                  return null;
              }
              if (ssldata == null) return null;
  
              super.setAttribute("javax.servlet.request.cipher_suite",
                  ssldata.ciph);
              if (ssldata.size!=0)
                  super.setAttribute("javax.servlet.request.key_size",
                      new Integer (ssldata.size));
              super.setAttribute("javax.servlet.request.ssl_session",
                  ssldata.sess);
          }
          return(super.getAttribute(name));
      }
  
      public void setHost(Host host) {
          this.host=host;
      }
  
      public Host getHost() {
          return(this.host);
      }
  
      /**
       * Recycle this <code>WarpResponse</code> instance.
       */
      public void recycle() {
          // Recycle our parent
          super.recycle();
          // Recycle the stream
          this.localstream.recycle();
          // Tell the parent that a stream is already in use.
          this.setStream(localstream);
      }
  
      /**
       * Associate this <code>WarpResponse</code> instance with a specific
       * <code>WarpConnection</code> instance.
       */
      public void setConnection(WarpConnection connection) {
          this.connection=connection;
      }
  
      /**
       * Return the <code>WarpConnection</code> associated this instance of
       * <code>WarpResponse</code>.
       */
      public WarpConnection getConnection() {
          return(this.connection);
      }
  
      protected class Stream extends InputStream {
  
          /** The response associated with this stream instance. */
          private WarpRequest request=null;
          /** The packet used by this stream instance. */
          private WarpPacket packet=null;
          /** Wether <code>close()</code> was called or not. */
          private boolean closed=false;
  
          protected Stream(WarpRequest request) {
              super();
              this.request=request;
              this.packet=new WarpPacket();
              this.packet.setType(Constants.TYPE_CBK_DATA);
          }
  
          
          public int read()
          throws IOException {
              if (closed) throw new IOException("Stream closed");
  
              if (packet.getType()==Constants.TYPE_CBK_DONE) return(-1);
  
              if (packet.getType()!=Constants.TYPE_CBK_DATA)
                  throw new IOException("Invalid WARP packet type for body");
  
              if (this.packet.pointer<this.packet.size)
                  return(((int)this.packet.buffer[this.packet.pointer++])&0x0ff);
  
              this.packet.reset();
              this.packet.setType(Constants.TYPE_CBK_READ);
              this.packet.writeUnsignedShort(65535);
              this.request.getConnection().send(packet);
              packet.reset();
  
              this.request.getConnection().recv(packet);
              return(this.read());
          }
  
          public String getX509Certificates()
          throws IOException {
              if (closed) throw new IOException("Stream closed");
              this.packet.reset();
              this.packet.setType(Constants.TYPE_ASK_SSL_CLIENT);
              this.request.getConnection().send(packet);
              packet.reset();
  
              this.request.getConnection().recv(packet);
              if (closed) throw new IOException("Stream closed");
              if (packet.getType()==Constants.TYPE_REP_SSL_NO) return(null);
              if (packet.getType()!=Constants.TYPE_REP_SSL_CERT)
                 throw new IOException("Invalid WARP packet type for CC");
              return(this.packet.readString());
          }
  
          /** Read the data from the SSL environment. */
          public WarpSSLData getSSL()
          throws IOException {
            
              if (closed) throw new IOException("Stream closed");
              this.packet.reset();
              this.packet.setType(Constants.TYPE_ASK_SSL);
              this.request.getConnection().send(packet);
              packet.reset();
  
              this.request.getConnection().recv(packet);
              if (closed) throw new IOException("Stream closed");
              if (packet.getType()==Constants.TYPE_REP_SSL_NO) return(null);
              if (packet.getType()!=Constants.TYPE_REP_SSL)
                 throw new IOException("Invalid WARP packet type for SSL data");
              WarpSSLData ssldata  = new WarpSSLData();
              ssldata.ciph = this.packet.readString();
              ssldata.sess = this.packet.readString();
              ssldata.size = this.packet.readInteger();
              return(ssldata);
          }
  
  
          
          public void close()
          throws IOException {
              if (closed) throw new IOException("Stream closed");
              this.packet.reset();
              this.packet.setType(Constants.TYPE_CBK_DONE);
              this.closed=true;
          }
  
          public void recycle() {
              this.packet.reset();
              this.packet.setType(Constants.TYPE_CBK_DATA);
              this.closed=false;
          }
  
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpRequestHandler.java
  
  Index: WarpRequestHandler.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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 java.util.*;
  import java.util.Locale;
  import java.util.TreeMap;
  
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  
  import org.apache.catalina.Container;
  import org.apache.catalina.Context;
  import org.apache.catalina.Deployer;
  import org.apache.catalina.Globals;
  import org.apache.catalina.Host;
  import org.apache.catalina.core.StandardHost;
  import org.apache.catalina.util.RequestUtil;
  import org.apache.catalina.util.StringParser;
  
  import java.security.Principal;
  
  public class WarpRequestHandler {
  
      private StringParser parser = new StringParser();
      private static final String match=";"+Globals.SESSION_PARAMETER_NAME+"=";
  
      /* ==================================================================== */
      /* Constructor                                                          */
      /* ==================================================================== */
  
      public WarpRequestHandler() {
          super();
      }
  
      public boolean handle(WarpConnection connection, WarpPacket packet)
      throws IOException {
          WarpLogger logger=new WarpLogger(this);
          WarpConnector connector=connection.getConnector();
          logger.setContainer(connector.getContainer());
          WarpRequest request=new WarpRequest();
          WarpResponse response=new WarpResponse();
          response.setRequest(request);
          response.setConnection(connection);
          response.setPacket(packet);
          request.setConnection(connection);
  
          // Prepare the Proceed packet
          packet.reset();
          packet.setType(Constants.TYPE_CONF_PROCEED);
          connection.send(packet);
  
          // Loop for configuration packets
          while (true) {
              connection.recv(packet);
  
              switch (packet.getType()) {
                  case Constants.TYPE_REQ_INIT: {
                      int id=packet.readInteger();
                      String meth=packet.readString();
                      String ruri=packet.readString();
                      String args=packet.readString();
                      String prot=packet.readString();
                      if (Constants.DEBUG)
                          logger.debug("Request ID="+id+" \""+meth+" "+ruri+
                                       "?"+args+" "+prot+"\"");
  
                      request.recycle();
                      response.recycle();
                      response.setRequest(request);
                      response.setConnection(connection);
                      response.setPacket(packet);
  
                      request.setMethod(meth);
                      this.processUri(logger,request,ruri);
                      if (args.length()>0) request.setQueryString(args);
                      else request.setQueryString(null);
                      request.setProtocol(prot);
                      request.setConnection(connection);
                      Context ctx=connector.applicationContext(id);
                      if (ctx!=null) {
                          request.setContext(ctx);
                          request.setContextPath(ctx.getPath());
                          request.setHost((Host)ctx.getParent());
                      }
                      break;
                  }
  
                  case Constants.TYPE_REQ_CONTENT: {
                      String ctyp=packet.readString();
                      int clen=packet.readInteger();
                      if (Constants.DEBUG)
                          logger.debug("Request content type="+ctyp+" length="+
                                       clen);
                      if (ctyp.length()>0) request.setContentType(ctyp);
                      if (clen>0) request.setContentLength(clen);
                      break;
                  }
  
                  case Constants.TYPE_REQ_SCHEME: {
                      String schm=packet.readString();
                      if (Constants.DEBUG)
                          logger.debug("Request scheme="+schm);
                      request.setScheme(schm);
                      if (schm.equals("https"))
                         request.setSecure(true);
                      break;
                  }
  
                  case Constants.TYPE_REQ_AUTH: {
                      String user=packet.readString();
                      String auth=packet.readString();
                      if (Constants.DEBUG)
                          logger.debug("Request user="+user+" auth="+auth);
                      request.setAuthType(auth);
                      // What to do for user name?
                      if(user != null && auth != null && auth.equals("Basic")) {
                          Principal prin = new BasicPrincipal(user);
                          request.setUserPrincipal(prin);
                      }
  
                      break;
                  }
  
                  case Constants.TYPE_REQ_HEADER: {
                      String hnam=packet.readString();
                      String hval=packet.readString();
                      this.processHeader(logger,request,hnam,hval);
                      break;
                  }
  
                  case Constants.TYPE_REQ_SERVER: {
                      String host=packet.readString();
                      String addr=packet.readString();
                      int port=packet.readUnsignedShort();
                      if (Constants.DEBUG)
                          logger.debug("Server detail "+host+":"+port+
                                       " ("+addr+")");
                      request.setServerName(host);
                      request.setServerPort(port);
                      break;
                  }
  
                  case Constants.TYPE_REQ_CLIENT: {
                      String host=packet.readString();
                      String addr=packet.readString();
                      int port=packet.readUnsignedShort();
                      if (Constants.DEBUG)
                          logger.debug("Client detail "+host+":"+port+
                                       " ("+addr+")");
                      request.setRemoteHost(host);
                      request.setRemoteAddr(addr);
                      break;
                  }
  
                  case Constants.TYPE_REQ_PROCEED: {
                      if (Constants.DEBUG)
                          logger.debug("Request is about to be processed");
                      try {
                          connector.getContainer().invoke(request,response);
                      } catch (Exception e) {
                          logger.log(e);
                      }
                      request.finishRequest();
                      response.finishResponse();
                      if (Constants.DEBUG)
                          logger.debug("Request has been processed");
                      break;
                  }
  
                  default: {
                      String msg="Invalid packet "+packet.getType();
                      logger.log(msg);
                      packet.reset();
                      packet.setType(Constants.TYPE_FATAL);
                      packet.writeString(msg);
                      connection.send(packet);
                      return(false);
                  }
              }
          }
      }
  
      private void processUri(WarpLogger logger, WarpRequest req, String uri) {
  
          // Parse any requested session ID out of the request URI
          int semicolon = uri.indexOf(match);
          if (semicolon >= 0) {
              String rest = uri.substring(semicolon + match.length());
              int semicolon2 = rest.indexOf(';');
              if (semicolon2 >= 0) {
                  req.setRequestedSessionId(rest.substring(0, semicolon2));
                  rest = rest.substring(semicolon2);
              } else {
                  req.setRequestedSessionId(rest);
                  rest = "";
              }
              req.setRequestedSessionURL(true);
              uri = uri.substring(0, semicolon) + rest;
              if (Constants.DEBUG) {
                  logger.log("Requested URL session id is " +
                      ((HttpServletRequest) req.getRequest())
                      .getRequestedSessionId());
              }
          } else {
              req.setRequestedSessionId(null);
              req.setRequestedSessionURL(false);
          }
  
          req.setRequestURI(uri);
      }
  
      private void processHeader(WarpLogger logger, WarpRequest req,
                   String name, String value) {
  
          if (Constants.DEBUG)
              logger.debug("Request header "+name+": "+value);
  
          if ("cookie".equalsIgnoreCase(name)) {
              Cookie cookies[] = RequestUtil.parseCookieHeader(value);
              for (int i = 0; i < cookies.length; i++) {
                  if (cookies[i].getName().equals
                      (Globals.SESSION_COOKIE_NAME)) {
                      // Override anything requested in the URL
                      if (!req.isRequestedSessionIdFromCookie()) {
                          // Accept only the first session id cookie
                          req.setRequestedSessionId
                              (cookies[i].getValue());
                          req.setRequestedSessionCookie(true);
                          req.setRequestedSessionURL(false);
                          if (Constants.DEBUG) {
                              logger.debug("Requested cookie session id is " +
                                  ((HttpServletRequest) req.getRequest())
                                  .getRequestedSessionId());
                          }
                      }
                  }
                  if (Constants.DEBUG) {
                      logger.debug("Adding cookie "+cookies[i].getName()+"="+
                          cookies[i].getValue());
                  }
                  req.addCookie(cookies[i]);
              }
          }
          if (name.equalsIgnoreCase("Accept-Language"))
              parseAcceptLanguage(logger,req,value);
  
          if (name.equalsIgnoreCase("Authorization"))
              req.setAuthorization(value);
  
          req.addHeader(name,value);
      }
  
      /**
       * Parse the value of an <code>Accept-Language</code> header, and add
       * the corresponding Locales to the current request.
       *
       * @param value The value of the <code>Accept-Language</code> header.
       */
      private void parseAcceptLanguage(WarpLogger logger, WarpRequest request, 
                                       String value) {
  
          // Store the accumulated languages that have been requested in
          // a local collection, sorted by the quality value (so we can
          // add Locales in descending order).  The values will be ArrayLists
          // containing the corresponding Locales to be added
          TreeMap locales = new TreeMap();
  
          // Preprocess the value to remove all whitespace
          int white = value.indexOf(' ');
          if (white < 0)
              white = value.indexOf('\t');
          if (white >= 0) {
              StringBuffer sb = new StringBuffer();
              int len = value.length();
              for (int i = 0; i < len; i++) {
                  char ch = value.charAt(i);
                  if ((ch != ' ') && (ch != '\t'))
                      sb.append(ch);
              }
              value = sb.toString();
          }
  
          // Process each comma-delimited language specification
          parser.setString(value);        // ASSERT: parser is available to us
          int length = parser.getLength();
          while (true) {
  
              // Extract the next comma-delimited entry
              int start = parser.getIndex();
              if (start >= length)
                  break;
              int end = parser.findChar(',');
              String entry = parser.extract(start, end).trim();
              parser.advance();   // For the following entry
  
              // Extract the quality factor for this entry
              double quality = 1.0;
              int semi = entry.indexOf(";q=");
              if (semi >= 0) {
                  try {
                      quality = Double.parseDouble(entry.substring(semi + 3));
                  } catch (NumberFormatException e) {
                      quality = 0.0;
                  }
                  entry = entry.substring(0, semi);
              }
  
              // Skip entries we are not going to keep track of
              if (quality < 0.00005)
                  continue;       // Zero (or effectively zero) quality factors
              if ("*".equals(entry))
                  continue;       // FIXME - "*" entries are not handled
  
              // Extract the language and country for this entry
              String language = null;
              String country = null;
              int dash = entry.indexOf('-');
              if (dash < 0) {
                  language = entry;
                  country = "";
              } else {
                  language = entry.substring(0, dash);
                  country = entry.substring(dash + 1);
              }
  
              // Add a new Locale to the list of Locales for this quality level
              Locale locale = new Locale(language, country);
              Double key = new Double(-quality);  // Reverse the order
              ArrayList values = (ArrayList) locales.get(key);
              if (values == null) {
                  values = new ArrayList();
                  locales.put(key, values);
              }
              values.add(locale);
  
          }
  
          // Process the quality values in highest->lowest order (due to
          // negating the Double value when creating the key)
          Iterator keys = locales.keySet().iterator();
          while (keys.hasNext()) {
              Double key = (Double) keys.next();
              ArrayList list = (ArrayList) locales.get(key);
              Iterator values = list.iterator();
              while (values.hasNext()) {
                  Locale locale = (Locale) values.next();
                  if (Constants.DEBUG) {
                      logger.debug("Adding locale '" + locale + "'");
                  }
                  request.addLocale(locale);
              }
          }
      }
  
      class BasicPrincipal implements Principal {
          private String user;
  
          BasicPrincipal(String user) {
              this.user = user;
          }
  
          public boolean equals(Object another) {
              return (another instanceof Principal &&
                  ((Principal)another).getName().equals(user));
          }
  
          public String getName() {
              return user;
          }
  
          public String toString() {
              return getName();
          }
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpResponse.java
  
  Index: WarpResponse.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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.IOException;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.security.AccessController;
  import java.security.PrivilegedAction;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Locale;
  import java.util.TimeZone;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  //import javax.servlet.http.HttpUtils;
  import org.apache.catalina.HttpResponse;
  import org.apache.catalina.Globals;
  import org.apache.catalina.Logger;
  import org.apache.catalina.connector.HttpResponseBase;
  import org.apache.catalina.util.CookieTools;
  import org.apache.catalina.util.RequestUtil;
  
  public class WarpResponse extends HttpResponseBase {
      /** The local stream */
      private Stream localstream;
      /** The packet used for processing headers */
      private WarpPacket packet;
      /** The connection to which we are associated */
      private WarpConnection connection;
  
      /**
       * Create a new instance of a <code>WarpResponse</code>.
       */
      public WarpResponse() {
          super();
          // A WarpResponse is _always_ associated with a Stream
          this.localstream=new Stream(this);
          this.setStream(localstream);
      }
  
      /**
       * Recycle this <code>WarpResponse</code> instance.
       */
      public void recycle() {
          // Recycle our parent
          super.recycle();
          // Recycle the stream
          this.localstream.recycle();
          // Tell the parent that a stream is already in use.
          this.setStream(localstream);
      }
  
      /**
       * Set the <code>WarpPacket</code> instance used to process headers.
       */
      public void setPacket(WarpPacket packet) {
          this.packet=packet;
      }
  
      /**
       * Return the <code>WarpPacket</code> instance used to process headers.
       */
      public WarpPacket getPacket() {
          return(this.packet);
      }
  
      /**
       * Associate this <code>WarpResponse</code> instance with a specific
       * <code>WarpConnection</code> instance.
       */
      public void setConnection(WarpConnection connection) {
          this.connection=connection;
      }
  
      /**
       * Return the <code>WarpConnection</code> associated this instance of
       * <code>WarpResponse</code>.
       */
      public WarpConnection getConnection() {
          return(this.connection);
      }
  
      /**
       * Flush output and finish.
       */
      public void finishResponse()
      throws IOException {
          super.finishResponse();
          this.localstream.finish();
      }
  
      /**
       * Send the HTTP response headers, if this has not already occurred.
       */
      protected void sendHeaders() throws IOException {
          if (isCommitted()) return;
          if ("HTTP/0.9".equals(request.getRequest().getProtocol())) {
              committed = true;
              return;
          }
  
          this.packet.reset();
          this.packet.setType(Constants.TYPE_RES_STATUS);
          this.packet.writeUnsignedShort(status);
          this.packet.writeString(message);
          this.connection.send(this.packet);
  
          if (getContentType() != null) {
              this.packet.reset();
              this.packet.setType(Constants.TYPE_RES_HEADER);
              this.packet.writeString("Content-Type");
              this.packet.writeString(getContentType());
              this.connection.send(this.packet);
          }
          if (getContentLength() >= 0) {
              this.packet.reset();
              this.packet.setType(Constants.TYPE_RES_HEADER);
              this.packet.writeString("Content-Length");
              this.packet.writeString(Integer.toString(getContentLength()));
              this.connection.send(this.packet);
          }
  
          synchronized (headers) {
                  Iterator names = headers.keySet().iterator();
              while (names.hasNext()) {
                  String name = (String) names.next();
                  ArrayList values = (ArrayList) headers.get(name);
                  Iterator items = values.iterator();
                  while (items.hasNext()) {
                          String value = (String) items.next();
                      this.packet.reset();
                      this.packet.setType(Constants.TYPE_RES_HEADER);
                      this.packet.writeString(name);
                      this.packet.writeString(value);
                      this.connection.send(this.packet);
                      }
              }
          }
  
          // Add the session ID cookie if necessary
          HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
          HttpSession session = hreq.getSession(false);
  
          if ((session != null) && session.isNew() && (getContext() != null)
                  && getContext().getCookies()) {
              Cookie cookie = new Cookie(Globals.SESSION_COOKIE_NAME,
                                         session.getId());
              cookie.setMaxAge(-1);
              String contextPath = null;
                  if (context != null)
                      contextPath = context.getPath();
              if ((contextPath != null) && (contextPath.length() > 0))
                  cookie.setPath(contextPath);
              else
                  cookie.setPath("/");
              if (hreq.isSecure())
                  cookie.setSecure(true);
              addCookie(cookie);
          }
  
          // Send all specified cookies (if any)
          synchronized (cookies) {
              Iterator items = cookies.iterator();
              while (items.hasNext()) {
                  Cookie cookie = (Cookie) items.next();
                  String name=CookieTools.getCookieHeaderName(cookie);
                  StringBuffer value=new StringBuffer();
                  CookieTools.getCookieHeaderValue(cookie,value);
                      this.packet.reset();
                  this.packet.setType(Constants.TYPE_RES_HEADER);
                  this.packet.writeString(name);
                  this.packet.writeString(value.toString());
                  this.connection.send(this.packet);
              }
          }
  
              this.packet.reset();
          this.packet.setType(Constants.TYPE_RES_COMMIT);
          this.connection.send(this.packet);
  
          committed = true;
      }
  
      /**
       * The <code>OutputStream</code> that will handle all response body
       * transmission.
       */
      protected class Stream extends OutputStream {
          /** The response associated with this stream instance. */
          private WarpResponse response=null;
          /** The packet used by this stream instance. */
          private WarpPacket packet=null;
          /** Wether <code>close()</code> was called or not. */
          private boolean closed=false;
  
          /**
           * Construct a new instance of a <code>WarpResponse.Stream</code>
           * associated with a parent <code>WarpResponse</code>.
           */
          protected Stream(WarpResponse response) {
              super();
              this.response=response;
              this.packet=new WarpPacket();
          }
  
          /**
           * Write one byte of data to the <code>WarpPacket</code> nested
           * within this <code>WarpResponse.Stream</code>. All data is buffered
           * until the <code>flush()</code> or <code>close()</code> method is
           * not called.
           */
          public void write(int b)
          throws IOException {
              if (closed) throw new IOException("Stream closed");
              if (packet.size>=packet.buffer.length) this.flush();
              packet.buffer[packet.size++]=(byte)b;
          }
  
          /**
           * Flush the current packet to the WARP client.
           */
          public void flush()
          throws IOException {
              if (closed) throw new IOException("Stream closed");
              packet.setType(Constants.TYPE_RES_BODY);
              response.getConnection().send(packet);
              packet.reset();
          }
  
          /**
           * Flush this <code>WarpResponse.Stream</code> and close it.
           */
          public void close()
          throws IOException {
              if (closed) throw new IOException("Stream closed");
              flush();
              packet.setType(Constants.TYPE_RES_DONE);
              response.getConnection().send(packet);
              packet.reset();
          }
  
          /**
           * Flush this <code>WarpResponse.Stream</code> and close it.
           */
          public void finish()
          throws IOException {
              if (closed) return;
              else this.close();
          }
  
          /**
           * Recycle this <code>WarpResponse.Stream</code> instance.
           */
          public void recycle() {
              this.packet.reset();
              this.closed=false;
          }
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/java/org/apache/catalina/connector/warp/WarpSSLData.java
  
  Index: WarpSSLData.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 <ap...@apache.org>.                        *
   *                                                                           *
   * 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;
   
  /*
   * SSL message handling.
   */
   
  public class WarpSSLData {
      /**
       * Cipher use by the SSL.
       */
      String ciph;
      /**
       * SSL session.
       */
      String sess;
      /**
       * Size of the algorithm. (56-128)
       */
      int size;
  }
  
  
  

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