Index: Response.java
===================================================================
--- Response.java	(revision 986040)
+++ Response.java	(working copy)
@@ -1,3 +1,8 @@
+/// Response.java from Tomcat 6.0.29 with JOnAS-specific modifications.
+///
+/// Original file:
+/// https://svn.apache.org/repos/asf/tomcat/tc6.0.x/tags/TOMCAT_6_0_29/java/org/apache/catalina/connector/Response.java
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -55,11 +60,38 @@
 import org.apache.tomcat.util.net.URL;
 
 /**
+ * JOnAS: Java(TM) Open Application Server
+ * Copyright (C) 2010 Bull S.A.S.
+ * Contact: jonas-team@ow2.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+import org.ow2.jonas.web.tomcat6.versioning.FilteredOutputStream;
+import org.ow2.jonas.web.tomcat6.versioning.VersionedPathBean;
+
+/**
  * Wrapper object for the Coyote response.
  *
  * @author Remy Maucherat
  * @author Craig R. McClanahan
- * @version $Id$
+ * @version $Revision$ $Date$
  */
 
 public class Response
@@ -127,9 +159,9 @@
         this.connector = connector;
         if("AJP/1.3".equals(connector.getProtocol())) {
             // default size to size of one ajp-packet
-            outputBuffer = new OutputBuffer(8184);
+            outputBuffer = new FilteredOutputStream(this, 8184);
         } else {
-            outputBuffer = new OutputBuffer();
+            outputBuffer = new FilteredOutputStream(this);
         }
         outputStream = new CoyoteOutputStream(outputBuffer);
         writer = new CoyoteWriter(outputBuffer);
@@ -178,8 +210,28 @@
         request.setContext(context);
     }
 
+    /**
+     * Associated VersionedPathBean.
+     */
+    protected VersionedPathBean versionedPathBean;
 
     /**
+     * Return the VersionedPathBean for the request.
+     */
+    public VersionedPathBean getVersionedPathBean() {
+        return (this.versionedPathBean);
+    }
+
+    /**
+     * Set the VersionedPathBean for the request.
+     *
+     * @param versionedPathBean The new VersionedPathBean
+     */
+    public void setVersionedPathBean(VersionedPathBean versionedPathBean) {
+        this.versionedPathBean = versionedPathBean;
+    }
+
+    /**
      * The associated output buffer.
      */
     protected OutputBuffer outputBuffer;
@@ -1044,6 +1096,15 @@
 
     public StringBuffer generateCookieString(final Cookie cookie, 
             final boolean httpOnly) {
+        final String cookiePath;
+        if (versionedPathBean != null && cookie.getPath() != null && versionedPathBean.getUserPath() != null &&
+            versionedPathBean.getVersionedPath() != null && cookie.getPath().startsWith(versionedPathBean.getVersionedPath())) {
+            cookiePath = versionedPathBean.getUserPath() + cookie.getPath().substring(
+                versionedPathBean.getVersionedPath().length());
+        } else {
+            cookiePath = cookie.getPath();
+        }
+
         final StringBuffer sb = new StringBuffer();
         //web application code can receive a IllegalArgumentException 
         //from the appendCookieValue invokation
@@ -1052,7 +1113,7 @@
                 public Object run(){
                     ServerCookie.appendCookieValue
                         (sb, cookie.getVersion(), cookie.getName(), 
-                         cookie.getValue(), cookie.getPath(), 
+                         cookie.getValue(), cookiePath, 
                          cookie.getDomain(), cookie.getComment(), 
                          cookie.getMaxAge(), cookie.getSecure(),
                          httpOnly);
@@ -1062,7 +1123,7 @@
         } else {
             ServerCookie.appendCookieValue
                 (sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
-                     cookie.getPath(), cookie.getDomain(), cookie.getComment(), 
+                     cookiePath, cookie.getDomain(), cookie.getComment(), 
                      cookie.getMaxAge(), cookie.getSecure(), httpOnly);
         }
         return sb;
@@ -1338,6 +1399,13 @@
         // Clear any data content that has been buffered
         resetBuffer();
 
+        if (versionedPathBean != null && versionedPathBean.getUserPath() != null &&
+            versionedPathBean.getVersionedPath() != null && location.startsWith(versionedPathBean.getVersionedPath())) {
+
+            location = versionedPathBean.getUserPath() + location.substring(
+                versionedPathBean.getVersionedPath().length());
+        }
+
         // Generate a temporary redirect to the specified location
         try {
             String absolute = toAbsolute(location);
@@ -1597,7 +1665,12 @@
                     redirectURLCC.append(portS, 0, portS.length());
                 }
                 if (!leadingSlash) {
-                    String relativePath = request.getDecodedRequestURI();
+                    String relativePath;
+                    if (versionedPathBean != null && versionedPathBean.getOriginalDecodedUri() != null) {
+                        relativePath = versionedPathBean.getOriginalDecodedUri();
+                    } else {
+                        relativePath = request.getDecodedRequestURI();
+                    }
                     int pos = relativePath.lastIndexOf('/');
                     relativePath = relativePath.substring(0, pos);
                     
