Package org.apache.cocoon

Examples of org.apache.cocoon.Notification


        // Check if cocoon was initialized
        if (this.cocoon == null) {
            res.setStatus(res.SC_INTERNAL_SERVER_ERROR);

            Notification n = new Notification(this, this.exception);
            n.setType("internal-servlet-error");
            n.setTitle("Internal servlet error");
            n.setSource("Cocoon servlet");
            n.setMessage("Internal servlet error");
            n.setDescription("Cocoon was not initialized.");
            n.addExtraDescription("request-uri", request.getRequestURI());
            res.setContentType(Notifier.notify(n, res.getOutputStream()));;

            return;
        }

        // We got it... Process the request
        String uri = request.getServletPath();
        if (uri == null) {
            uri = "";
        }
        String pathInfo = request.getPathInfo();
        if (pathInfo != null) {
            uri += pathInfo;
        }

        if (uri.length() == 0) {
            /* empty relative URI
                 -> HTTP-redirect from /cocoon to /cocoon/ to avoid
                    StringIndexOutOfBoundsException when calling
                    "".charAt(0)
               else process URI normally
            */
            String prefix = request.getRequestURI();

            if (prefix == null) {
                prefix = "";
            }

            res.sendRedirect(res.encodeRedirectURL(prefix + "/"));
            return;
        }

        String contentType = null;
        try {
            if (uri.charAt(0) == '/') {
                uri = uri.substring(1);
            }

            Environment env = this.getEnvironment(uri, request, res);

            // Initialize a fresh log context containing the object model : it
            // will be used by the CocoonLogFormatter
            ContextMap ctxMap = org.apache.log.ContextMap.getCurrentContext();
            ctxMap.clear();
            // Add thread name (default content for empty context)
            String threadName = Thread.currentThread().getName();
            ctxMap.set("threadName", threadName);
            // Add the object model
            ctxMap.set("objectModel", env.getObjectModel());
            // Add a unique request id (threadName + currentTime
            ctxMap.set("request-id", threadName + System.currentTimeMillis());

            if (this.cocoon.process(env)) {
                contentType = env.getContentType();
            } else {
                // means SC_NOT_FOUND
                res.sendError(res.SC_NOT_FOUND);

                Notification n = new Notification(this);
                n.setType("resource-not-found");
                n.setTitle("Resource not found");
                n.setSource("Cocoon servlet");
                n.setMessage("Resource not found");
                n.setDescription("The requested URI \""
                                 + request.getRequestURI()
                                 + "\" was not found.");
                n.addExtraDescription("request-uri", request.getRequestURI());
                n.addExtraDescription("path-info", uri);
                // send the notification but don't include it in the output stream
                // as the status SC_NOT_FOUND is enough
                res.setContentType(Notifier.notify(n, (OutputStream)null));
            }
        } catch (ResourceNotFoundException rse) {
            if (log.isWarnEnabled()) {
                log.warn("The resource was not found", rse);
            }

            res.sendError(res.SC_NOT_FOUND);
            Notification n = new Notification(this);
            n.setType("resource-not-found");
            n.setTitle("Resource not found");
            n.setSource("Cocoon servlet");
            n.setMessage("Resource not found");
            n.setDescription("The requested URI \""
                             + request.getRequestURI()
                             + "\" was not found.");
            n.addExtraDescription("request-uri", request.getRequestURI());
            n.addExtraDescription("path-info", uri);
            // send the notification but don't include it in the output stream
            // as the status SC_NOT_FOUND is enough
            res.setContentType(Notifier.notify(n, (OutputStream)null));
        } catch (ConnectionResetException cre) {
            if (log.isWarnEnabled()) {
                log.warn("The connection was reset", cre);
            }

            Notification n = new Notification(this);
            n.setType("resource-not-found");
            n.setTitle("Resource not found");
            n.setSource("Cocoon servlet");
            n.setMessage("Resource not found");
            n.setDescription("The requested URI \""
                             + request.getRequestURI()
                             + "\" was not found.");
            n.addExtraDescription("request-uri", request.getRequestURI());
            n.addExtraDescription("path-info", uri);
            // send the notification but don't include it in the output stream
            // as the connection was reset anyway
            res.setContentType(Notifier.notify(n, (OutputStream)null));
        } catch (Exception e) {
            if (log.isErrorEnabled()) {
                log.error("Problem with servlet", e);
            }
            //res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
            Notification n = new Notification(this, e);
            n.setType("internal-server-error");
            n.setTitle("Internal server error");
            n.setSource("Cocoon servlet");
            n.addExtraDescription("request-uri", request.getRequestURI());
            n.addExtraDescription("path-info", uri);
            res.setContentType(contentType = Notifier.notify(n, res.getOutputStream()));
        }

        long end = System.currentTimeMillis();
        String timeString = processTime(end - start);
View Full Code Here


     * Set the Exception to report.
     *
     * @param exception The Exception to report
     */
    public void setException(Throwable throwable) {
        notification = new Notification(this, throwable);
        notification.setTitle("Error creating the resource");
    }
View Full Code Here

     * Set the Notification to report.
     *
     * @param exception The Exception to report
     */
    public void setNotification(Object o) {
        notification = new Notification(this, o);
        notification.setTitle("Error creating the resource");
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.Notification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.