use of org.springframework.http.HttpInputMessage in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
RequestPart requestPart = parameter.getParameterAnnotation(RequestPart.class);
boolean isRequired = ((requestPart == null || requestPart.required()) && !parameter.isOptional());
String name = getPartName(parameter, requestPart);
parameter = parameter.nestedIfOptional();
Object arg = null;
Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest);
if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) {
arg = mpArg;
} else {
try {
HttpInputMessage inputMessage = new RequestPartServletServerHttpRequest(servletRequest, name);
arg = readWithMessageConverters(inputMessage, parameter, parameter.getNestedGenericParameterType());
WebDataBinder binder = binderFactory.createBinder(request, arg, name);
if (arg != null) {
validateIfApplicable(binder, parameter);
if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
throw new MethodArgumentNotValidException(parameter, binder.getBindingResult());
}
}
mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());
} catch (MissingServletRequestPartException ex) {
if (isRequired) {
throw ex;
}
} catch (MultipartException ex) {
if (isRequired) {
throw ex;
}
}
}
if (arg == null && isRequired) {
if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
throw new MultipartException("Current request is not a multipart request");
} else {
throw new MissingServletRequestPartException(name);
}
}
return adaptArgumentIfNecessary(arg, parameter);
}
use of org.springframework.http.HttpInputMessage in project geode by apache.
the class SerializableObjectHttpMessageConverterJUnitTest method testReadInternal.
@Test
public void testReadInternal() throws IOException {
final String expectedInputMessageBody = "Expected content of the HTTP input message body!";
final HttpInputMessage mockInputMessage = mockContext.mock(HttpInputMessage.class, "HttpInputMessage");
mockContext.checking(new Expectations() {
{
oneOf(mockInputMessage).getBody();
will(returnValue(new ByteArrayInputStream(IOUtils.serializeObject(expectedInputMessageBody))));
}
});
final SerializableObjectHttpMessageConverter converter = new SerializableObjectHttpMessageConverter();
final Serializable obj = converter.readInternal(String.class, mockInputMessage);
assertTrue(obj instanceof String);
assertEquals(expectedInputMessageBody, obj);
}
Aggregations