You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/01/10 15:05:39 UTC

svn commit: r367608 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/ tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/

Author: weber
Date: Tue Jan 10 06:04:34 2006
New Revision: 367608

URL: http://svn.apache.org/viewcvs?rev=367608&view=rev
Log:
Error handling in Ajax. (session timeout on ajax requests)

Modified:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago.properties.xml
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago_de.properties.xml

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java?rev=367608&r1=367607&r2=367608&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java Tue Jan 10 06:04:34 2006
@@ -17,6 +17,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.context.ResourceManagerUtil;
 
 import javax.faces.FactoryFinder;
 import javax.faces.application.StateManager;
@@ -114,29 +115,7 @@
 
         AjaxUtils.processAjax(facesContext, viewRoot);
 
-        StringBuffer buf = new StringBuffer(content.toString());
-
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Size of AjaxResponse:\n" + buf.length());
-        }
-
-        buf.insert(0,Integer.toHexString(buf.length())+"\r\n");
-        buf.append("\r\n"+0+"\r\n\r\n");
-
-        //todo: fix this to work in PortletRequest as well
-        if(externalContext.getResponse() instanceof HttpServletResponse)
-        {
-          final HttpServletResponse httpServletResponse
-              = (HttpServletResponse) externalContext.getResponse();
-          httpServletResponse.addHeader("Transfer-Encoding", "chunked");
-          PrintWriter responseWriter = httpServletResponse.getWriter();
-          // buf.delete(buf.indexOf("<"), buf.indexOf(">")+1);
-          responseWriter.print(buf.toString());
-          //System.out.println("PhaseListener: buf = " + buf.toString());
-          responseWriter.flush();
-          responseWriter.close();
-        }
+        writeAjaxResponse(facesContext, content.toString());
 
         final StateManager stateManager
             = facesContext.getApplication().getStateManager();
@@ -151,6 +130,34 @@
     }
   }
 
+  private void writeAjaxResponse(FacesContext facesContext, String content)
+      throws IOException {
+
+    ExternalContext externalContext = facesContext.getExternalContext();
+    StringBuffer buf = new StringBuffer(content.toString());
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Size of AjaxResponse:\n" + buf.length());
+    }
+
+    buf.insert(0,Integer.toHexString(buf.length())+"\r\n");
+    buf.append("\r\n"+0+"\r\n\r\n");
+
+    //todo: fix this to work in PortletRequest as well
+    if(externalContext.getResponse() instanceof HttpServletResponse)
+    {
+      final HttpServletResponse httpServletResponse
+          = (HttpServletResponse) externalContext.getResponse();
+      httpServletResponse.addHeader("Transfer-Encoding", "chunked");
+      PrintWriter responseWriter = httpServletResponse.getWriter();
+      // buf.delete(buf.indexOf("<"), buf.indexOf(">")+1);
+      responseWriter.print(buf.toString());
+      //System.out.println("PhaseListener: buf = " + buf.toString());
+      responseWriter.flush();
+      responseWriter.close();
+    }
+  }
+
 //  public void afterPhaseOld(PhaseEvent event)
 //  {
 //    FacesContext facesContext = event.getFacesContext();
@@ -228,13 +235,23 @@
       return;
     }
 
-    FacesContext facesContext = event.getFacesContext();
-    final ExternalContext externalContext = facesContext.getExternalContext();
-    final Map requestParameterMap = externalContext.getRequestParameterMap();
-    if(requestParameterMap.containsKey(AJAX_COMPONENT_ID)) {
-      // TODO: error handling when ajax request came after session has expired
-      LOG.error("Ignoring AjaxRequest without valid component tree!");
-      facesContext.responseComplete();
+    try {
+      FacesContext facesContext = event.getFacesContext();
+      final ExternalContext externalContext = facesContext.getExternalContext();
+      final Map requestParameterMap = externalContext.getRequestParameterMap();
+      if(requestParameterMap.containsKey(AJAX_COMPONENT_ID)) {
+        LOG.error("Ignoring AjaxRequest without valid component tree!");
+
+        final String message = ResourceManagerUtil.getPropertyNotNull(
+            facesContext, "tobago", "tobago.ajax.response.error");
+
+        writeAjaxResponse(facesContext, message);
+
+        facesContext.responseComplete();
+      }
+
+    } catch (IOException e) {
+      LOG.error("Exception while processing Ajax", e);
     }
   }
 

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago.properties.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago.properties.xml?rev=367608&r1=367607&r2=367608&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago.properties.xml (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago.properties.xml Tue Jan 10 06:04:34 2006
@@ -95,4 +95,6 @@
 <entry key="javax.faces.validator.LengthValidator.MINIMUM">Minimum of "{0}" characters !</entry>
 <entry key="javax.faces.validator.LengthValidator.MINIMUM_detail">Value is shorter than allowable minimum of "{0}" characters!</entry>
 
+  <entry key="tobago.ajax.response.error">Server Error: unable to serve request. Probably a session timeout!</entry>
+
 </properties>

Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago_de.properties.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago_de.properties.xml?rev=367608&r1=367607&r2=367608&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago_de.properties.xml (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago_de.properties.xml Tue Jan 10 06:04:34 2006
@@ -98,4 +98,6 @@
 <entry key="javax.faces.validator.LengthValidator.MINIMUM">Minimal "{0}" Zeichen erlaubt!</entry>
 <entry key="javax.faces.validator.LengthValidator.MINIMUM_detail">Der eingegebene Wert ist kürzer als das zulässige Minimum von {0} Zeichen!</entry>
 
+  <entry key="tobago.ajax.response.error">Server Error: Fehler beim Bearbeiten der Anfrage. Möglicherweise ein Session Timeout!</entry>
+
 </properties>