Skip to content

Instantly share code, notes, and snippets.

@Onjanirina
Created January 23, 2013 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Onjanirina/4610885 to your computer and use it in GitHub Desktop.
Save Onjanirina/4610885 to your computer and use it in GitHub Desktop.
TransactionFilter
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