portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r544024 - in /portals/jetspeed-2/trunk: components/portal/src/java/org/apache/jetspeed/ components/portal/src/java/org/apache/jetspeed/container/state/impl/ components/portal/src/java/org/apache/jetspeed/resource/ jetspeed-api/src/java/org/...
Date Mon, 04 Jun 2007 00:59:10 GMT
Author: ate
Date: Sun Jun  3 17:59:09 2007
New Revision: 544024

URL: http://svn.apache.org/viewvc?view=rev&rev=544024
Log:
JS2-729: Preliminary Portlet API 2.0 ResourceURL support allowing full response control like
for cookies and compressed output streams
See: https://issues.apache.org/jira/browse/JS2-729

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/BufferedHttpServletResponse.java
  (with props)
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/ResourceValveImpl.java
  (with props)
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/   (props changed)
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/AbstractNavigationalState.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/JetspeedNavigationalStateCodec.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/PortletWindowRequestNavigationalStates.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/SessionNavigationalState.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/PortalReservedParameters.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/container/state/NavigationalState.java
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/pipelines.xml

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Jun  3 17:59:09 2007
@@ -1,2 +1,2 @@
-target
+target
 surefire*.properties

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/AbstractNavigationalState.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/AbstractNavigationalState.java?view=diff&rev=544024&r1=544023&r2=544024
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/AbstractNavigationalState.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/AbstractNavigationalState.java
Sun Jun  3 17:59:09 2007
@@ -219,6 +219,11 @@
     {
         return requestStates.getActionWindow();
     }
+    
+    public PortletWindow getPortletWindowOfResource()
+    {
+        return requestStates.getResourceWindow();
+    }
 
     public String encode(PortletWindow window, Map parameters, PortletMode mode, WindowState
state, boolean action)
     throws UnsupportedEncodingException

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/JetspeedNavigationalStateCodec.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/JetspeedNavigationalStateCodec.java?view=diff&rev=544024&r1=544023&r2=544024
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/JetspeedNavigationalStateCodec.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/JetspeedNavigationalStateCodec.java
Sun Jun  3 17:59:09 2007
@@ -30,6 +30,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.PortalContext;
+import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.container.window.PortletWindowAccessor;
 import org.apache.pluto.om.window.PortletWindow;
 
@@ -52,6 +53,7 @@
     protected static final char STATE_KEY = 'd';
     protected static final char PARAM_KEY = 'e';
     protected static final char CLEAR_PARAMS_KEY = 'f';
+    protected static final char RESOURCE_WINDOW_ID_KEY = 'g';
     
     protected static final String keytable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
     protected final PortletMode[] portletModes;
@@ -218,7 +220,7 @@
             }
         }
         // encode as requestURL parameters
