Author: woonsan
Date: Sun Nov 25 23:41:26 2007
New Revision: 598155

URL: http://svn.apache.org/viewvc?rev=598155&view=rev
Log:
Removed some problematic codes using ASMification to decorate Websphere's 
request object and modified documentation.

Added:
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/DefaultPortletRequestResponseUnwrapper.java
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/container/invoker/
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/container/invoker/PortletRequestResponseUnwrapper.java
Removed:
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/AdjustedSRTServletRequestDump.java
Modified:
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvokerFactory.java
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/pluto-factories.xml
    
portals/jetspeed-2/branches/JETSPEED-2.1.3/xdocs/guides/guide-aggregation.xml

Added: 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/DefaultPortletRequestResponseUnwrapper.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/DefaultPortletRequestResponseUnwrapper.java?rev=598155&view=auto
==============================================================================
--- 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/DefaultPortletRequestResponseUnwrapper.java
 (added)
+++ 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/DefaultPortletRequestResponseUnwrapper.java
 Sun Nov 25 23:41:26 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.container.invoker;
+
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+/**
+ * DefaultPortletRequestResponseUnwrapper implements 
PortletRequestResponseUnwrapper
+ * and finds servlet request or servlet response by simple unwrapping.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Woonsan Ko</a>
+ * @version $Id: $
+ */
+public class DefaultPortletRequestResponseUnwrapper implements 
PortletRequestResponseUnwrapper
+{
+    public ServletRequest unwrapPortletRequest(PortletRequest portletRequest)
+    {
+        ServletRequest servletRequest = 
((HttpServletRequestWrapper)((HttpServletRequestWrapper)((HttpServletRequestWrapper)portletRequest).getRequest()).getRequest()).getRequest();
+        return servletRequest;
+    }
+    
+    public ServletResponse unwrapPortletResponse(PortletResponse 
portletResponse)
+    {
+        ServletResponse servletResponse = ((HttpServletResponseWrapper) 
portletResponse).getResponse();
+        return servletResponse;
+    }
+}

Modified: 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java?rev=598155&r1=598154&r2=598155&view=diff
==============================================================================
--- 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
 (original)
+++ 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
 Sun Nov 25 23:41:26 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.jetspeed.container.invoker;
 
-import java.lang.reflect.Constructor;
 import java.io.IOException;
 
 import javax.portlet.ActionRequest;
@@ -32,8 +31,6 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpServletResponseWrapper;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -80,18 +77,19 @@
     protected String servletMappingName;
     
     /**
-     * Wheter the servlet request instance should be wrapped or not if it is 
under WebSphere environment.
+     * requestResponseUnwrapper used to unwrap portlet request or portlet 
response
+     * to find the real servlet request or servlet response.
      */
-    protected boolean wrapRequestOfWebSphere;
+    protected PortletRequestResponseUnwrapper requestResponseUnwrapper;
 
     public ServletPortletInvoker()
     {
-        this(false);
+        this(new DefaultPortletRequestResponseUnwrapper());
     }
     
