Index: Response.java
===================================================================
--- Response.java	(revision 964614)
+++ Response.java	(working copy)
@@ -1,3 +1,8 @@
+/// Response.java from Tomcat 7.0.2 with JOnAS-specific modifications.
+///
+/// Original file:
+/// https://svn.apache.org/repos/asf/tomcat/tc7.0.x/tags/TOMCAT_7_0_2/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
@@ -58,6 +63,33 @@
 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: Response.patch 20320 2010-09-15 06:23:19Z alitokmen $
+ * --------------------------------------------------------------------------
+ */
+
+import org.ow2.jonas.web.tomcat7.versioning.FilteredOutputStream;
+import org.ow2.jonas.web.tomcat7.versioning.VersionedPathBean;
+
+/**
  * Wrapper object for the Coyote response.
  *
  * @author Remy Maucherat
@@ -142,9 +174,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);
@@ -193,8 +225,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;
@@ -1005,6 +1057,15 @@
     }
 
     public StringBuffer generateCookieString(final Cookie cookie) {
+        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 invocation
@@ -1013,7 +1074,7 @@
                 public Void run(){
                     ServerCookie.appendCookieValue
                         (sb, cookie.getVersion(), cookie.getName(), 
-                         cookie.getValue(), cookie.getPath(), 
+                         cookie.getValue(), cookiePath, 
                          cookie.getDomain(), cookie.getComment(), 
                          cookie.getMaxAge(), cookie.getSecure(),
                          cookie.isHttpOnly());
@@ -1023,7 +1084,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(),
                      cookie.isHttpOnly());
         }
@@ -1302,6 +1363,17 @@
         // Clear any data content that has been buffered
         resetBuffer();
 
+        if (versionedPathBean != null && versionedPathBean.getUserPath() != null &&
+            versionedPathBean.getVersionedPath() != null && location.startsWith(versionedPathBean.getVersionedPath())) {
+
+            if ("/".equals(versionedPathBean.getUserPath())) {
+                location = location.substring(versionedPathBean.getVersionedPath().length());
+            } else {
+                location = versionedPathBean.getUserPath() + location.substring(
+                    versionedPathBean.getVersionedPath().length());
+            }
+        }
+
         // Generate a temporary redirect to the specified location
         try {
             String absolute = toAbsolute(location);
@@ -1570,7 +1642,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);
                     
