org.nuiton.web.filter
Class TopiaTransactionFilter

java.lang.Object
  extended by org.nuiton.web.filter.TopiaTransactionFilter
All Implemented Interfaces:
javax.servlet.Filter

public abstract class TopiaTransactionFilter
extends Object
implements javax.servlet.Filter

Purpose of this filter

This filter purpose is to inject in the request a transaction from TopiaContext and deal with the complete lifecycle of a topia transaction while a request.

The injected transaction will be closed (if was really opened) at the end of the request.

Configuration of the filter

The filter accepts two configuration parameters:

Obtain the transaction

The (proxied) transaction is pushed as an attribute in the servlet request.

The attribute name is TOPIA_TRANSACTION_REQUEST_ATTRIBUTE.

A convience method is created here to obtain the transaction getTransaction(ServletRequest) :

 TopiaContext tx = TopiaTransactionFilter.getTransaction(ServletRequest);
 

If you prefer to not use this nice method, you can also do this:

 TopiaContext tx = (TopiaContext) request.getAttribute(TopiaTransactionFilter#TOPIA_TRANSACTION_REQUEST_ATTRIBUTE);
 

Since:
1.6
Author:
tchemit

Nested Class Summary
 class TopiaTransactionFilter.TopiaTransactionProxyInvocationHandler
          Handler of a proxy on a TopiaContext.
 
Field Summary
static String[] DEFAULT_EXCLUDE_METHODS
           
static String[] DEFAULT_UNUSED_METHODS
           
protected  Set<String> excludeMethods
          names of methods to forbid access while using proxy.
static String TOPIA_TRANSACTION_REQUEST_ATTRIBUTE
           
protected  Set<String> unusedMethods
          names of methods to by-pass if no transaction opened on proxy.
 
Constructor Summary
TopiaTransactionFilter()
           
 
Method Summary
protected abstract  org.nuiton.topia.TopiaContext beginTransaction()
          Method to open a new transaction.
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
           
 Set<String> getExcludeMethods()
           
static org.nuiton.topia.TopiaContext getTransaction(javax.servlet.ServletRequest request)
           
 Set<String> getUnusedMethods()
           
 void init(javax.servlet.FilterConfig filterConfig)
           
protected  Object onExcludeMethod(Object proxy, Method method, Object[] args)
          Hook method called when a method with his name in excludeMethods was invoked on the proxied transaction.
protected  Object onUnusedMethod(Object proxy, Method method, Object[] args)
          Hook method called when a method with his name in unusedMethods was invoked on the proxied transaction while the underlying transaction is still not opened.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOPIA_TRANSACTION_REQUEST_ATTRIBUTE

public static final String TOPIA_TRANSACTION_REQUEST_ATTRIBUTE
See Also:
Constant Field Values

DEFAULT_EXCLUDE_METHODS

public static final String[] DEFAULT_EXCLUDE_METHODS

DEFAULT_UNUSED_METHODS

public static final String[] DEFAULT_UNUSED_METHODS

excludeMethods

protected Set<String> excludeMethods
names of methods to forbid access while using proxy.


unusedMethods

protected Set<String> unusedMethods
names of methods to by-pass if no transaction opened on proxy.

Constructor Detail

TopiaTransactionFilter

public TopiaTransactionFilter()
Method Detail

getExcludeMethods

public Set<String> getExcludeMethods()

getUnusedMethods

public Set<String> getUnusedMethods()

getTransaction

public static org.nuiton.topia.TopiaContext getTransaction(javax.servlet.ServletRequest request)

beginTransaction

protected abstract org.nuiton.topia.TopiaContext beginTransaction()
                                                           throws org.nuiton.topia.TopiaRuntimeException
Method to open a new transaction.

Returns:
the new freshly opened transaction
Throws:
org.nuiton.topia.TopiaRuntimeException - if any problem while opening a new transaction

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException

onExcludeMethod

protected Object onExcludeMethod(Object proxy,
                                 Method method,
                                 Object[] args)
                          throws Throwable
Hook method called when a method with his name in excludeMethods was invoked on the proxied transaction.

Parameters:
proxy - proxied transaction
method - method invoked
args - arguments of the invoked method
Returns:
the return code of the method
Throws:
Throwable - if any error to do.

onUnusedMethod

protected Object onUnusedMethod(Object proxy,
                                Method method,
                                Object[] args)
                         throws Throwable
Hook method called when a method with his name in unusedMethods was invoked on the proxied transaction while the underlying transaction is still not opened.

Parameters:
proxy - the proxy itself
method - method invoked
args - arguments of the invoked method
Returns:
the return code of the method
Throws:
Throwable - if any error to do.


Copyright © 2011 CodeLutin. All Rights Reserved.