-        return encode(states, windowId, targetState, false, navParamsStateFull, renderParamsStateFull);
+        return encode(states, windowId, targetState, false, false, navParamsStateFull, renderParamsStateFull);
     }
 
     public String encode(PortletWindowRequestNavigationalStates states, PortletWindow window,
Map parameters, 
@@ -233,13 +235,26 @@
         targetState.setWindowState(windowState != null ? windowState : currentState != null
? currentState.getWindowState() : null);
         
         Iterator parametersIter = parameters.entrySet().iterator();
+        
+        boolean resource = false;
 
         Map.Entry entry;
+        String parameter;
         // fill in the new parameters
         while ( parametersIter.hasNext())
         {
             entry = (Map.Entry)parametersIter.next();
-            targetState.setParameters((String)entry.getKey(), (String[])entry.getValue());
+            parameter = (String)entry.getKey();
+            if (!resource && !action && PortalReservedParameters.PORTLET_RESOURCE_URL_REQUEST_PARAMETER.equals(parameter))
+            {
+                resource = true;
+                navParamsStateFull = true;
+                renderParamsStateFull = true;
+            }
+            else
+            {
+                targetState.setParameters(parameter, (String[])entry.getValue());
+            }
         }
         if ( renderParamsStateFull && targetState.getParametersMap() == null )
         {
@@ -247,11 +262,11 @@
             // and not copied when synchronizing the state (encoded as CLEAR_PARAMS_KEY)
             targetState.setClearParameters(true);
         }
-        return encode(states, windowId, targetState, action, navParamsStateFull, renderParamsStateFull);
+        return encode(states, windowId, targetState, action, resource, navParamsStateFull,
renderParamsStateFull);
     }
 
     protected String encode(PortletWindowRequestNavigationalStates states, String targetWindowId,

-            PortletWindowRequestNavigationalState targetState, boolean action, boolean navParamsStateFull,

+            PortletWindowRequestNavigationalState targetState, boolean action, boolean resource,
boolean navParamsStateFull, 
             boolean renderParamsStateFull)
     throws UnsupportedEncodingException
     {
@@ -275,7 +290,7 @@
                 }
                 else
                 {
-                    encodedState = encodePortletWindowNavigationalState(windowId, pwfns,
false, navParamsStateFull, 
+                    encodedState = encodePortletWindowNavigationalState(windowId, pwfns,
false, false, navParamsStateFull, 
                             renderParamsStateFull);
                     if ( encodedState.length() > 0 )
                     {
@@ -292,7 +307,7 @@
                 }
             }
         }
