Commit 1834cadd authored by Matija Obreza's avatar Matija Obreza
Browse files

User proper HTTP error codes and make Sitemesh3 decorate error pages

parent 33629148
......@@ -30,7 +30,9 @@ import org.genesys2.server.servlet.filter.LocaleURLFilter;
import org.genesys2.server.servlet.filter.NewGUIFilter;
import org.genesys2.spring.config.ApplicationConfig;
import org.genesys2.spring.config.SpringServletConfig;
import org.sitemesh.builder.SiteMeshFilterBuilder;
import org.sitemesh.config.ConfigurableSiteMeshFilter;
import org.sitemesh.webapp.contentfilter.BasicSelector;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
......@@ -69,8 +71,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
DispatcherServlet dispatcher = new DispatcherServlet(appContext);
dispatcher.setThrowExceptionIfNoHandlerFound(true);
ServletRegistration.Dynamic dispatcherServlet = servletContext
.addServlet("mvc", dispatcher);
ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("mvc", dispatcher);
dispatcherServlet.setLoadOnStartup(1);
dispatcherServlet.addMapping("/");
......@@ -93,18 +94,15 @@ public class WebAppInitializer implements WebApplicationInitializer {
private void registerFilters(ServletContext servletContext, AnnotationConfigWebApplicationContext appContext) {
// UrlRewrite filter configuration
FilterRegistration.Dynamic urlRewriteFilter = servletContext
.addFilter("urlRewriteFilter", UrlRewriteFilter.class);
FilterRegistration.Dynamic urlRewriteFilter = servletContext.addFilter("urlRewriteFilter", UrlRewriteFilter.class);
urlRewriteFilter.setInitParameter("confReloadCheckInterval", "10");
// urlRewriteFilter.setInitParameter("logLevel", "sysout:DEBUG");
urlRewriteFilter.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
urlRewriteFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
// Encoding filter configuration
FilterRegistration.Dynamic encodingFilter = servletContext
.addFilter("encodingFilter", CharacterEncodingFilter.class);
FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class);
encodingFilter.setInitParameter("encoding", "UTF-8");
encodingFilter.setInitParameter("forceEncoding", "true");
......@@ -112,8 +110,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
encodingFilter.addMappingForUrlPatterns(null, false, "/*");
// Configuration of cross origin filter for web REST API clients
FilterRegistration.Dynamic crossOriginFilter = servletContext
.addFilter("cross-origin", "org.eclipse.jetty.servlets.CrossOriginFilter");
FilterRegistration.Dynamic crossOriginFilter = servletContext.addFilter("cross-origin", "org.eclipse.jetty.servlets.CrossOriginFilter");
crossOriginFilter.setInitParameter("allowedOrigins", "*");
crossOriginFilter.setInitParameter("allowCredentials", "true");
......@@ -127,27 +124,25 @@ public class WebAppInitializer implements WebApplicationInitializer {
crossOriginFilter.addMappingForUrlPatterns(null, false, "/webapi");
// Hazelcast web filter configuration goes first!
FilterRegistration.Dynamic hazelcastWebFilter = servletContext
.addFilter("hazelcastWebFilter", new DelegatingFilterProxy("hazelcastWebFilter"));
FilterRegistration.Dynamic hazelcastWebFilter = servletContext.addFilter("hazelcastWebFilter", new DelegatingFilterProxy("hazelcastWebFilter"));
hazelcastWebFilter.setInitParameter("targetFilterLifecycle", "true");
hazelcastWebFilter.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST), false, "/*");
servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain"))
.addMappingForUrlPatterns(null, false, "/*");
hazelcastWebFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST), false, "/*");
// Filter chain proxy configuration
/* FilterRegistration.Dynamic filterChainProxy = servletContext
.addFilter("org.springframework.security.filterChainProxy",
"org.springframework.web.filter.DelegatingFilterProxy");
servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false, "/*");
filterChainProxy.addMappingForUrlPatterns(null, false, "*//*");*/
// Filter chain proxy configuration
/*
* FilterRegistration.Dynamic filterChainProxy = servletContext
* .addFilter("org.springframework.security.filterChainProxy",
* "org.springframework.web.filter.DelegatingFilterProxy");
*
* filterChainProxy.addMappingForUrlPatterns(null, false, "
*//* "); */
// Locale URL filter configuration
FilterRegistration.Dynamic localeURLFilter = servletContext
.addFilter("localeURLFilter", LocaleURLFilter.class);
FilterRegistration.Dynamic localeURLFilter = servletContext.addFilter("localeURLFilter", LocaleURLFilter.class);
localeURLFilter.setInitParameter("exclude-paths", "/html /login-attempt");
localeURLFilter.setInitParameter("default-locale", "en");
......@@ -157,34 +152,37 @@ public class WebAppInitializer implements WebApplicationInitializer {
// EnvVar filter configuration
// Adds variables to all requests
FilterRegistration.Dynamic envVarFilter = servletContext
.addFilter("envVarFilter", new DelegatingFilterProxy("envVarFilter"));
FilterRegistration.Dynamic envVarFilter = servletContext.addFilter("envVarFilter", new DelegatingFilterProxy("envVarFilter"));
envVarFilter.addMappingForUrlPatterns(null, false, "/*");
// Genesys Web API Filter configuration
FilterRegistration.Dynamic webApiFilter = servletContext
.addFilter("webApiFilter", new DelegatingFilterProxy("webApiFilter"));
FilterRegistration.Dynamic webApiFilter = servletContext.addFilter("webApiFilter", new DelegatingFilterProxy("webApiFilter"));
webApiFilter.addMappingForUrlPatterns(null, false, "/webapi/*");
// http://stackoverflow.com/a/22409634
ConfigurableSiteMeshFilter sitemeshWithErrors = new ConfigurableSiteMeshFilter() {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.setCustomSelector(new BasicSelector(true, "text/html"));
}
};
// Sitemesh filter configuration
FilterRegistration.Dynamic sitemeshFilter = servletContext
.addFilter("sitemesh", ConfigurableSiteMeshFilter.class);
FilterRegistration.Dynamic sitemeshFilter = servletContext.addFilter("sitemesh", sitemeshWithErrors);
sitemeshFilter.addMappingForUrlPatterns(null, false, "/*");
// New GUI filter configuration
FilterRegistration.Dynamic newGUIFilter = servletContext
.addFilter("newGUIFilter", NewGUIFilter.class);
FilterRegistration.Dynamic newGUIFilter = servletContext.addFilter("newGUIFilter", NewGUIFilter.class);
newGUIFilter.setInitParameter("exclude-paths", "/html /login-attempt");
newGUIFilter.addMappingForUrlPatterns(null, false, "/*");
// GZip filter configuration
FilterRegistration.Dynamic gZIPFilter = servletContext
.addFilter("gZIPFilter", GzipFilter.class);
FilterRegistration.Dynamic gZIPFilter = servletContext.addFilter("gZIPFilter", GzipFilter.class);
gZIPFilter.addMappingForUrlPatterns(null, false, "/html/*");
}
......
......@@ -38,9 +38,8 @@ import org.springframework.web.servlet.NoHandlerFoundException;
@ControllerAdvice
public class UserControllerAdvice extends BaseController {
/*@ResponseStatus(HttpStatus.FORBIDDEN)*/
@ResponseStatus(code = HttpStatus.FORBIDDEN)
@ExceptionHandler(value = { AccessDeniedException.class })
// @ResponseBody
public ModelAndView handleAccessDeniedException(AccessDeniedException e) {
final ModelAndView mav = new ModelAndView("/errors/error");
mav.addObject("exception", e);
......@@ -49,7 +48,6 @@ public class UserControllerAdvice extends BaseController {
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(value = { ResourceNotFoundException.class })
// @ResponseBody
public ModelAndView handleResourceNotFoundException(ResourceNotFoundException e) {
final ModelAndView mav = new ModelAndView("/errors/error");
mav.addObject("exception", e);
......@@ -65,7 +63,6 @@ public class UserControllerAdvice extends BaseController {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(value = { Throwable.class })
// @ResponseBody
public ModelAndView handleAll(Throwable e) {
_logger.error(e.getMessage(), e);
final ModelAndView mav = new ModelAndView("/errors/error");
......@@ -81,6 +78,7 @@ public class UserControllerAdvice extends BaseController {
return transformErrors(e.getBindingResult());
}
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(value = { NoHandlerFoundException.class })
public ModelAndView handle404() {
return new ModelAndView("/errors/404");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment