weaver      2005/03/08 13:59:15

  Modified:    portal/src/java/org/apache/jetspeed/engine/servlet
                        ServletRequestImpl.java
  Added:       portal/src/java/org/apache/jetspeed/engine/servlet
                        NamespaceEncodedSession.java
                        HttpSessionWrapper.java
  Log:
  Added a fix for the issues related to Tomcat not using a seperate session 
when a crosscontext dispatched to another.
  This patch uses the same namespace encodings approach as the PortletRequest 
does
  
  Revision  Changes    Path
  1.35      +21 -1     
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
  
  Index: ServletRequestImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- ServletRequestImpl.java   4 Feb 2005 19:52:20 -0000       1.34
  +++ ServletRequestImpl.java   8 Mar 2005 21:59:15 -0000       1.35
  @@ -28,6 +28,7 @@
   import javax.servlet.ServletRequest;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletRequestWrapper;
  +import javax.servlet.http.HttpSession;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -35,6 +36,7 @@
   import org.apache.jetspeed.container.url.PortalURL;
   import org.apache.jetspeed.request.JetspeedRequestContext;
   import org.apache.jetspeed.request.RequestContext;
  +import org.apache.pluto.om.common.ObjectID;
   import org.apache.pluto.om.entity.PortletApplicationEntity;
   import org.apache.pluto.om.entity.PortletEntity;
   import org.apache.pluto.om.portlet.PortletApplicationDefinition;
  @@ -61,12 +63,14 @@
       private ServletRequest currentRequest = null;
   
       private Map portletParameters;
  +    private ObjectID webAppId;
   
       public ServletRequestImpl( HttpServletRequest servletRequest, 
PortletWindow window )
       {
           super(servletRequest);
           nameSpaceMapper = NamespaceMapperAccess.getNamespaceMapper();
           this.portletWindow = window;        
  +        webAppId = 
portletWindow.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition().getWebApplicationDefinition().getId();
       }
   
       protected HttpServletRequest _getHttpServletRequest()
  @@ -447,4 +451,20 @@
                                        .getPortletApplicationDefinition()
                                        
.getWebApplicationDefinition().getContextRoot();
        }
  +     
  +    /* (non-Javadoc)
  +     * @see javax.servlet.http.HttpServletRequest#getSession()
  +     */
  +    public HttpSession getSession()
  +    {
  +        return new NamespaceEncodedSession(super.getSession(), webAppId);
  +    }
  +    
  +    /* (non-Javadoc)
  +     * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
  +     */
  +    public HttpSession getSession(boolean arg0)
  +    {
  +        return new NamespaceEncodedSession(super.getSession(arg0), webAppId);
  +    }
   }
  \ No newline at end of file
  
  
  
  1.1                  
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/NamespaceEncodedSession.java
  
  Index: NamespaceEncodedSession.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.engine.servlet;
  
  import java.util.Collections;
  import java.util.Enumeration;
  import java.util.HashSet;
  
  import javax.servlet.http.HttpSession;
  
  import org.apache.pluto.om.common.ObjectID;
  import org.apache.pluto.util.NamespaceMapper;
  import org.apache.pluto.util.NamespaceMapperAccess;
  
  /**
   * @author Scott T Weaver
   *  
   */
  public class NamespaceEncodedSession extends HttpSessionWrapper
  {
  
      private NamespaceMapper nameSpaceMapper;
  
      private ObjectID webAppId;
  
      private HashSet mappedNames = new HashSet();
  
      /**
       * @param session
       */
      public NamespaceEncodedSession(HttpSession session, ObjectID webAppId)
      {
          super(session);
          this.nameSpaceMapper = NamespaceMapperAccess.getNamespaceMapper();
          this.webAppId = webAppId;
      }
  
      /**
       * <p>
       * setAttribute
       * </p>
       * 
       * @see javax.servlet.ServletRequest#setAttribute(java.lang.String,
       *      java.lang.Object)
       * @param arg0
       * @param arg1
       */
      public void setAttribute(String name, Object value)
      {
  
          if (name == null)
          {
              throw new IllegalArgumentException("Attribute name == null");
          }
  
          if (skipEncode(name))
          {
              super.setAttribute(name, value);
          }
          else
          {
              String encodedKey = nameSpaceMapper.encode(webAppId, name);
              mappedNames.add(name);
              super.setAttribute(encodedKey, value);
          }
  
      }
  
      /**
       * @see 
javax.servlet.http.HttpServletRequest#getAttribute(java.lang.String)
       */
      public Object getAttribute(String name)
      {
          if (skipEncode(name))
          {
              return super.getAttribute(name);
          }
          else
          {
              return 
super.getAttribute(NamespaceMapperAccess.getNamespaceMapper().encode(webAppId, 
name));
          }
      }
  
      private boolean skipEncode(String name)
      {
          return name.startsWith("Pluto_") || name.startsWith("javax.portlet") 
|| name.startsWith("javax.servlet") || name.startsWith("org.apache.jetspeed");
      }
  
      /*
       * (non-Javadoc)
       * 
       * @see javax.servlet.http.HttpSession#getAttributeNames()
       */
      public Enumeration getAttributeNames()
      {
          Enumeration names = super.getAttributeNames();
          while (names.hasMoreElements())
          {
              String name = (String) names.nextElement();
              if (skipEncode(name))
              {
                  mappedNames.add(name);
              }
          }
  
          return Collections.enumeration(mappedNames);
      }
  
      /*
       * (non-Javadoc)
       * 
       * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
       */
      public void removeAttribute(String name)
      {
          if (skipEncode(name))
          {
              super.removeAttribute(name);
          }
          else
          {
              mappedNames.add(name);
              super.removeAttribute(nameSpaceMapper.encode(webAppId, name));
          }
      }
  }
  
  
  1.1                  
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/HttpSessionWrapper.java
  
  Index: HttpSessionWrapper.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.engine.servlet;
  
  import java.util.Enumeration;
  
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpSessionContext;
  
  /**
   * @author Scott T Weaver
   *
   */
  public class HttpSessionWrapper implements HttpSession
  {
      private HttpSession session;
      
      public HttpSessionWrapper(HttpSession session)
      {
          this.session = session;
      }
      
  
      /* (non-Javadoc)
       * @see java.lang.Object#equals(java.lang.Object)
       */
      public boolean equals(Object obj)
      {
          return session.equals(obj);
      }
      /**
       * @param arg0
       * @return
       */
      public Object getAttribute(String arg0)
      {
          return session.getAttribute(arg0);
      }
      /**
       * @return
       */
      public Enumeration getAttributeNames()
      {
          return session.getAttributeNames();
      }
      /**
       * @return
       */
      public long getCreationTime()
      {
          return session.getCreationTime();
      }
      /**
       * @return
       */
      public String getId()
      {
          return session.getId();
      }
      /**
       * @return
       */
      public long getLastAccessedTime()
      {
          return session.getLastAccessedTime();
      }
      /**
       * @return
       */
      public int getMaxInactiveInterval()
      {
          return session.getMaxInactiveInterval();
      }
      /**
       * @return
       */
      public ServletContext getServletContext()
      {
          return session.getServletContext();
      }
      /**
       * @return
       */
      public HttpSessionContext getSessionContext()
      {
          return session.getSessionContext();
      }
      /**
       * @param arg0
       * @return
       */
      public Object getValue(String arg0)
      {
          return session.getValue(arg0);
      }
      /**
       * @return
       */
      public String[] getValueNames()
      {
          return session.getValueNames();
      }
      /* (non-Javadoc)
       * @see java.lang.Object#hashCode()
       */
      public int hashCode()
      {
          return session.hashCode();
      }
      /**
       * 
       */
      public void invalidate()
      {
          session.invalidate();
      }
      /**
       * @return
       */
      public boolean isNew()
      {
          return session.isNew();
      }
      /**
       * @param arg0
       * @param arg1
       */
      public void putValue(String arg0, Object arg1)
      {
          session.putValue(arg0, arg1);
      }
      /**
       * @param arg0
       */
      public void removeAttribute(String arg0)
      {
          session.removeAttribute(arg0);
      }
      /**
       * @param arg0
       */
      public void removeValue(String arg0)
      {
          session.removeValue(arg0);
      }
      /**
       * @param arg0
       * @param arg1
       */
      public void setAttribute(String arg0, Object arg1)
      {
          session.setAttribute(arg0, arg1);
      }
      /**
       * @param arg0
       */
      public void setMaxInactiveInterval(int arg0)
      {
          session.setMaxInactiveInterval(arg0);
      }
      /* (non-Javadoc)
       * @see java.lang.Object#toString()
       */
      public String toString()
      {
          return session.toString();
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to