r184 - trunk/nuiton-web/src/main/java/org/nuiton/web/filter
Author: tchemit Date: 2012-02-18 17:03:59 +0100 (Sat, 18 Feb 2012) New Revision: 184 Url: http://nuiton.org/repositories/revision/nuiton-web/184 Log: Evolution #1973: Can customize request attribute name to use in TransactionFilter Modified: trunk/nuiton-web/src/main/java/org/nuiton/web/filter/TopiaTransactionFilter.java Modified: trunk/nuiton-web/src/main/java/org/nuiton/web/filter/TopiaTransactionFilter.java =================================================================== --- trunk/nuiton-web/src/main/java/org/nuiton/web/filter/TopiaTransactionFilter.java 2012-02-08 10:16:43 UTC (rev 183) +++ trunk/nuiton-web/src/main/java/org/nuiton/web/filter/TopiaTransactionFilter.java 2012-02-18 16:03:59 UTC (rev 184) @@ -76,9 +76,11 @@ * <h2>Obtain the transaction</h2> * The (proxied) transaction is pushed as an attribute in the servlet request. * <p/> - * The attribute name is {@link #TOPIA_TRANSACTION_REQUEST_ATTRIBUTE}. + * The attribute name is defined by field {@link #requestAttribute} + * (default value is {@link #TOPIA_TRANSACTION_REQUEST_ATTRIBUTE}) and can be + * changed. * <p/> - * A convience method is created here to obtain the transaction {@link #getTransaction(ServletRequest)} : + * A convience method is created here to obtain the transaction {@link #getTransaction(ServletRequest)} : * <pre> * TopiaContext tx = TopiaTransactionFilter.getTransaction(ServletRequest); * </pre> @@ -88,6 +90,11 @@ * TopiaContext tx = (TopiaContext) request.getAttribute(TopiaTransactionFilter#TOPIA_TRANSACTION_REQUEST_ATTRIBUTE); * </pre> * + * Or + * <pre> + * TopiaContext tx = (TopiaContext) request.getAttribute(modifiedAttributeName); + * </pre> + * * @author tchemit <chemit@codelutin.com> * @since 1.6 */ @@ -123,6 +130,16 @@ /** names of methods to by-pass if no transaction opened on proxy. */ protected Set<String> unusedMethods; + /** + * Name of the request attribute where to push the transaction. + * <p/> + * By default will use value of + * {@link #TOPIA_TRANSACTION_REQUEST_ATTRIBUTE}. + * + * @since 1.10 + */ + protected String requestAttribute = TOPIA_TRANSACTION_REQUEST_ATTRIBUTE; + public Set<String> getExcludeMethods() { return excludeMethods; } @@ -131,6 +148,16 @@ return unusedMethods; } + /** + * to change the {@link #requestAttribute}. + * + * @param requestAttribute new name of the request attribute where to push the transaction. + * @since 1.10 + */ + public void setRequestAttribute(String requestAttribute) { + this.requestAttribute = requestAttribute; + } + public static TopiaContext getTransaction(ServletRequest request) { TopiaContext topiaContext = (TopiaContext) request.getAttribute(TOPIA_TRANSACTION_REQUEST_ATTRIBUTE); @@ -187,12 +214,12 @@ TopiaContext proxy = (TopiaContext) Proxy.newProxyInstance( getClass().getClassLoader(), new Class<?>[]{TopiaContext.class, - TopiaContextImplementor.class}, + TopiaContextImplementor.class}, proxyInvocationHandler ); // push it in request as an attribute - request.setAttribute(TOPIA_TRANSACTION_REQUEST_ATTRIBUTE, proxy); + request.setAttribute(requestAttribute, proxy); try { // chain to next filter @@ -221,7 +248,7 @@ // not authorized throw new IllegalAccessException( "Not allowed to access method " + method.getName() + " on " + - proxy); + proxy); } /** @@ -283,7 +310,7 @@ String methodName = method.getName(); if (log.isDebugEnabled()) { log.debug("Skip execution of method " + methodName + - " since no transaction is instanciated."); + " since no transaction is instanciated."); } Set<String> methods = getUnusedMethods();
participants (1)
-
tchemit@users.nuiton.org