ignore

Interceptors

Back to Examples

For operations that are common to many actions, interceptors are ideal. In plain Struts applications, there is no built in interceptor framework. Instead, you either create a common Action base class, or subclass RequestProcessor. With Strecks, interceptors can be added via configuration. An example of an interceptor implementation is shown below:

/**
* Strecks interceptor implementation
*/
public class ActionLoggingInterceptor implements BeforeInterceptor, AfterInterceptor
{

	private static Log log = LogFactory.getLog(ActionLoggingInterceptor.class);

	public void beforeExecute(Object actionBean, ActionContext context)
	{
		HttpServletRequest request = context.getRequest();
		log.info("Starting process action perform " + request.getRequestURI());
		log.info("Using " + context.getMapping().getType());
	}

	public void afterExecute(Object actionBean, ActionContext context)
	{
		HttpServletRequest request = context.getRequest();
		log.info("Ended action perform of " + request.getRequestURI() + StringUtils.LINE_SEPARATOR);
	}

}

In this case, the interceptor implements both BeforeInterceptor and AfterInterceptor. This means the interceptor will be called both before and after the action bean's methods have executed. Note that the interceptor gets access to the full ActionContext as well as the state of the action bean itself.

SourceForge.net logo java.net Member logo Copyright © 2005-2007 Realsolve Solutions