Coverage Report - pt.digitalis.dif.utils.logging.DIFCoreDebugAspect
 
Classes in this File Line Coverage Branch Coverage Complexity
DIFCoreDebugAspect
0%
0/84
0%
0/16
0
 
 1  0
 /**
 2  
  * - Digitalis Internal Framework v2.0 - (C) 2007, Digitalis Informatica. Distribuicao e Gestao de Informatica, Lda.
 3  
  * Estrada de Paco de Arcos num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999
 4  
  * http://www.digitalis.pt
 5  
  */
 6  
 package pt.digitalis.dif.utils.logging;
 7  
 
 8  
 import org.aspectj.lang.Signature;
 9  
 
 10  
 import pt.digitalis.dif.controller.AbstractDIFDispatcher;
 11  
 import pt.digitalis.dif.controller.objects.DIFContext;
 12  
 import pt.digitalis.dif.controller.objects.DIFRequest;
 13  
 import pt.digitalis.dif.controller.objects.DIFResponse;
 14  
 import pt.digitalis.log.LogLevel;
 15  
 
 16  
 /**
 17  
  * This aspect performs logging duties on the framework's core associated with the so-called "Debug" logging level. The
 18  
  * aspect is declared privileged so it can access the Dispatcher's difContext (which is declared with protected scope).
 19  
  *
 20  
  * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a>
 21  
  * @created 2007/05/22
 22  
  */
 23  
 
 24  0
 privileged public aspect DIFCoreDebugAspect extends DIFLogAspect {
 25  
 
 26  
     /* --- Pointcuts --- */
 27  
 
 28  
     /**
 29  
      * Captures the execution of validate, authenticate and authorize methods in any Dispatcher.
 30  
      */
 31  
     private pointcut dispatcherMethodsWithReturn() : execution(* pt.digitalis.dif.controller.AbstractDIFDispatcher+.validate(..)) ||
 32  
     execution(* pt.digitalis.dif.controller.AbstractDIFDispatcher+.authenticate(..)) ||
 33  0
     execution(* pt.digitalis.dif.controller.AbstractDIFDispatcher+.authorize(..));
 34  
 
 35  
     /**
 36  
      * This pointcut captures the execution of the createContext() method. It also exposes the method's argument.
 37  
      *
 38  
      * @param difRequest
 39  
      *            the methods argument
 40  
      */
 41  0
     private pointcut contextCreation(DIFRequest difRequest) : execution (* pt.digitalis.dif.controller.AbstractDIFDispatcher+.createContext(..)) && args (difRequest);
 42  
 
 43  
     /**
 44  
      * Captures the execution of the execute() method of any Dispatcher. Exposes the Dispatcher so the context can be
 45  
      * printed.
 46  
      *
 47  
      * @param dispatcher
 48  
      *            the dispatcher
 49  
      */
 50  0
     private pointcut stageExecution(AbstractDIFDispatcher dispatcher) : execution (* pt.digitalis.dif.controller.AbstractDIFDispatcher+.execute(..)) && this(dispatcher);
 51  
 
 52  
     /** Captures the execution of the DIFRequest construction method. */
 53  0
     private pointcut difResponseCreation() : call (* pt.digitalis.dif.controller.AbstractDIFDispatcher+.createResponse(..));
 54  
 
 55  
     /**
 56  
      * Captures the execution of the AbstractChAL method <code>serve()</code>.
 57  
      *
 58  
      * @param request
 59  
      *            the original request
 60  
      * @param response
 61  
      *            the response
 62  
      * @param restAction
 63  
      *            the REST action
 64  
      */
 65  0
     private pointcut serve(Object request, Object response, Object restAction) : execution (* pt.digitalis.dif.controller.AbstractChAL+.serve(..)) && args (request, response, restAction);
 66  
 
 67  
     /* --- Advice --- */
 68  
 
 69  
     /**
 70  
      * This advice logs the return of the methods captured by the pointcut
 71  
      *
 72  
      * @param returnValue
 73  
      *            the method's return value
 74  
      */
 75  
     after() returning(Object returnValue): dispatcherMethodsWithReturn()
 76  
     {
 77  0
         super.getLogger().increaseIndentation();
 78  
 
 79  0
         if (super.getLogger().isDebugEnabled())
 80  
         {
 81  0
             Signature signature = thisJoinPointStaticPart.getSignature();
 82  0
             super.getLogger().log(
 83  0
                     LogLevel.DEBUG,
 84  0
                     super.getLogger().getIndentationString() + "Method " + signature.getDeclaringType().getName() + "."
 85  0
                             + signature.getName());
 86  
         }
 87  
 
 88  0
         super.getLogger().decreaseIndentation();
 89  0
     }
 90  
 
 91  
     /**
 92  
      * Logs debugging information about the received request and the created context.
 93  
      *
 94  
      * @param difRequest
 95  
      *            the request received
 96  
      * @param context
 97  
      *            the created context
 98  
      */
 99  
     after(DIFRequest difRequest) returning (DIFContext context) : contextCreation(difRequest)
 100  
     {
 101  0
         super.getLogger().increaseIndentation();
 102  
 
 103  0
         if (super.getLogger().isDebugEnabled())
 104  
         {
 105  
 
 106  0
             Signature signature = thisJoinPointStaticPart.getSignature();
 107  
 
 108  
             // Logging the request
 109  0
             super.getLogger().log(
 110  0
                     LogLevel.DEBUG,
 111  0
                     super.getLogger().getIndentationString() + "\n------------------------" + difRequest.toString()
 112  0
                             + "\nat: " + signature.getDeclaringType().getName() + "." + signature.getName()
 113  0
                             + "\n------------------------");
 114  
             // Logging the context object
 115  0
             super.getLogger().log(
 116  0
                     LogLevel.DEBUG,
 117  0
                     super.getLogger().getIndentationString() + "\n------------------------" + context.toString()
 118  0
                             + "\nat: " + signature.getDeclaringType().getName() + "." + signature.getName()
 119  0
                             + "\n------------------------");
 120  
         }
 121  
 
 122  0
         super.getLogger().decreaseIndentation();
 123  0
     }
 124  
 
 125  
     /**
 126  
      * Logs the execution context before the stage execution. This logging effort reflects the changes the context
 127  
      * suffered since it's creation through the <code>validate()</code>,<code>authenticate()</code>,<code>authorize()</code>
 128  
      *
 129  
      * @param dispatcher
 130  
      *            the dispatcher
 131  
      */
 132  
     before(AbstractDIFDispatcher dispatcher) : stageExecution(dispatcher)
 133  
     {
 134  0
         super.getLogger().increaseIndentation();
 135  
 
 136  0
         if (super.getLogger().isDebugEnabled())
 137  
         {
 138  
 
 139  0
             Signature signature = thisJoinPointStaticPart.getSignature();
 140  
 
 141  0
             super.getLogger().log(
 142  0
                     LogLevel.DEBUG,
 143  0
                     super.getLogger().getIndentationString() + "\n------------------------"
 144  0
                             + dispatcher.difContext.toString() + "\nbefore entering: "
 145  0
                             + signature.getDeclaringType().getName() + "." + signature.getName()
 146  0
                             + "\n------------------------");
 147  
         }
 148  0
     }
 149  
 
 150  
     /**
 151  
      * Logs the execution context after the stage execution. This logging effort reflects the changes the context
 152  
      * suffered during the stage execution (redirections, etc...)
 153  
      *
 154  
      * @param dispatcher
 155  
      *            the dispatcher
 156  
      */
 157  
     after(AbstractDIFDispatcher dispatcher) : stageExecution(dispatcher)
 158  
     {
 159  0
         if (super.getLogger().isDebugEnabled())
 160  
         {
 161  
 
 162  0
             Signature signature = thisJoinPointStaticPart.getSignature();
 163  
 
 164  0
             super.getLogger().log(
 165  0
                     LogLevel.DEBUG,
 166  0
                     super.getLogger().getIndentationString() + "\n------------------------"
 167  0
                             + dispatcher.difContext.toString() + "\nafter exiting: "
 168  0
                             + signature.getDeclaringType().getName() + "." + signature.getName()
 169  0
                             + "\n------------------------");
 170  
         }
 171  
 
 172  0
         super.getLogger().decreaseIndentation();
 173  0
     }
 174  
 
 175  
     /**
 176  
      * @param response
 177  
      *            the returned response.
 178  
      */
 179  
     after() returning (DIFResponse response) : difResponseCreation()
 180  
     {
 181  0
         super.getLogger().increaseIndentation();
 182  
 
 183  0
         if (super.getLogger().isDebugEnabled())
 184  
         {
 185  0
             Signature signature = thisJoinPointStaticPart.getSignature();
 186  
 
 187  0
             super.getLogger().log(
 188  0
                     LogLevel.DEBUG,
 189  0
                     super.getLogger().getIndentationString() + "\n------------------------" + response.toString()
 190  0
                             + "\nat: " + signature.getDeclaringType().getName() + "." + signature.getName()
 191  0
                             + "\n------------------------");
 192  
         }
 193  
 
 194  0
         super.getLogger().decreaseIndentation();
 195  0
     }
 196  
 
 197  
     /**
 198  
      * Logs original request from the Listener received by the AbstractChAL.
 199  
      *
 200  
      * @param request
 201  
      *            the original request
 202  
      * @param response
 203  
      *            the response
 204  
      * @param restAction
 205  
      *            the REST action
 206  
      */
 207  
     before(Object request, Object response, Object restAction) : serve(request, response, restAction)
 208  
     {
 209  0
         super.getLogger().increaseIndentation();
 210  
 
 211  0
         if (super.getLogger().isDebugEnabled())
 212  
         {
 213  0
             Signature signature = thisJoinPointStaticPart.getSignature();
 214  0
             super.getLogger().log(
 215  0
                     LogLevel.DEBUG,
 216  0
                     super.getLogger().getIndentationString() + "\n------------------------\n" + request.toString()
 217  0
                             + "\nat: " + signature.getDeclaringType().getName() + "." + signature.getName()
 218  0
                             + "\n------------------------");
 219  
         }
 220  0
     }
 221  
 
 222  
     /**
 223  
      * Logs response that will be sent to the Listener.
 224  
      *
 225  
      * @param request
 226  
      *            the request
 227  
      * @param response
 228  
      *            the response to send to the Listener
 229  
      * @param restAction
 230  
      *            the REST action
 231  
      */
 232  
     after(Object request, Object response, Object restAction) : serve(request, response, restAction)
 233  
     {
 234  0
         if (super.getLogger().isDebugEnabled())
 235  
         {
 236  0
             Signature signature = thisJoinPointStaticPart.getSignature();
 237  
 
 238  
             // Log request
 239  0
             super.getLogger().log(
 240  0
                     LogLevel.DEBUG,
 241  0
                     super.getLogger().getIndentationString() + "\n------------------------\n" + request.toString()
 242  0
                             + "\nat: " + signature.getDeclaringType().getName() + "." + signature.getName()
 243  0
                             + "\n------------------------");
 244  
             // Log response
 245  0
             super.getLogger().log(
 246  0
                     LogLevel.DEBUG,
 247  0
                     super.getLogger().getIndentationString() + "\n------------------------\n" + response.toString()
 248  0
                             + "\nat: " + signature.getDeclaringType().getName() + "." + signature.getName()
 249  0
                             + "\n------------------------");
 250  
         }
 251  
 
 252  0
         super.getLogger().decreaseIndentation();
 253  0
     }
 254  
 
 255  
 }