Browse Source

Fix issues encountered in Greenhouse

pull/7/head
Rossen Stoyanchev 14 years ago
parent
commit
36970115ed
  1. 8
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandler.java
  2. 7
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/ServletRequestMethodArgumentResolver.java
  3. 12
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandlerTests.java
  4. 16
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/ServletRequestMethodArgumentResolverTests.java

8
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandler.java

@ -79,10 +79,12 @@ public class DefaultMethodReturnValueHandler implements HandlerMethodReturnValue @@ -79,10 +79,12 @@ public class DefaultMethodReturnValueHandler implements HandlerMethodReturnValue
else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
mavContainer.addAttribute(name, returnValue);
return;
}
else {
// should not happen
throw new UnsupportedOperationException();
}
// should not happen
throw new UnsupportedOperationException();
}
}

7
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/support/ServletRequestMethodArgumentResolver.java

@ -29,6 +29,7 @@ import javax.servlet.http.HttpSession; @@ -29,6 +29,7 @@ import javax.servlet.http.HttpSession;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.multipart.MultipartRequest;
@ -43,7 +44,8 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume @@ -43,7 +44,8 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
public boolean supportsParameter(MethodParameter parameter) {
Class<?> parameterType = parameter.getParameterType();
return ServletRequest.class.isAssignableFrom(parameterType) ||
return WebRequest.class.isAssignableFrom(parameterType) ||
ServletRequest.class.isAssignableFrom(parameterType) ||
MultipartRequest.class.isAssignableFrom(parameterType) ||
HttpSession.class.isAssignableFrom(parameterType) || Principal.class.isAssignableFrom(parameterType) ||
Locale.class.equals(parameterType) || InputStream.class.isAssignableFrom(parameterType) ||
@ -61,6 +63,9 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume @@ -61,6 +63,9 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
Class<?> parameterType = parameter.getParameterType();
if (WebRequest.class.isAssignableFrom(parameterType)) {
return webRequest;
}
if (ServletRequest.class.isAssignableFrom(parameterType) ||
MultipartRequest.class.isAssignableFrom(parameterType)) {
Object nativeRequest = webRequest.getNativeRequest(parameterType);

12
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/DefaultMethodReturnValueHandlerTests.java

@ -23,6 +23,7 @@ import java.lang.reflect.Method; @@ -23,6 +23,7 @@ import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.TestBean;
import org.springframework.core.MethodParameter;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.ui.ExtendedModelMap;
@ -61,6 +62,12 @@ public class DefaultMethodReturnValueHandlerTests { @@ -61,6 +62,12 @@ public class DefaultMethodReturnValueHandlerTests {
assertNull(mavContainer.getViewName());
assertTrue(mavContainer.getModel().isEmpty());
}
@Test
public void returnSingleModelAttribute() throws Exception{
handler.handleReturnValue(new TestBean(), createMethodParam("singleModelAttribute"), mavContainer, webRequest);
assertTrue(mavContainer.containsAttribute("testBean"));
}
private MethodParameter createMethodParam(String methodName) throws Exception {
Method method = getClass().getDeclaredMethod(methodName);
@ -76,4 +83,9 @@ public class DefaultMethodReturnValueHandlerTests { @@ -76,4 +83,9 @@ public class DefaultMethodReturnValueHandlerTests {
private void voidReturnValue() {
}
@SuppressWarnings("unused")
private TestBean singleModelAttribute() {
return null;
}
}

16
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/support/ServletRequestMethodArgumentResolverTests.java

@ -32,6 +32,7 @@ import org.springframework.mock.web.MockHttpServletRequest; @@ -32,6 +32,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.servlet.mvc.method.annotation.support.ServletRequestMethodArgumentResolver;
@ -55,7 +56,7 @@ public class ServletRequestMethodArgumentResolverTests { @@ -55,7 +56,7 @@ public class ServletRequestMethodArgumentResolverTests {
resolver = new ServletRequestMethodArgumentResolver();
supportedParams = getClass()
.getMethod("supportedParams", ServletRequest.class, MultipartRequest.class, HttpSession.class,
Principal.class, Locale.class, InputStream.class, Reader.class);
Principal.class, Locale.class, InputStream.class, Reader.class, WebRequest.class);
servletRequest = new MockHttpServletRequest();
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
}
@ -135,13 +136,24 @@ public class ServletRequestMethodArgumentResolverTests { @@ -135,13 +136,24 @@ public class ServletRequestMethodArgumentResolverTests {
assertSame("Invalid result", webRequest.getRequest().getReader(), result);
}
@Test
public void webRequest() throws Exception {
MethodParameter webRequestParameter = new MethodParameter(supportedParams, 7);
assertTrue("WebRequest not supported", resolver.supportsParameter(webRequestParameter));
Object result = resolver.resolveArgument(webRequestParameter, null, webRequest, null);
assertSame("Invalid result", webRequest, result);
}
public void supportedParams(ServletRequest p0,
MultipartRequest p1,
HttpSession p2,
Principal p3,
Locale p4,
InputStream p5,
Reader p9) {
Reader p6,
WebRequest p7) {
}
}

Loading…
Cancel
Save