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 2003/01/29 13:54:59 UTC

cvs commit: jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5 MapperListener.java CoyoteConnector.java CoyoteRequest.java

remm        2003/01/29 04:54:59

  Modified:    coyote/src/java/org/apache/coyote/tomcat5
                        CoyoteConnector.java CoyoteRequest.java
  Added:       coyote/src/java/org/apache/coyote/tomcat5
                        MapperListener.java
  Log:
  - Use the new mapper.
  - This will very likely cause problems (although for now the old mapper still tries to
    map requests whcih have not been fully mapped). If it does, the mapper
    can be uncommented easily in CoyoteAdapter.postParseRequest.
  - Currently, the new mapper intgroduces a quite nasty B2C conversion on the
    URI, which will be addressed.
  
  Revision  Changes    Path
  1.11      +10 -2     jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteConnector.java
  
  Index: CoyoteConnector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteConnector.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CoyoteConnector.java	28 Jan 2003 18:19:38 -0000	1.10
  +++ CoyoteConnector.java	29 Jan 2003 12:54:59 -0000	1.11
  @@ -70,8 +70,8 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -import org.apache.tomcat.util.http.mapper.Mapper;
   import org.apache.tomcat.util.IntrospectionUtils;
  +import org.apache.tomcat.util.http.mapper.Mapper;
   
   import org.apache.coyote.Adapter;
   import org.apache.coyote.ProtocolHandler;
  @@ -329,6 +329,12 @@
        private Mapper mapper = new Mapper();
   
   
  +     /**
  +      * Mapper listener.
  +      */
  +     private MapperListener mapperListener = new MapperListener(mapper);
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -1113,6 +1119,8 @@
                   (sm.getString
                    ("coyoteConnector.protocolHandlerStartFailed", e));
           }
  +
  +        mapperListener.init();
   
       }
   
  
  
  
  1.16      +57 -37    jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteRequest.java
  
  Index: CoyoteRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteRequest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CoyoteRequest.java	28 Jan 2003 18:19:38 -0000	1.15
  +++ CoyoteRequest.java	29 Jan 2003 12:54:59 -0000	1.16
  @@ -100,8 +100,11 @@
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
   
  +import org.apache.tomcat.util.buf.MessageBytes;
   import org.apache.tomcat.util.http.FastHttpDateFormat;
   import org.apache.tomcat.util.http.Parameters;
  +import org.apache.tomcat.util.http.mapper.MappingData;
  +import org.apache.tomcat.util.net.SSLSupport;
   
   import org.apache.coyote.ActionCode;
   import org.apache.coyote.Request;
  @@ -124,9 +127,6 @@
   import org.apache.catalina.util.StringManager;
   import org.apache.catalina.util.StringParser;
   
  -import org.apache.tomcat.util.http.mapper.MappingData;
  -import org.apache.tomcat.util.net.SSLSupport;
  -
   /**
    * Wrapper object for the Coyote request.
    *
  @@ -272,24 +272,6 @@
   
   
       /**
  -     * Context path.
  -     */
  -    protected String contextPath = "";
  -
  -
  -    /**
  -     * Path info.
  -     */
  -    protected String pathInfo = null;
  -
  -
  -    /**
  -     * Servlet path.
  -     */
  -    protected String servletPath = null;
  -
  -
  -    /**
        * User principal.
        */
       protected Principal userPrincipal = null;
  @@ -396,9 +378,6 @@
           inputBuffer.recycle();
           usingInputStream = false;
           usingReader = false;
  -        contextPath = "";
  -        pathInfo = null;
  -        servletPath = null;
           userPrincipal = null;
           sessionParsed = false;
           requestParametersParsed = false;
  @@ -1475,9 +1454,9 @@
       public void setContextPath(String path) {
   
           if (path == null) {
  -            this.contextPath = "";
  +            mappingData.contextPath.setString("");
           } else {
  -            this.contextPath = path;
  +            mappingData.contextPath.setString(path);
           }
   
       }
  @@ -1512,7 +1491,7 @@
        * @param path The path information
        */
       public void setPathInfo(String path) {
  -        this.pathInfo = path;
  +        mappingData.pathInfo.setString(path);
       }
   
   
  @@ -1589,6 +1568,16 @@
   
   
       /**
  +     * Get the decoded request URI.
  +     * 
  +     * @return the URL decoded request URI
  +     */
  +    public MessageBytes getDecodedRequestURIMB() {
  +        return (coyoteRequest.decodedURI());
  +    }
  +
  +
  +    /**
        * Set the servlet path for this Request.  This will normally be called
        * when the associated Context is mapping the Request to a particular
        * Wrapper.
  @@ -1596,7 +1585,8 @@
        * @param path The servlet path
        */
       public void setServletPath(String path) {
  -        this.servletPath = path;
  +        if (path != null)
  +            mappingData.wrapperPath.setString(path);
       }
   
   
  @@ -1628,7 +1618,17 @@
        * of the Request.
        */
       public String getContextPath() {
  -        return (contextPath);
  +        return (mappingData.contextPath.toString());
  +    }
  +
  +
  +    /**
  +     * Get the context path.
  +     * 
  +     * @return the context path
  +     */
  +    public MessageBytes getContextPathMB() {
  +        return (mappingData.contextPath);
       }
   
   
  @@ -1740,7 +1740,17 @@
        * Return the path information associated with this Request.
        */
       public String getPathInfo() {
  -        return (pathInfo);
  +        return (mappingData.pathInfo.toString());
  +    }
  +
  +
  +    /**
  +     * Get the path info.
  +     * 
  +     * @return the path info
  +     */
  +    public MessageBytes getPathInfoMB() {
  +        return (mappingData.pathInfo);
       }
   
   
  @@ -1753,10 +1763,10 @@
           if (context == null)
               return (null);
   
  -        if (pathInfo == null) {
  +        if (getPathInfo() == null) {
               return (null);
           } else {
  -            return (context.getServletContext().getRealPath(pathInfo));
  +            return (context.getServletContext().getRealPath(getPathInfo()));
           }
   
       }
  @@ -1850,7 +1860,17 @@
        * that will process this request.
        */
       public String getServletPath() {
  -        return (servletPath);
  +        return (mappingData.wrapperPath.toString());
  +    }
  +
  +
  +    /**
  +     * Get the servlet path.
  +     * 
  +     * @return the servlet path
  +     */
  +    public MessageBytes getServletPathMB() {
  +        return (mappingData.wrapperPath);
       }
   
   
  
  
  
  1.1                  jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/MapperListener.java
  
  Index: MapperListener.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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 apache@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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  package org.apache.coyote.tomcat5;
  
  import java.util.Iterator;
  import java.util.Set;
  
  import javax.management.MBeanServer;
  import javax.management.Notification;
  import javax.management.NotificationListener;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.apache.commons.modeler.Registry;
  
  import org.apache.tomcat.util.http.mapper.Mapper;
  
  import org.apache.catalina.Container;
  import org.apache.catalina.Context;
  import org.apache.catalina.Engine;
  import org.apache.catalina.Host;
  import org.apache.catalina.ServerFactory;
  import org.apache.catalina.Wrapper;
  
  /**
   * Mapper listener.
   *
   * @author Remy Maucherat
   */
  public class MapperListener
      implements NotificationListener {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * Associated mapper.
       */
      protected Mapper mapper = null;
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Create mapper listener.
       */
      public MapperListener(Mapper mapper) {
          this.mapper = mapper;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Initialize associated mapper.
       */
      public void init() {
  
          try {
  
              MBeanServer mBeanServer = Registry.getServer();
  
              // Query contexts
              String onStr = "*:j2eeType=WebModule,*";
              ObjectName objectName = new ObjectName(onStr);
              Set set = mBeanServer.queryMBeans(objectName, null);
              Iterator iterator = set.iterator();
              while (iterator.hasNext()) {
                  ObjectInstance oi = (ObjectInstance) iterator.next();
                  String name = oi.getObjectName().getKeyProperty("name");
              }
  
              // Query wrappers
              onStr = "*:j2eeType=Servlet,*";
              objectName = new ObjectName(onStr);
              set = mBeanServer.queryMBeans(objectName, null);
              iterator = set.iterator();
              while (iterator.hasNext()) {
                  ObjectInstance oi = (ObjectInstance) iterator.next();
                  String name = oi.getObjectName().getKeyProperty("name");
                  String contextName = 
                      oi.getObjectName().getKeyProperty("WebModule");
                  registerWrapper(contextName, name);
              }
  
              //mBeanServer.addNotificationListener(objectName, this, null, null);
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
  
      // ------------------------------------------- NotificationListener Methods
  
  
      public void handleNotification(Notification notification,
                                     java.lang.Object handback) {
  
  
  
      }
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * Find context.
       */
      private void registerWrapper(String name, String wrapperName) {
  
          String defaultHost = null;
          Host host = null;
          Context context = null;
          Wrapper wrapper = null;
  
          String hostName = null;
          String contextName = null;
          if (name.startsWith("//")) {
              name = name.substring(2);
          }
          int slash = name.indexOf("/");
          if (slash != -1) {
              hostName = name.substring(0, slash);
              contextName = name.substring(slash);
          } else {
              return;
          }
          // Special case for the root context
          if (contextName.equals("/")) {
              contextName = "";
          }
  
          Container container = 
              ServerFactory.getServer().findServices()[0].getContainer();
  
          if (container instanceof Engine) {
              defaultHost = ((Engine) container).getDefaultHost();
              host = (Host) container.findChild(hostName);
          } else if (container instanceof Host) {
              defaultHost = container.getName();
              host = (Host) container;
          }
  
          context = (Context) host.findChild(contextName);
          wrapper = (Wrapper) context.findChild(wrapperName);
          String[] mappings = wrapper.findMappings();
  
          mapper.setDefaultHostName(defaultHost);
          mapper.addHost(hostName, host);
          mapper.addContext(hostName, contextName, context, 
                            context.findWelcomeFiles(), context.getResources());
          for (int i = 0; i < mappings.length; i++) {
              mapper.addWrapper(hostName, contextName, mappings[i], wrapper);
          }
  
      }
  
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org