|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2002-2015 the original author or authors.
|
|
|
|
|
* Copyright 2002-2017 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
@@ -87,7 +87,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
ThemeChangeInterceptor interceptor4 = new ThemeChangeInterceptor();
|
|
|
|
|
interceptor4.setParamName("theme2");
|
|
|
|
|
UserRoleAuthorizationInterceptor interceptor5 = new UserRoleAuthorizationInterceptor();
|
|
|
|
|
interceptor5.setAuthorizedRoles(new String[] {"role1", "role2"});
|
|
|
|
|
interceptor5.setAuthorizedRoles("role1", "role2");
|
|
|
|
|
|
|
|
|
|
List<Object> interceptors = new ArrayList<>();
|
|
|
|
|
interceptors.add(interceptor5);
|
|
|
|
|
@@ -100,8 +100,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
interceptors.add(new MyWebRequestInterceptor());
|
|
|
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues();
|
|
|
|
|
pvs.add(
|
|
|
|
|
"mappings", "/view.do=viewHandler\n/locale.do=localeHandler\nloc.do=anotherLocaleHandler");
|
|
|
|
|
pvs.add("mappings", "/view.do=viewHandler\n/locale.do=localeHandler\nloc.do=anotherLocaleHandler");
|
|
|
|
|
pvs.add("interceptors", interceptors);
|
|
|
|
|
registerSingleton("myUrlMapping1", SimpleUrlHandlerMapping.class, pvs);
|
|
|
|
|
|
|
|
|
|
@@ -124,7 +123,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
registerSingleton("noviewController", NoViewController.class);
|
|
|
|
|
|
|
|
|
|
pvs = new MutablePropertyValues();
|
|
|
|
|
pvs.add("order", new Integer(0));
|
|
|
|
|
pvs.add("order", 0);
|
|
|
|
|
pvs.add("basename", "org.springframework.web.servlet.complexviews");
|
|
|
|
|
registerSingleton("viewResolver", ResourceBundleViewResolver.class, pvs);
|
|
|
|
|
|
|
|
|
|
@@ -150,8 +149,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
pvs = new MutablePropertyValues();
|
|
|
|
|
pvs.add("order", "1");
|
|
|
|
|
pvs.add("exceptionMappings",
|
|
|
|
|
"java.lang.IllegalAccessException=failed2\n" +
|
|
|
|
|
"ServletRequestBindingException=failed3");
|
|
|
|
|
"java.lang.IllegalAccessException=failed2\n" +
|
|
|
|
|
"ServletRequestBindingException=failed3");
|
|
|
|
|
pvs.add("defaultErrorView", "failed0");
|
|
|
|
|
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs);
|
|
|
|
|
|
|
|
|
|
@@ -237,11 +236,11 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static interface MyHandler {
|
|
|
|
|
public interface MyHandler {
|
|
|
|
|
|
|
|
|
|
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException;
|
|
|
|
|
void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException;
|
|
|
|
|
|
|
|
|
|
public long lastModified();
|
|
|
|
|
long lastModified();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -259,7 +258,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object delegate)
|
|
|
|
|
throws ServletException, IllegalAccessException {
|
|
|
|
|
throws ServletException, IllegalAccessException {
|
|
|
|
|
|
|
|
|
|
((MyHandler) delegate).doSomething(request);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
@@ -295,7 +295,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
|
|
|
throws ServletException {
|
|
|
|
|
throws ServletException {
|
|
|
|
|
|
|
|
|
|
if (request.getAttribute("test2") != null) {
|
|
|
|
|
throw new ServletException("Wrong interceptor order");
|
|
|
|
|
}
|
|
|
|
|
@@ -309,6 +310,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
public void postHandle(
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
|
|
|
|
throws ServletException {
|
|
|
|
|
|
|
|
|
|
if (request.getAttribute("test2x") != null) {
|
|
|
|
|
throw new ServletException("Wrong interceptor order");
|
|
|
|
|
}
|
|
|
|
|
@@ -322,9 +324,13 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
public void afterCompletion(
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
|
|
|
|
throws ServletException {
|
|
|
|
|
|
|
|
|
|
if (request.getAttribute("test2y") != null) {
|
|
|
|
|
throw new ServletException("Wrong interceptor order");
|
|
|
|
|
}
|
|
|
|
|
if (request.getAttribute("test1y") == null) {
|
|
|
|
|
throw new ServletException("afterCompletion invoked twice");
|
|
|
|
|
}
|
|
|
|
|
request.removeAttribute("test1y");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -334,7 +340,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
|
|
|
throws ServletException {
|
|
|
|
|
throws ServletException {
|
|
|
|
|
|
|
|
|
|
if (request.getAttribute("test1x") == null) {
|
|
|
|
|
throw new ServletException("Wrong interceptor order");
|
|
|
|
|
}
|
|
|
|
|
@@ -351,6 +358,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
public void postHandle(
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
|
|
|
|
throws ServletException {
|
|
|
|
|
|
|
|
|
|
if (request.getParameter("noView") != null) {
|
|
|
|
|
modelAndView.clear();
|
|
|
|
|
}
|
|
|
|
|
@@ -367,9 +375,13 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|
|
|
|
public void afterCompletion(
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
if (request.getAttribute("test1y") == null) {
|
|
|
|
|
throw new ServletException("Wrong interceptor order");
|
|
|
|
|
}
|
|
|
|
|
if (request.getAttribute("test2y") == null) {
|
|
|
|
|
throw new ServletException("afterCompletion invoked twice");
|
|
|
|
|
}
|
|
|
|
|
request.removeAttribute("test2y");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|