Update of 
/var/cvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/cmsc/portalImpl
In directory 
james.mmbase.org:/tmp/cvs-serv3785/cmsc/portal/src/java/com/finalist/cmsc/portalImpl

Modified Files:
        PortalErrorServlet.java PortalServlet.java 
Log Message:
CMSC-938 Make inline editors work for demo sites
Foxed some erro pager conditions


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/cmsc/portalImpl
See also: http://www.mmbase.org/jira/browse/CMSC-938


Index: PortalErrorServlet.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/cmsc/portalImpl/PortalErrorServlet.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- PortalErrorServlet.java     9 May 2008 10:06:57 -0000       1.15
+++ PortalErrorServlet.java     2 Jun 2008 21:56:34 -0000       1.16
@@ -14,7 +14,8 @@
 import java.util.List;
 import java.util.regex.Pattern;
 
-import javax.servlet.*;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
 import javax.servlet.http.*;
 
 import net.sf.mmapps.commons.util.HttpUtil;
@@ -28,6 +29,32 @@
 import com.finalist.pluto.portalImpl.core.*;
 import com.finalist.util.version.VersionUtil;
 
+/**
+ * Servlet which handles all requests which have an error.
+ * This Servlet is mapped in the web.xml on all <error-page>'s
+ *
+ * This servlet resolves the most appropriate error page for the requested url
+ * - All static resources inside the editors are not processed further
+ * - the requested uri is matched against the sites.
+ * - If a site matches then a child page with the statuscode as urlfragment is 
used as the error page
+ * - No site found then the first site with a page with the statuscode as 
urlfragment is used as the error page
+ * - No child page with the statuscode found then the default error jsp's are 
used
+ * - When the default jsp's are missing then a basic error page is rendered.
+ *
+ *
+ * Rendering a custom error page can result in the following exception
+ * "ClientAbortException: java.net.SocketException: Software caused connection 
abort: socket write error"
+ *
+ * The error is caused by a page referring to a missing image.
+ * The exception stack doesn't involve the actual error page processing. It is 
apparently
+ * due to the browser preemptively aborting on 404. It's reasonable that it 
figures that
+ * on 404, you're not going to return content, and the browser is going to do 
it's own
+ * thing anyway, especially if it starts getting HTML content (our error page)
+ * for an IMG tag.
+ *
+ * We can't distinguish between a request for an image from a referring page 
or a direct image
+ * request. The "Referer" http header is send in both cases.
+ */
 @SuppressWarnings("serial")
 public class PortalErrorServlet extends PortalServlet {
 
@@ -41,19 +68,16 @@
 
    private static final String SIMPLE_404 = 
"(.*/editors/.*[.](jpg$|gif$|png$|css$|js$|ico$))|robots.txt";
    
-   protected ServletConfig config;
    private Pattern excludePattern = Pattern.compile(SIMPLE_404);
    
    protected static final String[] vars = { ERROR_STATUS_CODE, 
ERROR_EXCEPTION_TYPE, 
                                             ERROR_MESSAGE, ERROR_EXCEPTION, 
ERROR_REQUEST_URI };
-
    @Override
-   public void init(ServletConfig config) {
-      // do not start the portal
-      this.config = config;
+   protected void startPortal() {
+      // do not start the portal. We only share the render code for navigation 
items.
    }
 
-
+   @Override
    public void service(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
       log.debug("===>PortalErrorServlet.doGet START!");
       
@@ -79,10 +103,10 @@
               }
           }
           // The incoming request has a servletPath of /PortalError. The 
mapped url to this servlet.
-          // Pretend it is  the uri which has the error in itss
+          // Pretend it is the uri which has the error in it
           HttpServletRequest errorUriRequest = new 
ErrorHttpServletRequest(request, errorUri);
           
-         PortalEnvironment env = new PortalEnvironment(errorUriRequest, 
response, config);
+         PortalEnvironment env = new PortalEnvironment(errorUriRequest, 
response);
          PortalURL currentURL = env.getRequestedPortalURL();
          try {
             String path = extractPath(request, currentURL);
@@ -104,11 +128,10 @@
                   }
                }
             }