-        encodedState = encodePortletWindowNavigationalState(targetWindowId, targetState,
action, false, false); 
+        encodedState = encodePortletWindowNavigationalState(targetWindowId, targetState,
action, resource, false, false); 
         if ( encodedState.length() > 0 )
         {
             if ( !haveState )
@@ -315,12 +330,12 @@
     }
     
     protected String encodePortletWindowNavigationalState(String windowId, PortletWindowRequestNavigationalState
state, 
-            boolean action, boolean navParamsStateFull, boolean renderParamsStateFull)
+            boolean action, boolean resource, boolean navParamsStateFull, boolean renderParamsStateFull)
     {
         StringBuffer buffer = new StringBuffer();
-        buffer.append(action ? ACTION_WINDOW_ID_KEY : RENDER_WINDOW_ID_KEY);
+        buffer.append(action ? ACTION_WINDOW_ID_KEY : resource? RESOURCE_WINDOW_ID_KEY: RENDER_WINDOW_ID_KEY);
         buffer.append(windowId);
-        boolean encoded = action;
+        boolean encoded = action || resource;
         
         if ( action || !navParamsStateFull )
         {
@@ -388,7 +403,7 @@
     protected PortletWindowRequestNavigationalState decodeParameter(PortletWindowAccessor
accessor, PortletWindowRequestNavigationalStates states, PortletWindowRequestNavigationalState
currentState, String parameter)
     {
         char parameterType = parameter.charAt(0);
-        if (parameterType == RENDER_WINDOW_ID_KEY || parameterType == ACTION_WINDOW_ID_KEY
)
+        if (parameterType == RENDER_WINDOW_ID_KEY || parameterType == ACTION_WINDOW_ID_KEY
|| parameterType == RESOURCE_WINDOW_ID_KEY )
         {            
             String windowId = parameter.substring(1);
             currentState = states.getPortletWindowNavigationalState(windowId);
@@ -404,6 +419,10 @@
                 if ( parameterType == ACTION_WINDOW_ID_KEY )
                 {
                     states.setActionWindow(window);
+                }
+                else if (parameterType == RESOURCE_WINDOW_ID_KEY )
+                {
+                    states.setResourceWindow(window);
                 }
             }
         }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/PortletWindowRequestNavigationalStates.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/PortletWindowRequestNavigationalStates.java?view=diff&rev=544024&r1=544023&r2=544024
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/PortletWindowRequestNavigationalStates.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/PortletWindowRequestNavigationalStates.java
Sun Jun  3 17:59:09 2007
@@ -28,6 +28,7 @@
     private Map pwnStates = new HashMap();
     private PortletWindow maximizedWindow;
     private PortletWindow actionWindow;
+    private PortletWindow resourceWindow;
     
     public PortletWindowRequestNavigationalStates(String characterEncoding)
     {
@@ -76,5 +77,13 @@
     public void setActionWindow(PortletWindow actionWindow)
     {
         this.actionWindow = actionWindow;
-    }    
+    }
+    public void setResourceWindow(PortletWindow resourceWindow)
+    {
+        this.resourceWindow = resourceWindow;
+    }
+    public PortletWindow getResourceWindow()
+    {
+        return resourceWindow;
+    }
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/SessionNavigationalState.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/SessionNavigationalState.java?view=diff&rev=544024&r1=544023&r2=544024
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/SessionNavigationalState.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/state/impl/SessionNavigationalState.java
Sun Jun  3 17:59:09 2007
@@ -20,7 +20,6 @@
 import javax.servlet.http.HttpSession;
 
 import org.apache.jetspeed.JetspeedActions;
-import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.cache.JetspeedCache;
 import org.apache.jetspeed.container.state.NavigationalState;
 import org.apache.jetspeed.request.RequestContext;
@@ -42,37 +41,41 @@
     {
         PortletWindowRequestNavigationalStates requestStates = getPortletWindowRequestNavigationalStates();
         
-        boolean transientNavState = false;
+        // for Resource (PortletURL) requests, session state is never synchronized
+        boolean transientNavState = requestStates.getResourceWindow() != null;
         
-        // Check if a maximized window is set in the request.
-        // This can mean a window with state MAXIMIZED *or* SOLO.
-        // With a SOLO state, or if request parameter nav-state is provided with value "transient",
skip all synchroniziations!
-        String requestMaximizedWindowId = null;
+        String clearCacheWindowId = null;
         
-        if ( requestStates.getMaximizedWindow() != null )
+        if (!transientNavState)
         {
-            requestMaximizedWindowId = requestStates.getMaximizedWindow().getId().toString();
-            WindowState state = requestStates.getPortletWindowNavigationalState(requestMaximizedWindowId).getWindowState();
-            transientNavState = JetspeedActions.SOLO_STATE.equals(state);
+            // Check if a maximized window is set in the request.
+            // This can mean a window with state MAXIMIZED *or* SOLO.
+            // With a SOLO state, also skip all synchroniziations!
+            String requestMaximizedWindowId = null;
             
-            if (!transientNavState)
+            if ( requestStates.getMaximizedWindow() != null )
             {
-                // check if request parameter nav-state=transient is provided
-                String navState = context.getRequestParameter(PortalReservedParameters.NAV_STATE);
-                transientNavState = (navState != null && PortalReservedParameters.TRANSIENT_NAV_STATE.equals(navState));
+                requestMaximizedWindowId = requestStates.getMaximizedWindow().getId().toString();
+                WindowState state = requestStates.getPortletWindowNavigationalState(requestMaximizedWindowId).getWindowState();
+                transientNavState = JetspeedActions.SOLO_STATE.equals(state);
+                clearCacheWindowId = requestMaximizedWindowId;
             }
+            
         }
-        
         if (transientNavState)
         {
-            // skip *any* navState synchronizations
-            HttpSession session = context.getRequest().getSession();
-            if ( session != null )
+            // no navState synchronizations
+            
+            if (clearCacheWindowId != null)
             {
-                PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates)session.getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
-                if ( sessionStates != null )
+                HttpSession session = context.getRequest().getSession();
+                if ( session != null )
                 {
-                    sessionStates.removeFromCache(context, requestMaximizedWindowId, cache);
+                    PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates)session.getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
+                    if ( sessionStates != null )
+                    {
+                        sessionStates.removeFromCache(context, clearCacheWindowId, cache);
+                    }
                 }
             }
         }

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/BufferedHttpServletResponse.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/BufferedHttpServletResponse.java?view=auto&rev=544024
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/BufferedHttpServletResponse.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/BufferedHttpServletResponse.java
Sun Jun  3 17:59:09 2007
@@ -0,0 +1,591 @@
+/*
+ * 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.resource;
+
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map.Entry;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+/**
+ * <p>
+ * BufferedHttpServletResponse fully captures all HttpServletResponse interactions to be
flushed out later.
+ * This wrapper is specifically written to allow included servlets to set headers, cookies,
encoding etc. which isn't allowed by
+ * the servlet specification on included responses.
+ * </p>
+ * <p>
+ * Call flush(HttpServletResponse) after the include has returned to flush out the buffered
data, headers and state.
+ * </p>
+ * <p>
+ * Note: the only method not fully supported by this buffered version is getCharacterEncoding().
Setting characterEncoding through
+ * setContentType or setLocale on this class won't be reflected in the return value from
getCharacterEncoding(), and calling getWriter()
+ * won't set it either although calling setLocale, setContentType or setCharacterEncoding
(servlet api 2.4+) after that will be ignored.
+ * But, when this object is flused to a (real) response, the contentType, locale and/or characterEncoding
recorded will be set on the
+ * target response then.
+ * </p>
+ * 
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ */
+public class BufferedHttpServletResponse extends HttpServletResponseWrapper
+{
+    private static class CharArrayWriterBuffer extends CharArrayWriter
+    {
+        public char[] getBuffer()
+        {
+            return buf;
+        }
+        
+        public int getCount()
+        {
+            return count;
+        }
+    }
+    
+    private ByteArrayOutputStream byteOutputBuffer;
+    private CharArrayWriterBuffer charOutputBuffer;
+    private ServletOutputStream outputStream;
+    private PrintWriter printWriter;
+    private HashMap headers;
+    private ArrayList cookies;
+    private int errorCode;
+    private int statusCode;
+    private String errorMessage;
+    private String redirectLocation;
+    private boolean committed;
+    private boolean hasStatus;
+    private boolean hasError;
+    private Locale locale;
+    private boolean closed;
+    private String characterEncoding;
+    private int contentLength = -1;
+    private String contentType;
+    private boolean flushed;
+    
+    public BufferedHttpServletResponse(HttpServletResponse response)
+    {
+        super(response);
+    }
+    
+    public void flush(HttpServletResponse response) throws IOException
+    {
+        if (flushed)
+        {
+            throw new IllegalStateException("Already flushed");            
+        }
+        flushed = true;
+        
+        if (locale != null)
+        {
+            response.setLocale(locale);
+        }        
+        if (contentType != null)
+        {
+            response.setContentType(contentType);
+        }
+        if (characterEncoding != null)
+        {
+            // setCharacterEncoding only available on Servlet Spec 2.4+
+            try
+            {
+                response.getClass().getMethod("setCharacterEncoding", new Class[]{String.class}).invoke(response,
new Object[]{characterEncoding});
+            }
+            catch (NoSuchMethodException nsme)
+            {
+                // servlet spec 2.3
+            }
+            catch (Exception e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+        if (cookies != null)
+        {
+            for (int i=0,size=cookies.size(); i<size; i++)
+            {
+                response.addCookie((Cookie)cookies.get(i));
+            }
+            cookies = null;
+        }
+        if (headers != null)
+        {
+            Iterator iter = headers.entrySet().iterator();
+            while (iter.hasNext())
+            {
+                Entry e = (Entry)iter.next();
+                String name = (String)e.getKey();
+                ArrayList values = (ArrayList)e.getValue();
+                for (int i=0, size=values.size(); i < size; i++ )
+                {
+                    Object value = values.get(i);
+                    if (value instanceof Integer)
+                    {
+                        response.addIntHeader(name, ((Integer)value).intValue());
+                    }
+                    else if (value instanceof Long)
+                    {
+                        response.addDateHeader(name, ((Long)value).longValue());
+                    }
+                    else
+                    {
+                        response.addHeader(name, (String)value);
+                    }
+                }
+            }
+            headers = null;
+        }
+        if (contentLength > -1)
+        {
+            response.setContentLength(contentLength);
+        }
+        if (hasStatus)
+        {
+            response.setStatus(statusCode);
+        }
+        if (hasError)
+        {
+            response.sendError(errorCode, errorMessage);            
+        }
+        else if (redirectLocation != null)
+        {
+            response.sendRedirect(redirectLocation);
+        }
+        else
+        {
+            if (outputStream != null)
+            {
+                if (!closed)
+                {
+                    outputStream.flush();
+                }
+                ServletOutputStream realOutputStream = response.getOutputStream();
+                int len = byteOutputBuffer.size();
+                if (contentLength > -1 && contentLength < len)
+                {
+                    len = contentLength;
+                }
+                if (len > 0)
+                {
+                    realOutputStream.write(byteOutputBuffer.toByteArray(), 0, len);
+                }
+                outputStream.close();
+                outputStream = null;
+                byteOutputBuffer = null;
+            }
+            else if (printWriter != null)
+            {
+                if (!closed)
+                {
+                    printWriter.flush();
+                    if ( charOutputBuffer.getCount() > 0)
+                    {
+                        response.getWriter().write(charOutputBuffer.getBuffer(), 0, charOutputBuffer.getCount());
+                    }
+                    printWriter.close();
+                    
+                    printWriter = null;
+                    charOutputBuffer = null;
+                }
+            }
+            
+        }
+    }
+    
+    private ArrayList getHeaderList(String name, boolean create)
+    {
+        if ( headers == null )
+        {
+            headers = new HashMap();
+        }
+        ArrayList headerList = (ArrayList)headers.get(name);
+        if ( headerList == null && create )
+        {
+            headerList = new ArrayList();
+            headers.put(name,headerList);
+        }
+        return headerList;
+    }
+    
+    private void failIfCommitted()
+    {
+        if (committed)
+        {
+            throw new IllegalStateException("Response is already committed");
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#addCookie(javax.servlet.http.Cookie)
+     */
+    public void addCookie(Cookie cookie)
+    {
+        if ( !committed )
+        {
+            if ( cookies == null )
+            {
+                cookies = new ArrayList();
+            }
+            cookies.add(cookie);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#addDateHeader(java.lang.String,
long)
+     */
+    public void addDateHeader(String name, long date)
+    {
+        if (!committed)
+        {
+            ArrayList headerList = getHeaderList(name, true);
+            headerList.add(new Long(date));
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#addHeader(java.lang.String, java.lang.String)
+     */
+    public void addHeader(String name, String value)
+    {
+        if (!committed)
+        {
+            ArrayList headerList = getHeaderList(name, true);
+            headerList.add(value);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#addIntHeader(java.lang.String,
int)
+     */
+    public void addIntHeader(String name, int value)
+    {
+        if (!committed)
+        {
+            ArrayList headerList = getHeaderList(name, true);
+            headerList.add(new Integer(value));
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#containsHeader(java.lang.String)
+     */
+    public boolean containsHeader(String name)
+    {
+        return getHeaderList(name, false) != null;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#sendError(int, java.lang.String)
+     */
+    public void sendError(int errorCode, String errorMessage) throws IOException
+    {
+        failIfCommitted();
+        committed = true;
+        closed = true;
+        hasError = true;
+        this.errorCode = errorCode;
+        this.errorMessage = errorMessage;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#sendError(int)
+     */
+    public void sendError(int errorCode) throws IOException
+    {
+        sendError(errorCode, null);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#sendRedirect(java.lang.String)
+     */
+    public void sendRedirect(String redirectLocation) throws IOException
+    {
+        failIfCommitted();
+        closed = true;
+        committed = true;
+        this.redirectLocation = redirectLocation;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#setDateHeader(java.lang.String,
long)
+     */
+    public void setDateHeader(String name, long date)
+    {
+        if (!committed)
+        {
+            ArrayList headerList = getHeaderList(name, true);
+            headerList.clear();
+            headerList.add(new Long(date));
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#setHeader(java.lang.String, java.lang.String)
+     */
+    public void setHeader(String name, String value)
+    {
+        if (!committed)
+        {
+            ArrayList headerList = getHeaderList(name, true);
+            headerList.clear();
+            headerList.add(value);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#setIntHeader(java.lang.String,
int)
+     */
+    public void setIntHeader(String name, int value)
+    {
+        if (!committed)
+        {
+            ArrayList headerList = getHeaderList(name, true);
+            headerList.clear();
+            headerList.add(new Integer(value));
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#setStatus(int, java.lang.String)
+     */
+    public void setStatus(int statusCode, String message)
+    {
+        throw new UnsupportedOperationException("This method is deprecated and no longer
available");
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.http.HttpServletResponseWrapper#setStatus(int)
+     */
+    public void setStatus(int statusCode)
+    {
+        if (!committed)
+        {
+            this.statusCode = statusCode;
+            this.hasStatus = true;
+            resetBuffer();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#flushBuffer()
+     */
+    public void flushBuffer() throws IOException
+    {
+        if (!closed)
+        {
+            committed = true;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#getBufferSize()
+     */
+    public int getBufferSize()
+    {
+        return Integer.MAX_VALUE;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#getCharacterEncoding()
+     */
+    public String getCharacterEncoding()
+    {
+        return characterEncoding != null ? characterEncoding : "ISO-8859-1";
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#getLocale()
+     */
+    public Locale getLocale()
+    {
+        return locale != null ? locale : super.getLocale();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#getOutputStream()
+     */
+    public ServletOutputStream getOutputStream() throws IOException
+    {
+        if (outputStream == null)
+        {
+            if (printWriter != null)
+            {
+                throw new IllegalStateException("getWriter() has already been called on this
response");
+            }
+            byteOutputBuffer = new ByteArrayOutputStream();
+            outputStream = new ServletOutputStream()
+            {
+                public void write(int b) throws IOException
+                {
+                    if (!closed)
+                    {
+                        byteOutputBuffer.write(b);
+                        if (contentLength>-1 && byteOutputBuffer.size()>=contentLength)
+                        {
+                            committed = true;
+                            closed = true;
+                        }
+                    }
+                }
+            };
+        }
+        return outputStream;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#getWriter()
+     */
+    public PrintWriter getWriter() throws IOException
+    {
+        if (printWriter == null)
+        {
+            if (outputStream != null)
+            {
+                throw new IllegalStateException("getOutputStream() has already been called
on this response");
+            }
+            charOutputBuffer = new CharArrayWriterBuffer();
+            printWriter = new PrintWriter(charOutputBuffer);
+        }
+        return printWriter;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#isCommitted()
+     */
+    public boolean isCommitted()
+    {
+        return committed;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#reset()
+     */
+    public void reset()
+    {
+        resetBuffer(); // fails if committed
+        headers = null;
+        cookies = null;
+        hasStatus = false;
+        contentLength = -1;
+        if (printWriter == null)
+        {
+            contentType = null;
+            characterEncoding = null;
+            locale = null;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#resetBuffer()
+     */
+    public void resetBuffer()
+    {
+        failIfCommitted();
+        if (outputStream != null)
+        {
+            try { outputStream.flush(); } catch (Exception e){}
+            byteOutputBuffer.reset();
+        }
+        else if (printWriter != null)
+        {
+            printWriter.flush();
+            charOutputBuffer.reset();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#setBufferSize(int)
+     */
+    public void setBufferSize(int size)
+    {
+        failIfCommitted();
+        if ( (charOutputBuffer != null && charOutputBuffer.size() > 0)
+                || (byteOutputBuffer != null && byteOutputBuffer.size() > 0) )
+        {
+            throw new IllegalStateException("Content has already been written");
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#setCharacterEncoding(java.lang.String)
+     */
+    public void setCharacterEncoding(String charset)
+    {
+        if (charset != null && !committed && printWriter == null)
+        {
+            characterEncoding = charset;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#setContentLength(int)
+     */
+    public void setContentLength(int len)
+    {
+        if (!committed && printWriter == null && len > 0)
+        {
+            contentLength = len;
+            if (outputStream != null)
+            {
+                try { outputStream.flush(); } catch (Exception e){}
+            }
+            if ( !closed && byteOutputBuffer != null && byteOutputBuffer.size()
>= len )
+            {
+                committed = true;
+                closed = true;
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#setContentType(java.lang.String)
+     */
+    public void setContentType(String type)
+    {
+        if (!committed)
+        {
+            contentType = type;
+            if (printWriter == null)
+            {
+                // TODO: parse possible encoding for better return value from getCharacterEncoding()
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see javax.servlet.ServletResponseWrapper#setLocale(java.util.Locale)
+     */
+    public void setLocale(Locale locale)
+    {
+        if (!committed)
+        {
+            this.locale = locale;
+            /* NON-FIXABLE ISSUE: defaulting the characterEncoding from the Locale
+               This feature cannot be implemented/wrapped as it might depend on web.xml locale
settings
+             */
+        }
+    }
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/BufferedHttpServletResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/BufferedHttpServletResponse.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/ResourceValveImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/ResourceValveImpl.java?view=auto&rev=544024
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/ResourceValveImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/ResourceValveImpl.java
Sun Jun  3 17:59:09 2007
@@ -0,0 +1,138 @@
+/*
+ * 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.resource;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import javax.portlet.PortletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.container.window.PortletWindowAccessor;
+import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
+import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.om.page.ContentFragmentImpl;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.pipeline.PipelineException;
+import org.apache.jetspeed.pipeline.valve.AbstractValve;
+import org.apache.jetspeed.pipeline.valve.ValveContext;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * <p>
+ * ResourceValveImpl
+ * </p>
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ *
+ */
+public class ResourceValveImpl extends AbstractValve
+{
+
+    private static final Log log = LogFactory.getLog(ResourceValveImpl.class);
+    private PortletContainer container;
+    private PortletWindowAccessor windowAccessor;
+
+    public ResourceValveImpl(PortletContainer container, PortletWindowAccessor windowAccessor)
+    {
+        this.container = container;
+        this.windowAccessor = windowAccessor;
+    }
+    
+    /**
+     * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext,
org.apache.jetspeed.pipeline.valve.ValveContext)
+     */
+    public void invoke(RequestContext request, ValveContext context) throws PipelineException
+    {     
+        PortletWindow resourceWindow = request.getPortalURL().getNavigationalState().getPortletWindowOfResource();
+        
+        if ( resourceWindow != null )
+        {
+            try
+            {            
+                Page page = request.getPage();
+                Fragment fragment = page.getFragmentById(resourceWindow.getId().toString());
+                // If portlet entity is null, try to refresh the resourceWindow.
+                // Under some clustered environments, a cached portlet window could have
null entity.
+                if (null == resourceWindow.getPortletEntity())
+                {
+                    try 
+                    {
+                        ContentFragment contentFragment = new ContentFragmentImpl(fragment,
new HashMap());
+                        resourceWindow = this.windowAccessor.getPortletWindow(contentFragment);
+                    } 
+                    catch (Exception e)
+                    {
+                        log.error("Failed to refresh resource window.", e);
+                    }
+                }
+                ((MutablePortletEntity)resourceWindow.getPortletEntity()).setFragment(fragment);
+                HttpServletResponse response = request.getResponse();
+                HttpServletRequest requestForWindow = request.getRequestForWindow(resourceWindow);
+                requestForWindow.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE,
request);
+                requestForWindow.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE, request.getPage());
+                requestForWindow.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE,
fragment);
+                request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_OBJECTS, request.getObjects());
                       
+                request.setAttribute(PortalReservedParameters.PATH_ATTRIBUTE, request.getAttribute(PortalReservedParameters.PATH_ATTRIBUTE));
+                request.setAttribute(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE, resourceWindow);
+                BufferedHttpServletResponse bufferedResponse = new BufferedHttpServletResponse(response);
+                container.renderPortlet(resourceWindow, requestForWindow, bufferedResponse);
+                bufferedResponse.flush(response);
+            }
+            catch (PortletContainerException e)
+            {
+                log.fatal("Unable to retrieve portlet container!", e);
+                throw new PipelineException("Unable to retrieve portlet container!", e);
+            }
+            catch (PortletException e)
+            {
+                log.warn("Unexpected PortletException", e);
+
+            }
+            catch (IOException e)
+            {
+                log.error("Unexpected IOException", e);
+            }
+            catch (IllegalStateException e)
+            {
+                log.error("Unexpected IllegalStateException.", e);
+            }
+            catch (Exception t)
+            {
+                log.error("Unexpected Exception", t);
+            }
+        }
+        else
+        {
+            // Pass control to the next Valve in the Pipeline
+            context.invokeNext(request);
+        }
+    }
+
+    public String toString()
+    {
+        return "ResourceValveImpl";
+    }
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/ResourceValveImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/resource/ResourceValveImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/PortalReservedParameters.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/PortalReservedParameters.java?view=diff&rev=544024&r1=544023&r2=544024
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/PortalReservedParameters.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/PortalReservedParameters.java
Sun Jun  3 17:59:09 2007
@@ -131,4 +131,14 @@
      *  </p>
      */
      public static final String PORTLET_EXTENDED_DESCRIPTOR_MERGE_PORTAL_PARAMETERS_BEFORE_PORTLET_PARAMETERS
= "merge.portal.parameters.before.portlet.parameters";
+     
+     /**
+      * Preliminary Portlet API 2.0 ResourceURL support.
+      * By setting the RenderURL parameter PORTLET_RESOURCE_URL_REQUEST_PARAMETER (with whatever
value) the Jetspeed encoded PortletURL
+      * will be marked as a ResourceURL (the parameter itself will not be stored).
+      * By invoking such a Render/ResourceURL, NavigationalState.getPortletWindowOfResource()
will be set, and with an custom Valve 
+      * (example implementation o.a.j.resource.ResourceValveImpl) this PortletWindow can
be invoked directly,
+      * similar as an ActionURL but as a direct Portlet Render request.
+      */
+     public static final String PORTLET_RESOURCE_URL_REQUEST_PARAMETER = "org.apache.jetspeed.portlet.resource.url";
 }

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/container/state/NavigationalState.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/container/state/NavigationalState.java?view=diff&rev=544024&r1=544023&r2=544024
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/container/state/NavigationalState.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/container/state/NavigationalState.java
Sun Jun  3 17:59:09 2007
@@ -140,6 +140,7 @@
 
     PortletWindow getPortletWindowOfAction();
     
+    PortletWindow getPortletWindowOfResource();
     /**
      * Returns an iterator of Portlet Window ids of all the Portlet Windows 
      * within the NavigationalState.

Modified: portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/pipelines.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/pipelines.xml?view=diff&rev=544024&r1=544023&r2=544024
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/pipelines.xml (original)
+++ portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/pipelines.xml Sun Jun  3 17:59:09
2007
@@ -280,6 +280,17 @@
     </constructor-arg>      
   </bean>
       
+  <bean id="resourceValve"
+        class="org.apache.jetspeed.resource.ResourceValveImpl"
+        init-method="initialize">
+    <constructor-arg>
+      <ref bean="org.apache.pluto.PortletContainer" />
+    </constructor-arg>
+    <constructor-arg>   
+      <ref bean="PortletWindowAccessor" />    
+    </constructor-arg>
+  </bean> 
+    
   <bean id="jetspeed-pipeline"
         class="org.apache.jetspeed.pipeline.JetspeedPipeline"
         init-method="initialize"
@@ -298,6 +309,7 @@
       <ref bean="profilerValve"/>
       <ref bean="containerValve"/>
       <ref bean="actionValve"/>
+      <ref bean="resourceValve"/>
       <ref bean="DecorationValve" />
       <ref bean="headerAggregatorValvePortal"/>  
       <ref bean="aggregatorValve"/>



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


Mime
View raw message