Search in sources :

Example 1 with IncomingRequest

use of org.springframework.data.rest.webmvc.IncomingRequest in project CzechIdMng by bcvsolutions.

the class RequestResourceResolver method resolve.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T resolve(HttpServletRequest nativeRequest, Class<T> domainType, T objectToUpdate) throws HttpMessageNotReadableException {
    ServletServerHttpRequest request = new ServletServerHttpRequest(nativeRequest);
    IncomingRequest incoming = new IncomingRequest(request);
    MediaType contentType = request.getHeaders().getContentType();
    for (HttpMessageConverter converter : messageConverters) {
        if (!converter.canRead(PersistentEntityResource.class, contentType)) {
            continue;
        }
        T obj = (T) read(domainType, incoming, converter, objectToUpdate);
        if (obj == null) {
            throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, domainType));
        }
        return obj;
    }
    throw new HttpMessageNotReadableException(String.format(NO_CONVERTER_FOUND, domainType, contentType));
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) PersistentEntityResource(org.springframework.data.rest.webmvc.PersistentEntityResource) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MediaType(org.springframework.http.MediaType) IncomingRequest(org.springframework.data.rest.webmvc.IncomingRequest)

Aggregations

IncomingRequest (org.springframework.data.rest.webmvc.IncomingRequest)1 PersistentEntityResource (org.springframework.data.rest.webmvc.PersistentEntityResource)1 MediaType (org.springframework.http.MediaType)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1