-            if (errorPageSite != null) {
                 logError(request); 
-
+            if (errorPageSite != null) {
                 HttpServletRequest errorRequest = new 
ErrorHttpServletRequest(request, errorPageSite.getUrlfragment(), 
String.valueOf(statusCode)); 
-                PortalEnvironment errorEnv = new 
PortalEnvironment(errorRequest, response, config);
+                PortalEnvironment errorEnv = new 
PortalEnvironment(errorRequest, response);
 
                 String errorPagePath = errorPageSite.getUrlfragment() + 
PATH_SP + statusCode;
                 setSiteLocale(request, errorPagePath);
@@ -135,12 +158,11 @@
 
    private void defaultError(HttpServletRequest request, HttpServletResponse 
response, Integer statusCode)
          throws ServletException, IOException {
-      RequestDispatcher rd = 
config.getServletContext().getRequestDispatcher("/error/" + statusCode + 
".jsp");
+      RequestDispatcher rd = 
getServletConfig().getServletContext().getRequestDispatcher("/error/" + 
statusCode + ".jsp");
       if (rd != null) {
          rd.forward(request, response);
       }
       else {
-         logError(request);
          basicErrorPage(request, response);
       }
    }
@@ -161,12 +183,12 @@
 
    public void logError(HttpServletRequest request) {
       Integer statusCode = (Integer) request.getAttribute(ERROR_STATUS_CODE);
-      Throwable exception = (Throwable) request.getAttribute(ERROR_EXCEPTION);
       if (statusCode == 500) {
-         String version = 
VersionUtil.getApplicationVersion(config.getServletContext());
+         String version = 
VersionUtil.getApplicationVersion(getServletConfig().getServletContext());
          // prepare error ticket
          long ticket = System.currentTimeMillis();
 
+         Throwable exception = (Throwable) 
request.getAttribute(ERROR_EXCEPTION);
          String msg = HttpUtil.getErrorInfo(request, exception, ticket, 
version);
 
          String message = "";
@@ -179,6 +201,12 @@
          // write errors to mmbase log
          log.error(ticket + ":\n" + msg);
       }
+      if (statusCode == 404) {
+         if (!ServerUtil.isProduction()) {
+            String path = (String) request.getAttribute(ERROR_REQUEST_URI);
+            log.error("missing resource: " + path);
+         }
+      }
    }
    
    class ErrorHttpServletRequest extends HttpServletRequestWrapper {


Index: PortalServlet.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/portal/src/java/com/finalist/cmsc/portalImpl/PortalServlet.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- PortalServlet.java  10 May 2008 16:31:24 -0000      1.17
+++ PortalServlet.java  2 Jun 2008 21:56:34 -0000       1.18
@@ -10,16 +10,10 @@
 package com.finalist.cmsc.portalImpl;
 
 import java.io.IOException;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.UnavailableException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
@@ -31,16 +25,13 @@
 import com.finalist.cmsc.navigation.*;
 import com.finalist.cmsc.services.ServiceManager;
 import com.finalist.cmsc.services.sitemanagement.SiteManagement;
-import com.finalist.pluto.portalImpl.core.PortalEnvironment;
-import com.finalist.pluto.portalImpl.core.PortalURL;
-import com.finalist.pluto.portalImpl.core.PortletContainerEnvironment;
-import com.finalist.pluto.portalImpl.core.PortletContainerFactory;
+import com.finalist.pluto.portalImpl.core.*;
 import com.finalist.pluto.portalImpl.factory.FactoryAccess;
 import com.finalist.pluto.portalImpl.services.factorymanager.FactoryManager;
 import com.finalist.pluto.portalImpl.services.log.CommonsLogging;
 
 /**
- * Portal controller servlet. Alle portal requests gaan door deze servlet.
+ * Portal controller servlet. All portal requests go through this servlet.
  * 
  * @author Wouter Heijke
  */
@@ -50,25 +41,30 @@
    private static Log log = LogFactory.getLog(PortalServlet.class);
 
    protected static final String PATH_SP = "/";
-   protected static ServletConfig sc;
 
+   @Override
    public String getServletInfo() {
       return "CMSC Portal Driver";
    }
 
 
+   @Override
    public void init(ServletConfig config) throws ServletException {
       super.init(config);
+      startPortal();
+   }
+
 
+   protected void startPortal() throws UnavailableException {
       // [FP] register the navigation item managers, this should be done by the
       // modules in the future
       NavigationManager.registerNavigationManager(new 
SiteNavigationItemManager());
       NavigationManager.registerNavigationManager(new 
PageNavigationItemManager());
 
-      PortalServlet.sc = getServletConfig();
+      ServletConfig sc = getServletConfig();
 
       try {
-         ServiceManager.init(config);
+         ServiceManager.init(sc);
       }
       catch (Throwable exc) {
          log.error("Initialization failed!", exc);
@@ -76,7 +72,7 @@
       }
 
       try {
-         ServiceManager.postInit(config);
+         ServiceManager.postInit(sc);
       }
       catch (Throwable expos) {
          log.error("Post initialization failed!", expos);
@@ -97,7 +93,7 @@
          Properties properties = new Properties();
          properties.put("portletcontainer.supportsBuffering", Boolean.FALSE);
          try {
-            
PortletContainerFactory.getPortletContainer().init(uniqueContainerName, config, 
environment, properties);
+            
PortletContainerFactory.getPortletContainer().init(uniqueContainerName, sc, 
environment, properties);
          }
          catch (PortletContainerException exc) {
             log.error("Initialization of the portlet container failed!", exc);
@@ -112,6 +108,7 @@
    }
 
 
+   @Override
    public void destroy() {
       log.info("Shutting down portlet container. . .");
 
@@ -127,6 +124,7 @@
    }
 
 
+   @Override
    public void service(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
       log.debug("===>PortalServlet.doGet START!");
       log.debug("===>REQ spth='" + request.getServletPath() + "'");
@@ -198,7 +196,7 @@
             }
             response.setContentType(contentType);
             
-            manager.render(item, request, response, sc);
+            manager.render(item, request, response, getServletConfig());
             return true;
         }
      }
@@ -206,11 +204,13 @@
    }
 
 
+   @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
       service(request, response);
    }
 
 
+   @Override
    public void doPost(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
       service(request, response);
    }
@@ -226,7 +226,7 @@
 
 
    public static boolean isNavigation(HttpServletRequest request, 
HttpServletResponse response) {
-      PortalEnvironment env = new PortalEnvironment(request, response, sc);
+      PortalEnvironment env = new PortalEnvironment(request, response);
       PortalURL currentURL = env.getRequestedPortalURL();
       String path = extractPath(request, currentURL);
       if (path == null) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to