-    public ServletPortletInvoker(boolean wrapRequestOfWebSphere)
+    public ServletPortletInvoker(PortletRequestResponseUnwrapper 
requestResponseUnwrapper)
     {
-        this.wrapRequestOfWebSphere = wrapRequestOfWebSphere;
+        this.requestResponseUnwrapper = requestResponseUnwrapper;
     }
 
     /* (non-Javadoc)
@@ -228,8 +226,8 @@
         }
 
         // gather all required data from request and response
-        ServletRequest servletRequest = 
getServletRequestForContainer(portletRequest, appContext);
-        ServletResponse servletResponse = 
getServletResponseForContainer(portletResponse);
+        ServletRequest servletRequest = 
this.requestResponseUnwrapper.unwrapPortletRequest(portletRequest);
+        ServletResponse servletResponse = 
this.requestResponseUnwrapper.unwrapPortletResponse(portletResponse);
 
         try
         {
@@ -309,95 +307,4 @@
 
     }
 
-    protected ServletRequest getServletRequestForContainer(PortletRequest 
portletRequest, ServletContext appContext)
-    {
-        ServletRequest servletRequest = 
((HttpServletRequestWrapper)((HttpServletRequestWrapper)((HttpServletRequestWrapper)portletRequest).getRequest()).getRequest()).getRequest();
-        
-        if (this.wrapRequestOfWebSphere && 
CurrentWorkerContext.getParallelRenderingMode())
-        {
-            String entAppNameOnWebSphere = (String) 
appContext.getAttribute("com.ibm.websphere.servlet.enterprise.application.name");
-            
-            // If the container is WebSphere, wrap the request.
-            if (entAppNameOnWebSphere != null)
-            {
-                try
-                {
-                    servletRequest = 
wrapWebSphereSRTServletRequest(servletRequest);
-                }
-                catch (Throwable th)
-                {
-                    log.error("Failed to load websphere system classes.", th);
-                }
-            }
-        }
-        
-        return servletRequest;
-    }
-
-    protected ServletResponse getServletResponseForContainer(PortletResponse 
portletResponse)
-    {
-        ServletResponse servletResponse = ((HttpServletResponseWrapper) 
portletResponse).getResponse();
-        return servletResponse;
-    }
-
-    private static Class adjustedSRTServletRequestClazz;
-    private static Constructor adjustedSRTServletRequestClazzConstructor;
-    
-    private static ServletRequest 
wrapWebSphereSRTServletRequest(ServletRequest servletRequest) throws Throwable
-    {
-        if (adjustedSRTServletRequestClazzConstructor == null)
-        {
-            if (adjustedSRTServletRequestClazz == null)
-            {
-                synchronized (ServletPortletInvoker.class)
-                {
-                    if (adjustedSRTServletRequestClazz == null)
-                    {
-                        adjustedSRTServletRequestClazz = new 
AdjustedSRTServletRequestClassLoader().defineAdjustedSRTServletRequestClass();
-                    }
-                }
-            }
-            
-            adjustedSRTServletRequestClazzConstructor = 
adjustedSRTServletRequestClazz.getConstructors()[0];
-        }
-
-        Object [] args = new Object [] { servletRequest };
-        return (ServletRequest) 
adjustedSRTServletRequestClazzConstructor.newInstance(args);
-    }
-    
-    private static class AdjustedSRTServletRequestClassLoader extends 
ClassLoader
-    {
-        public AdjustedSRTServletRequestClassLoader()
-        {
-            super(PortletRequestContext.class.getClassLoader());
-        }
-        
-        public Class defineAdjustedSRTServletRequestClass() throws Throwable
-        {
-            byte [] bytes = AdjustedSRTServletRequestDump.dumpInner1();
-            
-            //if (log.isDebugEnabled())
-            //{
-            //    java.io.File classFile = 
java.io.File.createTempFile("AdjustedSRTServletRequest$1.class.", ".tmp");
-            //    java.io.FileOutputStream fos = new 
java.io.FileOutputStream(classFile);
-            //    fos.write(bytes, 0, bytes.length);
-            //    fos.close();
-            //    log.debug("Generated a class. See " + 
classFile.getCanonicalPath());
-            //}
-            
-            Class inner1 = 
defineClass("org.apache.jetspeed.container.invoker.AdjustedSRTServletRequest$1",
 bytes, 0, bytes.length);
-            bytes = AdjustedSRTServletRequestDump.dump();
-            
-            //if (log.isDebugEnabled())
-            //{
-            //    java.io.File classFile = 
java.io.File.createTempFile("AdjustedSRTServletRequest.class.", ".tmp");
-            //    java.io.FileOutputStream fos = new 
java.io.FileOutputStream(classFile);
-            //    fos.write(bytes, 0, bytes.length);
-            //    fos.close();
-            //    log.debug("Generated a class. See " + 
classFile.getCanonicalPath());
-            //}
-            
-            return 
defineClass("org.apache.jetspeed.container.invoker.AdjustedSRTServletRequest", 
bytes, 0, bytes.length);
-        }
-    }
 }

Modified: 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvokerFactory.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvokerFactory.java?rev=598155&r1=598154&r2=598155&view=diff
==============================================================================
--- 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvokerFactory.java
 (original)
+++ 
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvokerFactory.java
 Sun Nov 25 23:41:26 2007
@@ -25,18 +25,19 @@
 {
 
     /**
-     * Wheter the servlet request instance should be wrapped or not if it is 
under WebSphere environment.
+     * requestResponseUnwrapper used to unwrap portlet request or portlet 
response
+     * to find the real servlet request or servlet response.
      */
-    protected boolean wrapRequestOfWebSphere;
+    protected PortletRequestResponseUnwrapper requestResponseUnwrapper;
     
     public ServletPortletInvokerFactory()
     {
-        this(false);
+        this(null);
     }
 
