|
|
|
@ -25,14 +25,14 @@ import java.util.LinkedList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletConfig; |
|
|
|
import javax.servlet.ServletConfig; |
|
|
|
import javax.servlet.ServletContext; |
|
|
|
import javax.servlet.ServletContext; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpSession; |
|
|
|
import javax.servlet.http.HttpSession; |
|
|
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; |
|
|
|
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; |
|
|
|
import org.springframework.aop.interceptor.SimpleTraceInterceptor; |
|
|
|
import org.springframework.aop.interceptor.SimpleTraceInterceptor; |
|
|
|
@ -55,6 +55,7 @@ import org.springframework.ui.Model; |
|
|
|
import org.springframework.ui.ModelMap; |
|
|
|
import org.springframework.ui.ModelMap; |
|
|
|
import org.springframework.validation.BindingResult; |
|
|
|
import org.springframework.validation.BindingResult; |
|
|
|
import org.springframework.validation.Errors; |
|
|
|
import org.springframework.validation.Errors; |
|
|
|
|
|
|
|
import org.springframework.web.bind.MissingServletRequestParameterException; |
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
import org.springframework.web.bind.annotation.InitBinder; |
|
|
|
import org.springframework.web.bind.annotation.InitBinder; |
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute; |
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute; |
|
|
|
@ -82,11 +83,11 @@ import org.springframework.web.util.NestedServletException; |
|
|
|
* @author Sam Brannen |
|
|
|
* @author Sam Brannen |
|
|
|
* @since 2.5 |
|
|
|
* @since 2.5 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
public class ServletAnnotationControllerTests { |
|
|
|
|
|
|
|
|
|
|
|
public void testStandardHandleMethod() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void standardHandleMethod() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class)); |
|
|
|
@ -102,7 +103,61 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("test", response.getContentAsString()); |
|
|
|
assertEquals("test", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testProxiedStandardHandleMethod() throws Exception { |
|
|
|
@Test(expected = MissingServletRequestParameterException.class) |
|
|
|
|
|
|
|
public void requiredParamMissing() throws Exception { |
|
|
|
|
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
|
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
|
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
|
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(RequiredParamController.class)); |
|
|
|
|
|
|
|
wac.refresh(); |
|
|
|
|
|
|
|
return wac; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
servlet.init(new MockServletConfig()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); |
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
|
|
|
servlet.service(request, response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void optionalParamMissing() throws Exception { |
|
|
|
|
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
|
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
|
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
|
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(OptionalParamController.class)); |
|
|
|
|
|
|
|
wac.refresh(); |
|
|
|
|
|
|
|
return wac; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
servlet.init(new MockServletConfig()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); |
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
|
|
|
servlet.service(request, response); |
|
|
|
|
|
|
|
assertEquals("null", response.getContentAsString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void defaultParamMissing() throws Exception { |
|
|
|
|
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
|
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
|
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
|
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(DefaultValueParamController.class)); |
|
|
|
|
|
|
|
wac.refresh(); |
|
|
|
|
|
|
|
return wac; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
servlet.init(new MockServletConfig()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); |
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
|
|
|
servlet.service(request, response); |
|
|
|
|
|
|
|
assertEquals("foo", response.getContentAsString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void proxiedStandardHandleMethod() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
@ -110,7 +165,8 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator(); |
|
|
|
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator(); |
|
|
|
autoProxyCreator.setBeanFactory(wac.getBeanFactory()); |
|
|
|
autoProxyCreator.setBeanFactory(wac.getBeanFactory()); |
|
|
|
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator); |
|
|
|
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator); |
|
|
|
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor())); |
|
|
|
wac.getBeanFactory() |
|
|
|
|
|
|
|
.registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor())); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
return wac; |
|
|
|
return wac; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -123,12 +179,13 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("test", response.getContentAsString()); |
|
|
|
assertEquals("test", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEmptyParameterListHandleMethod() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void emptyParameterListHandleMethod() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(EmptyParameterListHandlerMethodController.class)); |
|
|
|
wac.registerBeanDefinition("controller", |
|
|
|
|
|
|
|
new RootBeanDefinition(EmptyParameterListHandlerMethodController.class)); |
|
|
|
RootBeanDefinition vrDef = new RootBeanDefinition(InternalResourceViewResolver.class); |
|
|
|
RootBeanDefinition vrDef = new RootBeanDefinition(InternalResourceViewResolver.class); |
|
|
|
vrDef.getPropertyValues().addPropertyValue("suffix", ".jsp"); |
|
|
|
vrDef.getPropertyValues().addPropertyValue("suffix", ".jsp"); |
|
|
|
wac.registerBeanDefinition("viewResolver", vrDef); |
|
|
|
wac.registerBeanDefinition("viewResolver", vrDef); |
|
|
|
@ -147,21 +204,23 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("", response.getContentAsString()); |
|
|
|
assertEquals("", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testAdaptedHandleMethods() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void adaptedHandleMethods() throws Exception { |
|
|
|
doTestAdaptedHandleMethods(MyAdaptedController.class); |
|
|
|
doTestAdaptedHandleMethods(MyAdaptedController.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testAdaptedHandleMethods2() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void adaptedHandleMethods2() throws Exception { |
|
|
|
doTestAdaptedHandleMethods(MyAdaptedController2.class); |
|
|
|
doTestAdaptedHandleMethods(MyAdaptedController2.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testAdaptedHandleMethods3() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void adaptedHandleMethods3() throws Exception { |
|
|
|
doTestAdaptedHandleMethods(MyAdaptedController3.class); |
|
|
|
doTestAdaptedHandleMethods(MyAdaptedController3.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doTestAdaptedHandleMethods(final Class<?> controllerClass) throws Exception { |
|
|
|
private void doTestAdaptedHandleMethods(final Class<?> controllerClass) throws Exception { |
|
|
|
@SuppressWarnings("serial") |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
|
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass)); |
|
|
|
@ -204,9 +263,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("test-name1-typeMismatch", response.getContentAsString()); |
|
|
|
assertEquals("test-name1-typeMismatch", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testFormController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void formController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyFormController.class)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyFormController.class)); |
|
|
|
@ -225,9 +284,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString()); |
|
|
|
assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testModelFormController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void modelFormController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyModelFormController.class)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyModelFormController.class)); |
|
|
|
@ -246,7 +305,8 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString()); |
|
|
|
assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testProxiedFormController() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void proxiedFormController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
@ -255,7 +315,8 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator(); |
|
|
|
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator(); |
|
|
|
autoProxyCreator.setBeanFactory(wac.getBeanFactory()); |
|
|
|
autoProxyCreator.setBeanFactory(wac.getBeanFactory()); |
|
|
|
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator); |
|
|
|
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator); |
|
|
|
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor())); |
|
|
|
wac.getBeanFactory() |
|
|
|
|
|
|
|
.registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor())); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
return wac; |
|
|
|
return wac; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -270,12 +331,13 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString()); |
|
|
|
assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCommandProvidingFormController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void commandProvidingFormController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("controller", |
|
|
|
|
|
|
|
new RootBeanDefinition(MyCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class); |
|
|
|
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class); |
|
|
|
adapterDef.getPropertyValues().addPropertyValue("webBindingInitializer", new MyWebBindingInitializer()); |
|
|
|
adapterDef.getPropertyValues().addPropertyValue("webBindingInitializer", new MyWebBindingInitializer()); |
|
|
|
@ -295,16 +357,18 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString()); |
|
|
|
assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testTypedCommandProvidingFormController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void typedCommandProvidingFormController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyTypedCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("controller", |
|
|
|
|
|
|
|
new RootBeanDefinition(MyTypedCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class); |
|
|
|
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class); |
|
|
|
adapterDef.getPropertyValues().addPropertyValue("webBindingInitializer", new MyWebBindingInitializer()); |
|
|
|
adapterDef.getPropertyValues().addPropertyValue("webBindingInitializer", new MyWebBindingInitializer()); |
|
|
|
adapterDef.getPropertyValues().addPropertyValue("customArgumentResolver", new MySpecialArgumentResolver()); |
|
|
|
adapterDef.getPropertyValues() |
|
|
|
|
|
|
|
.addPropertyValue("customArgumentResolver", new MySpecialArgumentResolver()); |
|
|
|
wac.registerBeanDefinition("handlerAdapter", adapterDef); |
|
|
|
wac.registerBeanDefinition("handlerAdapter", adapterDef); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
return wac; |
|
|
|
return wac; |
|
|
|
@ -337,12 +401,13 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView-special-99-special-99", response.getContentAsString()); |
|
|
|
assertEquals("myView-special-99-special-99", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testBinderInitializingCommandProvidingFormController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void binderInitializingCommandProvidingFormController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyBinderInitializingCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("controller", |
|
|
|
|
|
|
|
new RootBeanDefinition(MyBinderInitializingCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
return wac; |
|
|
|
return wac; |
|
|
|
@ -359,12 +424,13 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString()); |
|
|
|
assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testSpecificBinderInitializingCommandProvidingFormController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void specificBinderInitializingCommandProvidingFormController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MySpecificBinderInitializingCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("controller", |
|
|
|
|
|
|
|
new RootBeanDefinition(MySpecificBinderInitializingCommandProvidingFormController.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
return wac; |
|
|
|
return wac; |
|
|
|
@ -381,12 +447,12 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString()); |
|
|
|
assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testParameterDispatchingController() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void parameterDispatchingController() throws Exception { |
|
|
|
final MockServletContext servletContext = new MockServletContext(); |
|
|
|
final MockServletContext servletContext = new MockServletContext(); |
|
|
|
final MockServletConfig servletConfig = new MockServletConfig(servletContext); |
|
|
|
final MockServletConfig servletConfig = new MockServletConfig(servletContext); |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("serial") |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
|
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.setServletContext(servletContext); |
|
|
|
wac.setServletContext(servletContext); |
|
|
|
@ -441,9 +507,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testMethodNameDispatchingController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void methodNameDispatchingController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MethodNameDispatchingController.class)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MethodNameDispatchingController.class)); |
|
|
|
@ -474,9 +540,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testMethodNameDispatchingControllerWithSuffix() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void methodNameDispatchingControllerWithSuffix() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MethodNameDispatchingController.class)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MethodNameDispatchingController.class)); |
|
|
|
@ -512,9 +578,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testControllerClassNamePlusMethodNameDispatchingController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void controllerClassNamePlusMethodNameDispatchingController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
RootBeanDefinition mapping = new RootBeanDefinition(ControllerClassNameHandlerMapping.class); |
|
|
|
RootBeanDefinition mapping = new RootBeanDefinition(ControllerClassNameHandlerMapping.class); |
|
|
|
@ -548,12 +614,13 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testPostMethodNameDispatchingController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void postMethodNameDispatchingController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyPostMethodNameDispatchingController.class)); |
|
|
|
wac.registerBeanDefinition("controller", |
|
|
|
|
|
|
|
new RootBeanDefinition(MyPostMethodNameDispatchingController.class)); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
return wac; |
|
|
|
return wac; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -596,12 +663,13 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testRelativePathDispatchingController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void relativePathDispatchingController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyRelativePathDispatchingController.class)); |
|
|
|
wac.registerBeanDefinition("controller", |
|
|
|
|
|
|
|
new RootBeanDefinition(MyRelativePathDispatchingController.class)); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
return wac; |
|
|
|
return wac; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -629,9 +697,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
assertEquals("mySurpriseView", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testNullCommandController() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void nullCommandController() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyNullCommandController.class)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyNullCommandController.class)); |
|
|
|
@ -648,9 +716,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
assertEquals("myView", response.getContentAsString()); |
|
|
|
assertEquals("myView", response.getContentAsString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEquivalentMappingsWithSameMethodName() throws Exception { |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public void equivalentMappingsWithSameMethodName() throws Exception { |
|
|
|
DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) { |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(ChildController.class)); |
|
|
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(ChildController.class)); |
|
|
|
@ -672,128 +740,126 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
private static class MyController extends AbstractController { |
|
|
|
private static class MyController extends AbstractController { |
|
|
|
|
|
|
|
|
|
|
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) |
|
|
|
|
|
|
|
throws Exception { |
|
|
|
response.getWriter().write("test"); |
|
|
|
response.getWriter().write("test"); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class BaseController { |
|
|
|
private static class BaseController { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
public void myPath2(HttpServletResponse response) throws IOException { |
|
|
|
public void myPath2(HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test"); |
|
|
|
response.getWriter().write("test"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
private static class MyAdaptedController { |
|
|
|
private static class MyAdaptedController { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath1.do") |
|
|
|
@RequestMapping("/myPath1.do") |
|
|
|
public void myHandle(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test"); |
|
|
|
response.getWriter().write("test"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath2.do") |
|
|
|
@RequestMapping("/myPath2.do") |
|
|
|
public void myHandle(@RequestParam("param1") String p1, @RequestParam("param2") int p2, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(@RequestParam("param1")String p1, |
|
|
|
|
|
|
|
@RequestParam("param2")int p2, |
|
|
|
|
|
|
|
HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + p1 + "-" + p2); |
|
|
|
response.getWriter().write("test-" + p1 + "-" + p2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath3") |
|
|
|
@RequestMapping("/myPath3") |
|
|
|
public void myHandle(TestBean tb, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(TestBean tb, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + tb.getAge()); |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath4.do") |
|
|
|
@RequestMapping("/myPath4.do") |
|
|
|
public void myHandle(TestBean tb, Errors errors, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(TestBean tb, Errors errors, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + errors.getFieldError("age").getCode()); |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + errors.getFieldError("age").getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
@RequestMapping("/*.do") |
|
|
|
@RequestMapping("/*.do") |
|
|
|
private static class MyAdaptedController2 { |
|
|
|
private static class MyAdaptedController2 { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping |
|
|
|
@RequestMapping |
|
|
|
public void myHandle(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test"); |
|
|
|
response.getWriter().write("test"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath2.do") |
|
|
|
@RequestMapping("/myPath2.do") |
|
|
|
public void myHandle(@RequestParam("param1") String p1, int param2, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(@RequestParam("param1")String p1, int param2, HttpServletResponse response) |
|
|
|
|
|
|
|
throws IOException { |
|
|
|
response.getWriter().write("test-" + p1 + "-" + param2); |
|
|
|
response.getWriter().write("test-" + p1 + "-" + param2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath3") |
|
|
|
@RequestMapping("/myPath3") |
|
|
|
public void myHandle(TestBean tb, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(TestBean tb, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + tb.getAge()); |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath4.*") |
|
|
|
@RequestMapping("/myPath4.*") |
|
|
|
public void myHandle(TestBean tb, Errors errors, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(TestBean tb, Errors errors, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + errors.getFieldError("age").getCode()); |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + errors.getFieldError("age").getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
private static class MyAdaptedControllerBase<T> { |
|
|
|
private static class MyAdaptedControllerBase<T> { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath2.do") |
|
|
|
@RequestMapping("/myPath2.do") |
|
|
|
public void myHandle(@RequestParam("param1") T p1, int param2, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(@RequestParam("param1")T p1, int param2, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + p1 + "-" + param2); |
|
|
|
response.getWriter().write("test-" + p1 + "-" + param2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@InitBinder |
|
|
|
@InitBinder |
|
|
|
public void initBinder(@RequestParam("param1") T p1, int param2) { |
|
|
|
public void initBinder(@RequestParam("param1")T p1, int param2) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ModelAttribute |
|
|
|
@ModelAttribute |
|
|
|
public void modelAttribute(@RequestParam("param1") T p1, int param2) { |
|
|
|
public void modelAttribute(@RequestParam("param1")T p1, int param2) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/*.do") |
|
|
|
@RequestMapping("/*.do") |
|
|
|
private static class MyAdaptedController3 extends MyAdaptedControllerBase<String> { |
|
|
|
private static class MyAdaptedController3 extends MyAdaptedControllerBase<String> { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping |
|
|
|
@RequestMapping |
|
|
|
public void myHandle(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test"); |
|
|
|
response.getWriter().write("test"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void myHandle(@RequestParam("param1") String p1, int param2, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(@RequestParam("param1")String p1, int param2, HttpServletResponse response) |
|
|
|
|
|
|
|
throws IOException { |
|
|
|
response.getWriter().write("test-" + p1 + "-" + param2); |
|
|
|
response.getWriter().write("test-" + p1 + "-" + param2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath3") |
|
|
|
@RequestMapping("/myPath3") |
|
|
|
public void myHandle(TestBean tb, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(TestBean tb, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + tb.getAge()); |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath4.*") |
|
|
|
@RequestMapping("/myPath4.*") |
|
|
|
public void myHandle(TestBean tb, Errors errors, HttpServletResponse response) throws IOException { |
|
|
|
public void myHandle(TestBean tb, Errors errors, HttpServletResponse response) throws IOException { |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + errors.getFieldError("age").getCode()); |
|
|
|
response.getWriter().write("test-" + tb.getName() + "-" + errors.getFieldError("age").getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@InitBinder |
|
|
|
@InitBinder |
|
|
|
public void initBinder(@RequestParam("param1") String p1, int param2) { |
|
|
|
public void initBinder(@RequestParam("param1")String p1, int param2) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ModelAttribute |
|
|
|
@ModelAttribute |
|
|
|
public void modelAttribute(@RequestParam("param1") String p1, int param2) { |
|
|
|
public void modelAttribute(@RequestParam("param1")String p1, int param2) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
private static class EmptyParameterListHandlerMethodController { |
|
|
|
private static class EmptyParameterListHandlerMethodController { |
|
|
|
@ -810,7 +876,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
public static class MyFormController { |
|
|
|
public static class MyFormController { |
|
|
|
|
|
|
|
|
|
|
|
@ -823,7 +888,7 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
public String myHandle(@ModelAttribute("myCommand") TestBean tb, BindingResult errors, ModelMap model) { |
|
|
|
public String myHandle(@ModelAttribute("myCommand")TestBean tb, BindingResult errors, ModelMap model) { |
|
|
|
if (!model.containsKey("myKey")) { |
|
|
|
if (!model.containsKey("myKey")) { |
|
|
|
model.addAttribute("myKey", "myValue"); |
|
|
|
model.addAttribute("myKey", "myValue"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -831,7 +896,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
public static class MyModelFormController { |
|
|
|
public static class MyModelFormController { |
|
|
|
|
|
|
|
|
|
|
|
@ -844,7 +908,7 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
public String myHandle(@ModelAttribute("myCommand") TestBean tb, BindingResult errors, Model model) { |
|
|
|
public String myHandle(@ModelAttribute("myCommand")TestBean tb, BindingResult errors, Model model) { |
|
|
|
if (!model.containsAttribute("myKey")) { |
|
|
|
if (!model.containsAttribute("myKey")) { |
|
|
|
model.addAttribute("myKey", "myValue"); |
|
|
|
model.addAttribute("myKey", "myValue"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -852,20 +916,20 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
private static class MyCommandProvidingFormController<T, TB, TB2> extends MyFormController { |
|
|
|
private static class MyCommandProvidingFormController<T, TB, TB2> extends MyFormController { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
@ModelAttribute("myCommand") |
|
|
|
@ModelAttribute("myCommand") |
|
|
|
private TestBean createTestBean( |
|
|
|
private TestBean createTestBean(@RequestParam T defaultName, |
|
|
|
@RequestParam T defaultName, Map<String, Object> model, @RequestParam Date date) { |
|
|
|
Map<String, Object> model, |
|
|
|
|
|
|
|
@RequestParam Date date) { |
|
|
|
model.put("myKey", "myOriginalValue"); |
|
|
|
model.put("myKey", "myOriginalValue"); |
|
|
|
return new TestBean(defaultName.getClass().getSimpleName() + ":" + defaultName.toString()); |
|
|
|
return new TestBean(defaultName.getClass().getSimpleName() + ":" + defaultName.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
public String myHandle(@ModelAttribute("myCommand") TestBean tb, BindingResult errors, ModelMap model) { |
|
|
|
public String myHandle(@ModelAttribute("myCommand")TestBean tb, BindingResult errors, ModelMap model) { |
|
|
|
return super.myHandle(tb, errors, model); |
|
|
|
return super.myHandle(tb, errors, model); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -890,19 +954,17 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class MySpecialArg { |
|
|
|
private static class MySpecialArg { |
|
|
|
|
|
|
|
|
|
|
|
public MySpecialArg(String value) { |
|
|
|
public MySpecialArg(String value) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
private static class MyTypedCommandProvidingFormController |
|
|
|
private static class MyTypedCommandProvidingFormController |
|
|
|
extends MyCommandProvidingFormController<Integer, TestBean, ITestBean> { |
|
|
|
extends MyCommandProvidingFormController<Integer, TestBean, ITestBean> { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
private static class MyBinderInitializingCommandProvidingFormController extends MyCommandProvidingFormController { |
|
|
|
private static class MyBinderInitializingCommandProvidingFormController extends MyCommandProvidingFormController { |
|
|
|
@ -917,13 +979,13 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
private static class MySpecificBinderInitializingCommandProvidingFormController extends MyCommandProvidingFormController { |
|
|
|
private static class MySpecificBinderInitializingCommandProvidingFormController |
|
|
|
|
|
|
|
extends MyCommandProvidingFormController { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
@InitBinder({"myCommand", "date"}) |
|
|
|
@InitBinder({"myCommand", "date"}) |
|
|
|
private void initBinder(WebDataBinder binder, String date, @RequestParam("date") String[] date2) { |
|
|
|
private void initBinder(WebDataBinder binder, String date, @RequestParam("date")String[] date2) { |
|
|
|
assertEquals("2007-10-02", date); |
|
|
|
assertEquals("2007-10-02", date); |
|
|
|
assertEquals(1, date2.length); |
|
|
|
assertEquals(1, date2.length); |
|
|
|
assertEquals("2007-10-02", date2[0]); |
|
|
|
assertEquals("2007-10-02", date2[0]); |
|
|
|
@ -933,7 +995,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class MyWebBindingInitializer implements WebBindingInitializer { |
|
|
|
private static class MyWebBindingInitializer implements WebBindingInitializer { |
|
|
|
|
|
|
|
|
|
|
|
public void initBinder(WebDataBinder binder, WebRequest request) { |
|
|
|
public void initBinder(WebDataBinder binder, WebRequest request) { |
|
|
|
@ -944,7 +1005,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class MySpecialArgumentResolver implements WebArgumentResolver { |
|
|
|
private static class MySpecialArgumentResolver implements WebArgumentResolver { |
|
|
|
|
|
|
|
|
|
|
|
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) { |
|
|
|
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) { |
|
|
|
@ -955,7 +1015,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
private static class MyParameterDispatchingController { |
|
|
|
private static class MyParameterDispatchingController { |
|
|
|
@ -974,7 +1033,8 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping |
|
|
|
@RequestMapping |
|
|
|
public void myHandle(HttpServletResponse response, HttpServletRequest request) throws IOException { |
|
|
|
public void myHandle(HttpServletResponse response, HttpServletRequest request) throws IOException { |
|
|
|
if (this.servletContext == null || this.servletConfig == null || this.session == null || this.request == null) { |
|
|
|
if (this.servletContext == null || this.servletConfig == null || this.session == null || |
|
|
|
|
|
|
|
this.request == null) { |
|
|
|
throw new IllegalStateException(); |
|
|
|
throw new IllegalStateException(); |
|
|
|
} |
|
|
|
} |
|
|
|
response.getWriter().write("myView"); |
|
|
|
response.getWriter().write("myView"); |
|
|
|
@ -1000,14 +1060,12 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
@RequestMapping(value = "/*.do", method = RequestMethod.POST, params = "myParam=myValue") |
|
|
|
@RequestMapping(value = "/*.do", method = RequestMethod.POST, params = "myParam=myValue") |
|
|
|
private static class MyPostMethodNameDispatchingController extends MethodNameDispatchingController { |
|
|
|
private static class MyPostMethodNameDispatchingController extends MethodNameDispatchingController { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
@RequestMapping("/myApp/*") |
|
|
|
@RequestMapping("/myApp/*") |
|
|
|
private static class MyRelativePathDispatchingController { |
|
|
|
private static class MyRelativePathDispatchingController { |
|
|
|
@ -1033,7 +1091,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
private static class MyNullCommandController { |
|
|
|
private static class MyNullCommandController { |
|
|
|
|
|
|
|
|
|
|
|
@ -1048,8 +1105,11 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath") |
|
|
|
@RequestMapping("/myPath") |
|
|
|
public void handle(@ModelAttribute TestBean testBean, Errors errors, |
|
|
|
public void handle(@ModelAttribute TestBean testBean, |
|
|
|
@ModelAttribute TestPrincipal modelPrinc, OtherPrincipal requestPrinc, Writer writer) throws IOException { |
|
|
|
Errors errors, |
|
|
|
|
|
|
|
@ModelAttribute TestPrincipal modelPrinc, |
|
|
|
|
|
|
|
OtherPrincipal requestPrinc, |
|
|
|
|
|
|
|
Writer writer) throws IOException { |
|
|
|
assertNull(testBean); |
|
|
|
assertNull(testBean); |
|
|
|
assertNotNull(modelPrinc); |
|
|
|
assertNotNull(modelPrinc); |
|
|
|
assertNotNull(requestPrinc); |
|
|
|
assertNotNull(requestPrinc); |
|
|
|
@ -1059,7 +1119,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class TestPrincipal implements Principal { |
|
|
|
private static class TestPrincipal implements Principal { |
|
|
|
|
|
|
|
|
|
|
|
public String getName() { |
|
|
|
public String getName() { |
|
|
|
@ -1067,7 +1126,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class OtherPrincipal implements Principal { |
|
|
|
private static class OtherPrincipal implements Principal { |
|
|
|
|
|
|
|
|
|
|
|
public String getName() { |
|
|
|
public String getName() { |
|
|
|
@ -1075,7 +1133,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class TestViewResolver implements ViewResolver { |
|
|
|
private static class TestViewResolver implements ViewResolver { |
|
|
|
|
|
|
|
|
|
|
|
public View resolveViewName(final String viewName, Locale locale) throws Exception { |
|
|
|
public View resolveViewName(final String viewName, Locale locale) throws Exception { |
|
|
|
@ -1083,8 +1140,10 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
public String getContentType() { |
|
|
|
public String getContentType() { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked", "deprecation"}) |
|
|
|
@SuppressWarnings({"unchecked", "deprecation"}) |
|
|
|
public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
public void render(Map model, HttpServletRequest request, HttpServletResponse response) |
|
|
|
|
|
|
|
throws Exception { |
|
|
|
TestBean tb = (TestBean) model.get("testBean"); |
|
|
|
TestBean tb = (TestBean) model.get("testBean"); |
|
|
|
if (tb == null) { |
|
|
|
if (tb == null) { |
|
|
|
tb = (TestBean) model.get("myCommand"); |
|
|
|
tb = (TestBean) model.get("myCommand"); |
|
|
|
@ -1104,8 +1163,9 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
List<TestBean> testBeans = (List<TestBean>) model.get("testBeanList"); |
|
|
|
List<TestBean> testBeans = (List<TestBean>) model.get("testBeanList"); |
|
|
|
if (errors.hasFieldErrors("age")) { |
|
|
|
if (errors.hasFieldErrors("age")) { |
|
|
|
response.getWriter().write(viewName + "-" + tb.getName() + "-" + errors.getFieldError("age").getCode() + |
|
|
|
response.getWriter().write(viewName + "-" + tb.getName() + "-" + |
|
|
|
"-" + testBeans.get(0).getName() + "-" + model.get("myKey")); |
|
|
|
errors.getFieldError("age").getCode() + "-" + testBeans.get(0).getName() + "-" + |
|
|
|
|
|
|
|
model.get("myKey")); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
response.getWriter().write(viewName + "-" + tb.getName() + "-" + tb.getAge() + "-" + |
|
|
|
response.getWriter().write(viewName + "-" + tb.getName() + "-" + tb.getAge() + "-" + |
|
|
|
@ -1116,7 +1176,6 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class ParentController { |
|
|
|
public static class ParentController { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
@ -1124,13 +1183,41 @@ public class ServletAnnotationControllerTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
@Controller |
|
|
|
@RequestMapping("/child/test") |
|
|
|
@RequestMapping("/child/test") |
|
|
|
public static class ChildController extends ParentController { |
|
|
|
public static class ChildController extends ParentController { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
public void doGet(HttpServletRequest req, HttpServletResponse resp, @RequestParam("childId") String id) { |
|
|
|
public void doGet(HttpServletRequest req, HttpServletResponse resp, @RequestParam("childId")String id) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
|
|
|
public static class RequiredParamController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
|
|
|
|
public void myHandle(@RequestParam(value = "id", required = true)String id) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
|
|
|
public static class OptionalParamController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
|
|
|
|
public void myHandle(@RequestParam(value = "id", required = false)String id, HttpServletResponse response) |
|
|
|
|
|
|
|
throws IOException { |
|
|
|
|
|
|
|
response.getWriter().write(String.valueOf(id)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
|
|
|
public static class DefaultValueParamController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/myPath.do") |
|
|
|
|
|
|
|
public void myHandle(@RequestParam(value = "id", defaultValue = "foo")String id, HttpServletResponse response) |
|
|
|
|
|
|
|
throws IOException { |
|
|
|
|
|
|
|
response.getWriter().write(String.valueOf(id)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|