You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by dl...@apache.org on 2006/11/28 19:16:09 UTC

svn commit: r480146 - in /portals/wsrp4j/trunk/consumer-proxyportlet/src: java/org/apache/wsrp4j/consumer/proxyportlet/impl/ java/org/apache/wsrp4j/consumer/proxyportlet/util/ webapp/jsp/proxyportlet/

Author: dlouzan
Date: Tue Nov 28 10:16:08 2006
New Revision: 480146

URL: http://svn.apache.org/viewvc?view=rev&rev=480146
Log:
- Added support for viewing the exceptions on the portal when they happen on render() and processAction() calls
- Modified the way UserSessionImpl generates the handle of the map stored on the PortletSession

Modified:
    portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/ProxyPortlet.java
    portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/UserSessionImpl.java
    portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/util/Constants.java
    portals/wsrp4j/trunk/consumer-proxyportlet/src/webapp/jsp/proxyportlet/errorPage.jsp

Modified: portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/ProxyPortlet.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/ProxyPortlet.java?view=diff&rev=480146&r1=480145&r2=480146
==============================================================================
--- portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/ProxyPortlet.java (original)
+++ portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/ProxyPortlet.java Tue Nov 28 10:16:08 2006
@@ -58,6 +58,7 @@
  *******************************************************************************
  ******************************************************************************/
 
+import org.apache.wsrp4j.commons.util.PortletUtils;
 
 import org.apache.wsrp4j.commons.consumer.interfaces.consumer.
         ConsumerEnvironment;
@@ -99,6 +100,8 @@
 import org.apache.wsrp4j.commons.util.WindowStates;
 import org.apache.wsrp4j.commons.util.configuration.ConfigurationParametersManager;
 
+import org.apache.wsrp4j.consumer.proxyportlet.util.Constants;
+
 /**
  * JSR 168 portlet which acts as proxy (consumer) to WSRP portlets.
  *
@@ -358,7 +361,8 @@
             }
             
         } catch (WSRPException e) {
-            throw new PortletException(e);
+            handleProcessActionException(request, actionResponse, e);
+            log.error(e);
         } finally {
             if (log.isDebugEnabled()) {
                 log.debug(Utility.strExit(MN));
@@ -391,6 +395,16 @@
             log.debug(Utility.strEnter(MN));
         }
         
+        /**
+         * Check if we come from a previous call and there was an exception
+         */
+        String actionParam = request.getParameter(Constants.PROXYPORTLET_PARAM_ACTION);
+        String action = (actionParam == null) ? new String() : actionParam;
+        if (action.equals(Constants.PROXYPORTLET_ACTION_EXCEPTION)) {
+            PortletUtils.delegateToJSP(request, renderResponse,
+                    getPortletContext(), "/jsp/proxyportlet/errorPage.jsp");
+        }
+        
         try {
             // set content type in response
             renderResponse.setContentType(request.getResponseContentType());
@@ -466,9 +480,8 @@
             }
             
         } catch (WSRPException e) {
-            log.error("Error occured while retrieving markup", e);
-            request.setAttribute(ATTR_WSRP_EXCEPTION, e);
-            delegateToJSP(request, renderResponse, ERROR_PAGE);
+            handleRenderException(request, renderResponse, e);
+            log.error(e);
         }
 
         if (log.isDebugEnabled()) {
@@ -543,7 +556,7 @@
         if (userSession != null) {
             // get the group session
             String groupID = getPortletDescription(portlet).getGroupID();
-            groupID = groupID == null ? "default" : groupID;
+            groupID = groupID == null ? Constants.PROXYPORTLET_DEFAULT_GROUP_ID : groupID;
             
             GroupSession groupSession = userSession.getGroupSession(groupID);
             if (groupSession != null) {
@@ -791,15 +804,21 @@
         return consumerEnv;
     }
     
-    private void delegateToJSP(RenderRequest request, RenderResponse response, 
-            String jspPage)
+    private void handleRenderException(RenderRequest request, 
+            RenderResponse response, WSRPException e)
     throws PortletException, IOException {
-        
-        PortletContext portletContext = getPortletContext();
-        PortletRequestDispatcher requestDispatcher = 
-                portletContext.getRequestDispatcher(jspPage);
-        requestDispatcher.include(request, response);
-        
+        request.setAttribute(Constants.PROXYPORTLET_ATTR_EXCEPTION, 
+                e.toHTMLString());
+        PortletUtils.delegateToJSP(request, response, 
+                getPortletContext(), "/jsp/proxyportlet/errorPage.jsp");
+    }
+    
+    private void handleProcessActionException(ActionRequest request, 
+            ActionResponse response, WSRPException e) {
+        response.setRenderParameter(Constants.PROXYPORTLET_PARAM_ACTION, 
+                Constants.PROXYPORTLET_ACTION_EXCEPTION);
+        response.setRenderParameter(Constants.PROXYPORTLET_PARAM_EXCEPTION, 
+                e.toHTMLString());
     }
     
 }

Modified: portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/UserSessionImpl.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/UserSessionImpl.java?view=diff&rev=480146&r1=480145&r2=480146
==============================================================================
--- portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/UserSessionImpl.java (original)
+++ portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/UserSessionImpl.java Tue Nov 28 10:16:08 2006
@@ -21,11 +21,14 @@
 import javax.portlet.PortletSession;
 
 import oasis.names.tc.wsrp.v1.intf.WSRP_v1_Markup_PortType;
+
 import org.apache.wsrp4j.commons.consumer.interfaces.session.GroupSessionMgr;
 import org.apache.wsrp4j.commons.consumer.driver.session.GenericUserSessionImpl;
 import org.apache.wsrp4j.commons.consumer.util.ConsumerConstants;
 import org.apache.wsrp4j.commons.exception.WSRPException;
 
+import org.apache.wsrp4j.consumer.proxyportlet.util.Constants;
+
 /**
  * @version $Id$
  */
@@ -160,8 +163,14 @@
         return myMap;
     }
 
