testing DataSourceFilter
------------------------
Key: STS-902
URL: http://www.stripesframework.org/jira/browse/STS-902
Project: Stripes
Issue Type: Improvement
Components: Examples
Reporter: Tony Trung Thanh Vo
- I have setup a DataSourceFilter and change the web.xml so that
DataSourceFilter will get call before the ActionBean executed to obtain
database connection and close database connection after the action bean's
execution is finished
Here's the template code for DataSourceFilter.
- Is there anyway I can write unit/integration test(s) to make sure that the
database connection has been opened and closed properly by DataSourceFitler?
public class DataSourceFilter implements Filter {
private final Logger logger =
LoggerFactory.getLogger(DataSourceFilter.class);
@Override
public void init(FilterConfig filterConfig) throws ServletException {
this.logger.info("Datasource Filter has been initialized");
}
@Override
public void destroy() {
this.logger.info("Datasource Filter has been destroyed");
new DataSourceManager().closeConnection();
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse
servletResponse, FilterChain filterChain) throws ServletException, IOException {
final DataSourceManager dataSourceManager = new DataSourceManager();
try {
// Ensure that a connection has been retrieved for ThreadLocal
dataSourceManager.getConnection();
// Ask everything else to process first
filterChain.doFilter(servletRequest, servletResponse);
// Once everything is done, ensure everything is committed
dataSourceManager.getConnection().commit();
} catch(Exception exception) {
logger.error("Unable to processes the filtered request: " +
exception, exception);
try {
dataSourceManager.getConnection().rollback();
} catch(SQLException sqlException) {
this.logger.error("Unable to processes the filtered
request(Rollback): " + sqlException, sqlException);
}
} finally {
dataSourceManager.closeConnection();
}
}
}
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development