Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Server logging from custom class

    I've written a custom server class to extend IDACall modeled after the sample code under "operationbinding.requiresRole" in the reference. The idea being to set the userId and roles based on values passed down from shibboleth. Of course the new code is not working and I'd like to add some debugging statements that would dump values to the server console loge, or anywhere that I could read them to get a sense of where my code is failing.

    Is there a worked example somewhere of how to do this? I've tried a few things including com.isomorpic.Logger with no success thus far.

    Thanks
    RP

    #2
    Hi rpoyner,

    I'm using
    Code:
    com.isomorphic.log.Logger.Logger log = new Logger(MyClass.class.getName());
    Of course, your class/package must be registered in your log4j.isc.config.xml in your apache-tomcat\myproj\myproj\WEB-INF\classes directory.

    Best regards
    Blama

    Comment


      #3
      That was the problem. Once I added the new class to the log4j config I started seeing the expected output in the console log.

      Thanks.

      RP

      Comment


        #4
        Spoke too soon. I'm seeing some debug messages from SecureIDACall, but none that correspond to the logger statements in the code below.

        From SecureIDACall.java:

        /**
        * Extends IDACall to set UserId and UserRoles from attributes passed by shibboleth
        **/

        package edu.wisc.che.smartclient;

        import java.io.IOException;
        import java.util.Enumeration;

        import javax.servlet.*;
        import javax.servlet.http.*;
        import com.isomorphic.servlet.*;
        import com.isomorphic.rpc.RPCManager;
        import com.isomorphic.log.Logger;

        public class SecureIDACall extends IDACall {
        public void processRequest(HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException
        {
        HttpSession session = request.getSession();
        Logger eduLogger = new Logger(MyClass.class.getName());
        eduLogger.info("howdy from SecureIDACall");
        Enumeration keys = session.getAttributeNames();
        while (keys.hasMoreElements())
        {
        String key = (String)keys.nextElement();
        eduLogger.info("CBE session " + key + ": " + session.getValue(key));
        }
        Object roles = session == null ? null : session.getAttribute("isMemberOf");
        Object userId = session == null ? null : session.getAttribute("REMOTE_USER");

        if (roles != null) {
        try {
        RequestContext context = RequestContext.instance(this, request, response);
        RPCManager rpc = new RPCManager(request, response);
        rpc.setUserId((String) userId);
        rpc.setUserRoles(((String) roles).replace(':',','));

        // call processRPCTransaction() to iterate through all RPCRequests and
        // DSRequests and execute them
        processRPCTransaction(rpc, context);

        } catch (Throwable e) {
        handleError(response, e);
        }
        } else {
        super.processRequest(request, response);
        }
        }
        }

        From log4j.isc.config.xm
        <category name="edu.wisc.che.smartclient">
        <priority value="DEBUG" />
        <appender-ref ref="STDOUT"/>
        </category>

        Comment


          #5
          You should be using new Logger(SecureIDACall.class.getName()). I don't know in which package your "MyClass" is, if you really happen to have one and this is actual copy&paste.

          Best regards
          Blama

          Comment


            #6
            It turns out that log.debug("string"); works. I tried that on the hunch that the parent IDACall would already have a logger declared.

            Meanwhile it would appear that session.getAttributeNames(); is returning an empty enum. Which is the sort of debugging information I am after.

            Fun.

            Comment

            Working...
            X