dispatcher.setContextConfigLocation(GeoServerAbstractTestSupport.class.getResource("dispatcher-servlet.xml").toString());
dispatcher.init(config);
// build a filter chain so that we can test with filters as well
MockFilterChain chain = new MockFilterChain();
List<Filter> filters = getFilters();
if(filters != null) {
for (Filter filter : filters) {
chain.addFilter(filter);
}
}
chain.setServlet(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
//excute the pre handler step
Collection interceptors =
GeoServerExtensions.extensions(HandlerInterceptor.class, applicationContext );
for ( Iterator i = interceptors.iterator(); i.hasNext(); ) {
HandlerInterceptor interceptor = (HandlerInterceptor) i.next();
interceptor.preHandle( request, response, dispatcher );
}
//execute
//dispatcher.handleRequest( request, response );
dispatcher.service(request, response);
//execute the post handler step
for ( Iterator i = interceptors.iterator(); i.hasNext(); ) {
HandlerInterceptor interceptor = (HandlerInterceptor) i.next();
interceptor.postHandle( request, response, dispatcher, null );
}
} catch(RuntimeException e) {
throw e;
} catch(IOException e) {
throw e;
} catch(ServletException e) {
throw e;
} catch(Exception e) {
throw (IOException) new IOException("Failed to handle the request").initCause(e);
}
}
});
chain.doFilter(request, response);
}