use of org.springframework.web.context.request.ServletWebRequest in project com.revolsys.open by revolsys.
the class RecordReaderHttpMessageConverter method read.
@Override
public RecordReader read(final Class<? extends RecordReader> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final RecordReaderFactory readerFactory = IoFactory.factoryByMediaType(RecordReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final Reader<Record> reader = readerFactory.newRecordReader(new InputStreamResource("recordInput", body));
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
return (RecordReader) reader;
}
} catch (final IOException e) {
throw new HttpMessageNotReadableException("Error reading data", e);
}
}
use of org.springframework.web.context.request.ServletWebRequest in project com.revolsys.open by revolsys.
the class WebAnnotationMethodHandlerAdapter method invokeHandlerMethod.
protected ModelAndView invokeHandlerMethod(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
final AnnotationHandlerMethodResolver methodResolver = getMethodResolver(handler);
final WebMethodHandler handlerMethod = methodResolver.resolveHandlerMethod(request);
final ServletWebRequest webRequest = new ServletWebRequest(request, response);
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
try {
RequestContextHolder.setRequestAttributes(webRequest);
final ExtendedModelMap implicitModel = new BindingAwareModelMap();
final Object result = handlerMethod.invokeMethod(handler, request, response);
if (result == null) {
return null;
} else {
final ModelAndView mav = getModelAndView(handlerMethod.getMethod(), handler.getClass(), result, implicitModel, webRequest);
return mav;
}
} finally {
RequestContextHolder.setRequestAttributes(requestAttributes);
}
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-data-commons by spring-projects.
the class PageableHandlerMethodArgumentResolverUnitTests method returnsCorrectPageSizeForOneIndexParameters.
// DATACMNS-761
@Test
public void returnsCorrectPageSizeForOneIndexParameters() {
PageableHandlerMethodArgumentResolver resolver = getResolver();
resolver.setOneIndexedParameters(true);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("size", "10");
Pageable result = resolver.resolveArgument(supportedMethodParameter, null, new ServletWebRequest(request), null);
assertThat(result.getPageSize()).isEqualTo(10);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-data-commons by spring-projects.
the class PageableHandlerMethodArgumentResolverUnitTests method considersOneIndexedParametersSetting.
// DATACMNS-563
@Test
public void considersOneIndexedParametersSetting() {
PageableHandlerMethodArgumentResolver resolver = getResolver();
resolver.setOneIndexedParameters(true);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("page", "1");
assertThat(resolver.resolveArgument(supportedMethodParameter, null, new ServletWebRequest(request), null).getPageNumber()).isEqualTo(0);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-data-commons by spring-projects.
the class SortHandlerMethodArgumentResolverUnitTests method returnsNullForSortParameterSetToNothing.
@Test
public void returnsNullForSortParameterSetToNothing() throws Exception {
MethodParameter parameter = getParameterOfMethod("supportedMethod");
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("sort", (String) null);
SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();
Sort result = resolver.resolveArgument(parameter, null, new ServletWebRequest(request), null);
assertThat(result.isSorted()).isFalse();
}
Aggregations