Hi All,

        Hope all is well.

        Attached is a new action for help with debugging and development. It's
        called DebugAction. All it does is log everything do with the current
        request (request info, parameters, remost host info, session
        attributes, etc).

        I've found it useful to see what's going on when developing/debugging
        large applications. Maybe it's of use for others.

        The log output looks like:

DEBUG   11596   [cocoon  ] (Thread-15): org.apache.cocoon.acting.DebugAction: 
DEBUGGING INFORMATION:
REQUEST: /cocoon/debug

CONTEXT PATH: /cocoon
SERVLET PATH: /debug
PATH INFO: null

REMOTE HOST: localhost
REMOTE ADDRESS: 127.0.0.1
REMOTE USER: null
REQUEST SESSION ID: null
REQUEST PREFERRED LOCALE: en
SERVER HOST: localhost
SERVER PORT: 9001

METHOD: GET
CONTENT LENGTH: -1
PROTOCOL: HTTP/1.0
SCHEME: http
AUTH TYPE: null

REQUEST PARAMETERS:

PARAM: 'a' VALUE: 'b'
PARAM: 'c' VALUE: 'd'

SESSION ATTRIBUTES:

        Feel free to add whatever details you think might be useful.

        Cheers,

        Marcus

-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   Open Software Associates GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'     Email : [EMAIL PROTECTED]
          &&&&.        Business Hours : +49 69 9757 200
    &&&&&&&:
/*****************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included  with this distribution in *
 * the LICENSE file.                                                         *
 *****************************************************************************/

/*
 * Package definition
 */
package org.apache.cocoon.acting;

/*
 * Standard imports
 */
import java.util.HashMap;
import java.util.Map;
import java.util.Enumeration;
import org.apache.cocoon.acting.ComposerAction;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.Constants;
import org.apache.avalon.framework.parameters.Parameters;

/**
 * This action is used for debugging purposes. It logs all details to do with
 * the current environment (request, session, and context)
 *
 * Sitemap definition:
 *
 * <pre>
 * &lt;map:action name="debug" src="org.apache.cocoon.acting.DebugAction"/&gt;
 * </pre>
 *
 * <p>
 *
 * Example use:
 *
 * <pre>
 * &lt;map:match pattern="some-resource"&gt;
 *  &lt;map:act type="debug"/&gt;
 * &lt;/map:match&gt;
 * </pre>
 *
 * @author <a href="mailto:[EMAIL PROTECTED]";>Marcus Crafter</a>
 * @version CVS $Revision: 1.3 $
 */
public class DebugAction extends ComposerAction {

    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters param)
    throws Exception {
        Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
        Session session = request.getSession(false);
        String msg = getClass().getName() + ": DEBUGGING INFORMATION:\n";

        msg += "REQUEST: " + request.getRequestURI() + "\n\n";
        msg += "CONTEXT PATH: " + request.getContextPath() + "\n";
        msg += "SERVLET PATH: " + request.getServletPath() + "\n";
        msg += "PATH INFO: " + request.getPathInfo() + "\n\n";

        msg += "REMOTE HOST: " + request.getRemoteHost() + "\n";
        msg += "REMOTE ADDRESS: " + request.getRemoteAddr() + "\n";
        msg += "REMOTE USER: " + request.getRemoteUser() + "\n";
        msg += "REQUEST SESSION ID: " + request.getRequestedSessionId() + "\n";
        msg += "REQUEST PREFERRED LOCALE: " + request.getLocale().toString() + "\n";
        msg += "SERVER HOST: " + request.getServerName() + "\n";
        msg += "SERVER PORT: " + request.getServerPort() + "\n\n";

        msg += "METHOD: " + request.getMethod() + "\n";
        msg += "CONTENT LENGTH: " + request.getContentLength() + "\n";
        msg += "PROTOCOL: " + request.getProtocol() + "\n";
        msg += "SCHEME: " + request.getScheme() + "\n";
        msg += "AUTH TYPE: " + request.getAuthType() + "\n\n";

        // log all of the request parameters
        Enumeration e = request.getParameterNames();

        msg += "REQUEST PARAMETERS:\n\n";

        while (e.hasMoreElements()) {
            String p = (String) e.nextElement();

            msg += "PARAM: '" + p + "' " +
                   "VALUE: '" + request.getParameter(p) + "'\n";
        }

        msg += "\nSESSION ATTRIBUTES:\n\n";

        // log all of the session attributes
        if (session != null) {
            e = session.getAttributeNames();

            while (e.hasMoreElements()) {
                String p = (String) e.nextElement();

                msg += "PARAM: '" + p + "' " +
                       "VALUE: '" + session.getAttribute(p) + "'\n";
            }
        }

        getLogger().debug(msg);

        return null;
    }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to