-    public ServletPortletInvokerFactory(boolean wrapRequestOfWebSphere)
+    public ServletPortletInvokerFactory(PortletRequestResponseUnwrapper 
requestResponseUnwrapper)
     {
-        this.wrapRequestOfWebSphere = wrapRequestOfWebSphere;
+        this.requestResponseUnwrapper = requestResponseUnwrapper;
     }
 
     /**
@@ -50,7 +51,7 @@
      */
     public ServletPortletInvoker createInstance() 
     {  
-        return new ServletPortletInvoker(this.wrapRequestOfWebSphere);        
+        return new ServletPortletInvoker(this.requestResponseUnwrapper);       
 
     }
 
     /**

Added: 
portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/container/invoker/PortletRequestResponseUnwrapper.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/container/invoker/PortletRequestResponseUnwrapper.java?rev=598155&view=auto
==============================================================================
--- 
portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/container/invoker/PortletRequestResponseUnwrapper.java
 (added)
+++ 
portals/jetspeed-2/branches/JETSPEED-2.1.3/jetspeed-api/src/java/org/apache/jetspeed/container/invoker/PortletRequestResponseUnwrapper.java
 Sun Nov 25 23:41:26 2007
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.container.invoker;
+
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * PortletRequestResponseUnwrapper finds servlet request or servlet response 
+ * from portlet request or portlet response by unwrapping.
+ * Third-party module can provide an implementation to decorate the real 
request
+ * or response object of a servlet container.
+ * For example, the real request object of a servlet container can be decorated
+ * because it is not thread-safe under Jetspeed parallel rendering mode.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Woonsan Ko</a>
+ * @version $Id: $
+ */
+public interface PortletRequestResponseUnwrapper
+{
+    /**
+     * Unwraps portlet request to find the real servlet request.
+     * 
+     * @param portletRequest The portlet request to be unwrapped.
+     * @return servletRequest The servlet request found by unwrapping.
+     */
+    ServletRequest unwrapPortletRequest(PortletRequest portletRequest);
+    
+    /**
+     * Unwraps portlet response to find the real servlet response.
+     * 
+     * @param portletResponse The portlet response to be unwrapped.
+     * @return servletResponse The servlet response found by unwrapping.
+     */
+    ServletResponse unwrapPortletResponse(PortletResponse portletResponse);
+}

Modified: 
portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/pluto-factories.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/pluto-factories.xml?rev=598155&r1=598154&r2=598155&view=diff
==============================================================================
--- 
portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/pluto-factories.xml
 (original)
+++ 
portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/pluto-factories.xml
 Sun Nov 25 23:41:26 2007
@@ -29,12 +29,19 @@
           
   <bean id="ServletPortletInvokerFactory"
         
class="org.apache.jetspeed.container.invoker.ServletPortletInvokerFactory">
-    <!-- Set the following argument to true when you are running the system 
with parallel rendering mode under WebSphere. -->
     <constructor-arg index="0">
-        <value>false</value>
+        <ref bean="PortletRequestResponseUnwrapper" />
     </constructor-arg>
   </bean>
-       
+  
+  <!--  
+  PortletRequestResponseUnwrapper finds servlet request or servlet response 
from portlet request or portlet response by unwrapping.
+  Third-party module can provide an implementation to decorate the real 
request or response object of a servlet container.
+  For example, the real request object of a servlet container can be decorated 
because it is not thread-safe under Jetspeed parallel rendering mode.
+  -->
+  <bean id="PortletRequestResponseUnwrapper"
+        
class="org.apache.jetspeed.container.invoker.DefaultPortletRequestResponseUnwrapper"
 />
+  
   <bean id="javax.portlet.ActionRequest"
         
class="org.apache.jetspeed.components.factorybeans.PlutoFactoryFactoryBean"
   >             

Modified: 
portals/jetspeed-2/branches/JETSPEED-2.1.3/xdocs/guides/guide-aggregation.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/xdocs/guides/guide-aggregation.xml?rev=598155&r1=598154&r2=598155&view=diff
==============================================================================
--- 
portals/jetspeed-2/branches/JETSPEED-2.1.3/xdocs/guides/guide-aggregation.xml 
(original)
+++ 
portals/jetspeed-2/branches/JETSPEED-2.1.3/xdocs/guides/guide-aggregation.xml 
Sun Nov 25 23:41:26 2007
@@ -142,6 +142,7 @@
             </p>
             <subsection name='1. Login Filter'>
             <p>Configure the WEB-INF/web.xml to use the PortalFilter for 
