All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opensymphony.xwork2.interceptor.LoggingInterceptor Maven / Gradle / Ivy

Go to download

XWork is an command-pattern framework that is used to power WebWork as well as other applications. XWork provides an Inversion of Control container, a powerful expression language, data type conversion, validation, and pluggable configuration.

The newest version!
/*
 * Copyright (c) 2002-2007 by OpenSymphony
 * All rights reserved.
 */
package com.opensymphony.xwork2.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;


/**
 * 
 * This interceptor logs the start and end of the execution an action (in English-only, not internationalized).
 * 
* Note:: This interceptor will log at INFO level. *

* * * * There are no parameters for this interceptor. * * * * There are no obvious extensions to the existing interceptor. * * *

 * 
 * <!-- prints out a message before and after the immediate action execution -->
 * <action name="someAction" class="com.examples.SomeAction">
 *     <interceptor-ref name="completeStack"/>
 *     <interceptor-ref name="logger"/>
 *     <result name="success">good_result.ftl</result>
 * </action>
 *
 * <!-- prints out a message before any more interceptors continue and after they have finished -->
 * <action name="someAction" class="com.examples.SomeAction">
 *     <interceptor-ref name="logger"/>
 *     <interceptor-ref name="completeStack"/>
 *     <result name="success">good_result.ftl</result>
 * </action>
 * 
 * 
* * @author Jason Carreira */ public class LoggingInterceptor extends AbstractInterceptor { private static final Logger LOG = LoggerFactory.getLogger(LoggingInterceptor.class); private static final String FINISH_MESSAGE = "Finishing execution stack for action "; private static final String START_MESSAGE = "Starting execution stack for action "; @Override public String intercept(ActionInvocation invocation) throws Exception { logMessage(invocation, START_MESSAGE); String result = invocation.invoke(); logMessage(invocation, FINISH_MESSAGE); return result; } private void logMessage(ActionInvocation invocation, String baseMessage) { if (LOG.isInfoEnabled()) { StringBuilder message = new StringBuilder(baseMessage); String namespace = invocation.getProxy().getNamespace(); if ((namespace != null) && (namespace.trim().length() > 0)) { message.append(namespace).append("/"); } message.append(invocation.getProxy().getActionName()); LOG.info(message.toString()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy