Example usage for org.springframework.http.converter HttpMessageNotReadableException HttpMessageNotReadableException

List of usage examples for org.springframework.http.converter HttpMessageNotReadableException HttpMessageNotReadableException

Introduction

In this page you can find the example usage for org.springframework.http.converter HttpMessageNotReadableException HttpMessageNotReadableException.

Prototype

@Deprecated
public HttpMessageNotReadableException(String msg) 

Source Link

Document

Create a new HttpMessageNotReadableException.

Usage

From source file:com.epam.ta.reportportal.ws.exception.rest.ExceptionHandlingTest.java

@Parameterized.Parameters(name = "{index}:{0},{1},{2}")
public static List<Object[]> getParameters() {
    return Arrays.asList(new Object[][] {
            { new ReportPortalException(EXCEPTION_MESSAGE), ErrorType.UNCLASSIFIED_REPORT_PORTAL_ERROR,
                    HttpStatus.INTERNAL_SERVER_ERROR, EXCEPTION_MESSAGE },
            { new RuntimeException(EXCEPTION_MESSAGE), ErrorType.UNCLASSIFIED_ERROR,
                    HttpStatus.INTERNAL_SERVER_ERROR, EXCEPTION_MESSAGE },
            { new HttpMessageNotReadableException(EXCEPTION_MESSAGE), ErrorType.INCORRECT_REQUEST,
                    HttpStatus.BAD_REQUEST, EXCEPTION_MESSAGE },
            { new MissingServletRequestParameterException("test", "test"), ErrorType.INCORRECT_REQUEST,
                    HttpStatus.BAD_REQUEST, "Required test parameter 'test' is not present" } });
}

From source file:nl.flotsam.calendar.web.UriListHttpMessageConverter.java

@Override
protected List<URI> readInternal(Class<? extends List<URI>> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {
    InputStream in = inputMessage.getBody();
    try {// www . j  a  v a  2s  .c  om
        String text = IOUtils.toString(in, "UTF-8");
        List<URI> result = parseURIs(text);
        logger.info("Produced a list of " + result.size() + " items: " + result);
        return result;
    } catch (URISyntaxException e) {
        throw new HttpMessageNotReadableException("Illegal URI in list of URIs: " + e.getInput());
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.btmatthews.leabharlann.view.FileContentMessageConverter.java

/**
 * Always throws {@link HttpMessageNotReadableException} to indicate that reading {@link FileContent} descriptors is
 * not supported./*from  ww w  . j av a  2  s .c o m*/
 *
 * @param clazz        A class description.
 * @param inputMessage Used to access the servlet request headers and input stream.
 * @return Always throws an exception.
 * @throws HttpMessageNotReadableException Indicates that a {@link FileContent} cannot be read.
 */
@Override
protected FileContent readInternal(final Class<? extends FileContent> clazz,
        final HttpInputMessage inputMessage) throws HttpMessageNotReadableException {
    throw new HttpMessageNotReadableException("Cannot read messages of this type");
}

From source file:org.hobsoft.symmetry.spring.SymmetryHttpMessageConverter.java

@Override
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException {
    throw new HttpMessageNotReadableException("SymmetryHttpMessageConverter cannot read components");
}

From source file:org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    RootResourceInformation resourceInformation = resourceInformationResolver.resolveArgument(parameter,
            mavContainer, webRequest, binderFactory);

    HttpServletRequest nativeRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    ServletServerHttpRequest request = new ServletServerHttpRequest(nativeRequest);
    IncomingRequest incoming = new IncomingRequest(request);

    Class<?> domainType = resourceInformation.getDomainType();
    MediaType contentType = request.getHeaders().getContentType();

    for (HttpMessageConverter converter : messageConverters) {

        if (!converter.canRead(PersistentEntityResource.class, contentType)) {
            continue;
        }// w  w  w .  j av a 2 s . c om

        Serializable id = idResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory);
        Object objectToUpdate = getObjectToUpdate(id, resourceInformation);

        boolean forUpdate = false;
        Object entityIdentifier = null;
        PersistentEntity<?, ?> entity = resourceInformation.getPersistentEntity();

        if (objectToUpdate != null) {
            forUpdate = true;
            entityIdentifier = entity.getIdentifierAccessor(objectToUpdate).getIdentifier();
        }

        Object obj = read(resourceInformation, incoming, converter, objectToUpdate);

        if (obj == null) {
            throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, domainType));
        }

        if (entityIdentifier != null) {
            entity.getPropertyAccessor(obj).setProperty(entity.getIdProperty(), entityIdentifier);
        }

        Builder build = PersistentEntityResource.build(obj, entity);
        return forUpdate ? build.build() : build.forCreation();
    }

    throw new HttpMessageNotReadableException(String.format(NO_CONVERTER_FOUND, domainType, contentType));
}

From source file:hornet.framework.web.converter.AbstractHornetHttpMessageConverter.java

/**
 * Le read n'est pas implment (impossible de convertir un PDF, XLS, .. vers un bean Java)
 *///from w  w  w. j av a  2s.c  o  m
@Override
protected T readInternal(final Class<? extends T> clazz, final HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {

    throw new HttpMessageNotReadableException(
            "Import Non implment : ce MessageConverter ne gre que l'export");
}

From source file:com.monarchapis.driver.spring.rest.ApiErrorResponseEntityExceptionHandlerTest.java

@Test
public void testHttpMessageNotReadableException() {
    performTest(//
            new HttpMessageNotReadableException("test"), //
            400, //
            "messageNotReadable");
}

From source file:org.geoserver.rest.converters.InputStreamConverter.java

@Override
protected InputStream readInternal(Class<? extends InputStream> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {
    throw new HttpMessageNotReadableException(getClass().getName() + " does not support deserialization");
}

From source file:org.waterforpeople.mapping.app.web.rest.PlacemarkDetailsRestService.java

@RequestMapping(method = RequestMethod.GET, value = "")
@ResponseBody/*  w w  w.  j  av a2 s . c  o m*/
public Map<String, Object> getDetails(
        @RequestParam(value = "placemarkId", defaultValue = "") String placemarkId) {

    if (StringUtils.isEmpty(placemarkId)) {
        final String msg = "[placemarkId] is a required parameter";
        log.log(Level.SEVERE, msg);
        throw new HttpMessageNotReadableException(msg);
    }

    final SurveyedLocale sl = localeDao.getById(Long.valueOf(placemarkId));

    if (sl == null) {
        final String msg = "placemarkId : " + placemarkId + " not found";
        log.log(Level.SEVERE, msg);
        throw new HttpMessageNotReadableException(msg);
    }

    final Map<String, Object> response = new HashMap<String, Object>();

    response.put("placemark_details", getPlacemarkDetails(sl));

    return response;
}