weaver 2004/11/29 11:14:45 Modified: portal/src/java/org/apache/jetspeed/engine JetspeedServlet.java AbstractEngine.java portal/src/java/org/apache/jetspeed/security/impl SecurityValveImpl.java Log: Removed repetitive logging of exceptions and allow exceptions to bubble all the way up to the JetspeedServlet so that they can be reported to the user instead of just getting a blank web page. Revision Changes Path 1.9 +13 -14 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java Index: JetspeedServlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- JetspeedServlet.java 16 Aug 2004 13:27:03 -0000 1.8 +++ JetspeedServlet.java 29 Nov 2004 19:14:44 -0000 1.9 @@ -17,20 +17,18 @@ import java.io.IOException; -import javax.servlet.http.HttpServlet; -import javax.servlet.ServletException; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.lang.exception.ExceptionUtils; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.jetspeed.Jetspeed; import org.apache.jetspeed.engine.servlet.ServletHelper; import org.apache.jetspeed.exception.JetspeedException; @@ -151,11 +149,11 @@ catch (Throwable e) { // save the exception to complain loudly later :-) - initFailure = e; - log.fatal("Jetspeed: init() failed: ", e); - console.fatal("Jetspeed: init() failed: ", e); - System.err.println(ExceptionUtils.getStackTrace(e)); - throw new ServletException("Jetspeed: init() failed", e); + final String msg = "Jetspeed: init() failed: "; + initFailure = e; + log.fatal(msg, e); + console.fatal(msg, e); + } console.info(INIT_DONE_MSG); @@ -205,7 +203,7 @@ // Check to make sure that we started up properly. if (initFailure != null) { - throw initFailure; + throw new ServletException("Failed to initalize jetspeed. "+initFailure.toString(), initFailure); } // If this is the first invocation, perform some late @@ -229,10 +227,11 @@ } } - catch (Throwable t) + catch (JetspeedException e) { - t.printStackTrace(); - //handleException(data, req, res, t); + final String msg = "Fatal error encountered while processing portal request: "+e.toString(); + log.fatal(msg, e); + throw new ServletException(msg, e); } } 1.12 +12 -20 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/AbstractEngine.java Index: AbstractEngine.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/AbstractEngine.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- AbstractEngine.java 11 Nov 2004 19:20:45 -0000 1.11 +++ AbstractEngine.java 29 Nov 2004 19:14:44 -0000 1.12 @@ -221,8 +221,8 @@ public void service( RequestContext context ) throws JetspeedException { // requestContextPerThread.put(Thread.currentThread(), context); - try - { + + if (useInternalJNDI) { // bind the current JNDI context to this service thread. @@ -230,7 +230,14 @@ .getComponent(JNDIComponent.class); if (jndi != null) { - jndi.bindToCurrentThread(); + try + { + jndi.bindToCurrentThread(); + } + catch (NamingException e) + { + throw new JetspeedException("Unable bind jndi: "+e.toString(), e); + } } } String targetPipeline = context @@ -250,22 +257,7 @@ } } pipeline.invoke(context); - } - catch (Throwable t) - { - String msg = "JetspeedEngine unable to service request: " - + t.toString(); - log.error(msg, t); - try - { - // throw new JetspeedException(msg, t); - t.printStackTrace(context.getResponse().getWriter()); - } - catch (IOException e) - { - log.error("Failed to write error to response "+e.toString(), e); - } - } + } /** 1.11 +25 -24 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java Index: SecurityValveImpl.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SecurityValveImpl.java 25 Nov 2004 02:25:58 -0000 1.10 +++ SecurityValveImpl.java 29 Nov 2004 19:14:45 -0000 1.11 @@ -31,6 +31,7 @@ import org.apache.jetspeed.pipeline.valve.ValveContext; import org.apache.jetspeed.profiler.Profiler; import org.apache.jetspeed.request.RequestContext; +import org.apache.jetspeed.security.SecurityException; import org.apache.jetspeed.security.SecurityHelper; import org.apache.jetspeed.security.User; import org.apache.jetspeed.security.UserManager; @@ -38,8 +39,8 @@ /** * SecurityValve - * - * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> + * + * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a> * @version $Id$ */ public class SecurityValveImpl extends AbstractValve implements org.apache.jetspeed.pipeline.valve.SecurityValve @@ -47,20 +48,20 @@ private static final Log log = LogFactory.getLog(SecurityValveImpl.class); private Profiler profiler; private UserManager userMgr; - - public SecurityValveImpl(Profiler profiler, UserManager userMgr) + + public SecurityValveImpl( Profiler profiler, UserManager userMgr ) { this.profiler = profiler; this.userMgr = userMgr; } /** - * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext) + * @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 +public void invoke(RequestContext request, ValveContext context) throws PipelineException { - try - { + // initialize/validate security subject // access request user principal if defined or default @@ -102,6 +103,7 @@ { subject = null; } + // if subject not available, generate default subject using // request or default profiler anonymous user principal @@ -119,33 +121,32 @@ // set request context subject request.setSubject(subject); - // Pass control to the next Valve in the Pipeline and execute under the current subject + // Pass control to the next Valve in the Pipeline and execute under + // the current subject final ValveContext vc = context; final RequestContext rc = request; - Subject.doAsPrivileged(subject, new PrivilegedAction() + PipelineException pe = (PipelineException) Subject.doAsPrivileged(subject, new PrivilegedAction() { - public Object run() + public Object run() { - try + try { - vc.invokeNext(rc); + vc.invokeNext(rc); + return null; } catch (PipelineException e) - { - } - return null; + { + return e; + } } }, null); - } - catch (Throwable t) - { - // TODO: valve exception handling formalized - t.printStackTrace(); - } + if(pe != null) + { + throw pe; + } } - public String toString() { return "SecurityValve";
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]