logging in by uncommented  the PortalFilter and its mapping:</p>
+            <source test="">
                 <![CDATA[
   <filter>
     <filter-name>PortalFilter</filter-name>
@@ -153,19 +154,24 @@
     <url-pattern>/*</url-pattern>    
   </filter-mapping>               
 ]]>            
+            </source>
             </subsection>
             <subsection name='2.Portal Login Portlet'>
             <p>Edit the default-page.psml, changing the login portlet to the 
filter-based login portlet as shown below.
             Make sure to also change the fragment id. Change:</p>
+            <source test="">
                 <![CDATA[
     <fragment id="dp-12" type="portlet" name="j2-admin::LoginPortlet">
     ...
 ]]>            
+            </source>
                        <p>to ..</p>
+            <source test="">
                 <![CDATA[
     <fragment id="dp-12a" type="portlet" name="j2-admin::PortalLoginPortlet">
     ...
 ]]>                                                
+            </source>
             </subsection>
             <subsection name='3. Use the Jetspeed Portal Request Factory'>     
       
             <p>
@@ -180,17 +186,20 @@
 For other web containers like Tomcat which doesn't have this "problem", 
nothing has to be specified (none is by default), in which case the request 
will be wrapped in an HttpServletRequestWrapper to maintain the same level of 
wrapping (needed for easy access to the original request in 
ServletPortletInvoker.            
             </p>
             <p>Edit WEB-INF/assembly/wps.xml, and uncomment the one bean found 
there</p>
+            <source test="">
 <![CDATA[            
 <beans>   
     <!-- required for websphere, uncomment if running under websphere
          see:  http://issues.apache.org/jira/browse/JS2-355 -->
     <bean id="org.apache.jetspeed.request.PortalRequestFactory" 
class="org.apache.jetspeed.request.PortalRequestFactoryImpl"/>   
 </beans>
-]]>                                                            
+]]>                                    
+            </source>
             </subsection>
             <subsection name='4. Turn on the Multithreaded Aggregation Engine'>
             <p>Swap out the (org.apache.jetspeed.aggregator.PageAggregator) 
with the multithreaded aggregation engine in WEB-INF/assembly/pipelines.xml:
             </p>
+            <source test="">
 <![CDATA[            
   <bean id="aggregatorValve"
         class="org.apache.jetspeed.aggregator.AggregatorValve"
@@ -201,23 +210,27 @@
    </constructor-arg>
   </bean> 
 ]]>                                                            
+          </source>
                </subsection>
-               <subsection name='5. Pluto Factories'>
-               <p>Turn on the Websphere parallel rendering mode in the 
WEB-INF/assembly/pluto-factories.xml by setting the first constructor argument 
to true:</p>
+               <subsection name='Optional Replacement for Portlet 
Request/Response Unwrapper'>
+          <p>You can replace the default portlet request/response unwrapper 
with a third-party module in WEB-INF/assembly/pluto-factories.xml.</p>
+          <p>Because the servlet request object of a servlet container could 
not be thread-safe under Jetspeed parallel rendering mode, the third-party 
unwrapper module can provide a thread-safe implementation by decorating the 
original request object.</p>
+          <p>Here's an example setting for third-party unwrapper module:</p>
+          <source test="">
 <![CDATA[              
-   <bean id="ServletPortletInvokerFactory"
-        
class="org.apache.jetspeed.container.invoker.ServletPortletInvokerFactory" 
-  />   
-        
class="org.apache.jetspeed.container.invoker.ServletPortletInvokerFactory">
-    <!-- Set the following argument to true when you are running the system 
with parallel rendering mode under WebSphere. -->
-    <constructor-arg index="0">
-        <value>true</value>
-    </constructor-arg>
-  </bean>
+  <!--  
+  PortletRequestResponseUnwrapper finds servlet request or servlet response 
from portlet request or portlet response by unwrapping.
+  Third-party module can provide an implementation to decorate the real 
request or response object of a servlet container.
+  For example, the real request object of a servlet container can be decorated 
because it is not thread-safe under Jetspeed parallel rendering mode.
+  -->
+  <bean id="PortletRequestResponseUnwrapper"
+        
class="com.bluesunrise.jetspeed.container.invoker.WebspherePortletRequestResponseUnwrapper"
 />
 ]]>                                                                            
+          </source>
                </subsection>            
                <subsection name='Optional CommonJ Work Manager'>
                <p> If you want to use Commonj Work Manager provided by the 
container, uncomment the followings in WEB-INF/assembly/aggregation.xml:</p>
+          <source test="">
 <![CDATA[                              
     <bean id="JetspeedWorkManager" 
class="org.springframework.jndi.JndiObjectFactoryBean">
         <property name="resourceRef"><value>false</value></property> 
@@ -233,6 +246,7 @@
         </constructor-arg>
     </bean>
 ]]>                                    
+          </source>
 <p>                                                    
     Also replace all references to 
org.apache.jetspeed.aggregator.WorkerMonitor with 
org.apache.jetspeed.aggregator.CommonjWorkerMonitor in 
WEB-INF/assembly/aggregation.xml.
 </p>



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

Reply via email to