+    /**
+     * The userSession map is stored with a key of the form 
+     * <code>PROXYPORTLET_PREFIX.user:${user}-producer:${producer}</code>
+     */
     private String createKey() {
-        return "user :" + this.getUserID() + " producer:" + this.getProducerID();
+        return Constants.PROXYPORTLET_PREFIX + "." +
+                "user:" + this.getUserID() + 
+                "-producer:" + this.getProducerID();
     }
     
 }

Modified: portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/util/Constants.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/util/Constants.java?view=diff&rev=480146&r1=480145&r2=480146
==============================================================================
--- portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/util/Constants.java (original)
+++ portals/wsrp4j/trunk/consumer-proxyportlet/src/java/org/apache/wsrp4j/consumer/proxyportlet/util/Constants.java Tue Nov 28 10:16:08 2006
@@ -22,6 +22,27 @@
      * Configuration parameter for the class that implements the ProxyPortlet
      * controller
      */
-    public final static String PROXYPORTLET_CLASS_NAME = "wsrp4j.proxyportlet.class";
+    public final static String PROXYPORTLET_CLASS_NAME = 
+            "wsrp4j.proxyportlet.class";
+    
+    /**
+     * String used to prefix the parameters stored on the PortletSession
+     */
+    public final static String PROXYPORTLET_PREFIX = 
+            "org.apache.wsrp4j.consumer.proxyportlet";
+    
+    /**
+     * Default groupId for when the portlet doesn't specify one
+     */
+    public final static String PROXYPORTLET_DEFAULT_GROUP_ID =
+            "default";
+    
+    /**
+     * Parameters needed for showing the exceptions on the portlet
+     */
+    public final static String PROXYPORTLET_ATTR_EXCEPTION = "exception";
+    public final static String PROXYPORTLET_PARAM_ACTION = "action";
+    public final static String PROXYPORTLET_ACTION_EXCEPTION = "exceptionOccured";
+    public final static String PROXYPORTLET_PARAM_EXCEPTION = "exception";
     
 }

Modified: portals/wsrp4j/trunk/consumer-proxyportlet/src/webapp/jsp/proxyportlet/errorPage.jsp
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/consumer-proxyportlet/src/webapp/jsp/proxyportlet/errorPage.jsp?view=diff&rev=480146&r1=480145&r2=480146
==============================================================================
--- portals/wsrp4j/trunk/consumer-proxyportlet/src/webapp/jsp/proxyportlet/errorPage.jsp (original)
+++ portals/wsrp4j/trunk/consumer-proxyportlet/src/webapp/jsp/proxyportlet/errorPage.jsp Tue Nov 28 10:16:08 2006
@@ -20,23 +20,22 @@
 
 <%@page import="org.apache.wsrp4j.commons.exception.WSRPException" %>
 
-<p class="portlet-msg-error">
+<div class="portlet-msg-error">
     <fmt:message key="Error.exceptionThrown"/>
-</p>
+</div>
 
-<%
-String attrName = "org.apache.wsrp4j.proxyportlet.exception";
-WSRPException exception =
-        (WSRPException) request.getAttribute(attrName);
-if (exception != null) {
-%>
-    <%= exception.toHTMLString() %>
-<%
-} else {
-%>
-    <p class="portlet-font">
+<c:choose>
+
+<c:when test="${not empty exception}">
+    <div class="portlet-font">
+        <c:out value="${exception}" escapeXml="false"/>
+    </div>
+</c:when>
+
+<c:otherwise>
+    <div class="portlet-font">
         <fmt:message key="Error.exceptionNotFound"/>
-    </p>
-<%
-}
-%>
\ No newline at end of file
+    </div>
+</c:otherwise>
+    
+</c:choose>