Created
January 23, 2013 17:44
-
-
Save Onjanirina/4610885 to your computer and use it in GitHub Desktop.
TransactionFilter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.onja.gov.elections; | |
import java.io.IOException; | |
import javax.annotation.Resource; | |
import javax.servlet.Filter; | |
import javax.servlet.FilterChain; | |
import javax.servlet.FilterConfig; | |
import javax.servlet.ServletException; | |
import javax.servlet.ServletRequest; | |
import javax.servlet.ServletResponse; | |
import javax.servlet.annotation.WebFilter; | |
import javax.transaction.*; | |
/** | |
* Servlet Filter implementation class TransactionFilter | |
*/ | |
@WebFilter(servletNames = { "TestServlet" }) | |
public class TransactionFilter implements Filter { | |
@Resource | |
private UserTransaction userTransaction; | |
/** | |
* @see Filter#destroy() | |
*/ | |
public void destroy() { | |
} | |
/** | |
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) | |
*/ | |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | |
/***/ | |
try { | |
this.userTransaction.begin(); | |
chain.doFilter(request, response); | |
this.userTransaction.commit(); | |
} catch (NotSupportedException e) { | |
e.printStackTrace(); | |
} catch (SystemException e) { | |
e.printStackTrace(); | |
} catch (SecurityException e) { | |
e.printStackTrace(); | |
} catch (IllegalStateException e) { | |
e.printStackTrace(); | |
} catch (RollbackException e) { | |
e.printStackTrace(); | |
} catch (HeuristicMixedException e) { | |
e.printStackTrace(); | |
} catch (HeuristicRollbackException e) { | |
e.printStackTrace(); | |
} | |
} | |
/** | |
* @see Filter#init(FilterConfig) | |
*/ | |
public void init(FilterConfig fConfig) throws ServletException { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment