Example usage for org.springframework.http HttpInputMessage getHeaders

List of usage examples for org.springframework.http HttpInputMessage getHeaders

Introduction

In this page you can find the example usage for org.springframework.http HttpInputMessage getHeaders.

Prototype

HttpHeaders getHeaders();

Source Link

Document

Return the headers of this message.

Usage

From source file:cn.cuizuoli.appranking.http.converter.JsoupHttpMessageConverter.java

@Override
protected Document readInternal(Class<? extends Document> clazz, HttpInputMessage inputMessage)
        throws IOException {
    Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
    return Jsoup.parse(inputMessage.getBody(), charset.name(), StringUtils.EMPTY);
}

From source file:com.eu.evaluation.server.mvc.UTF8StringHttpMessageConverter.java

@Override
protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException {
    Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
    return StreamUtils.copyToString(inputMessage.getBody(), charset);
}

From source file:com.facetime.cloud.server.support.UTF8HttpMessageConverter.java

@Override
protected String readInternal(@SuppressWarnings("rawtypes") Class clazz, HttpInputMessage inputMessage)
        throws IOException {
    MediaType contentType = inputMessage.getHeaders().getContentType();
    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
    return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
}

From source file:com.igame.commons.util.UTF8StringHttpMessageConverter.java

@Override
protected String readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
    Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
    return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
}

From source file:com.e6soft.core.web.StringHttpMessageConverter.java

@SuppressWarnings("rawtypes")
@Override/*from w  w w.  j  av  a  2  s.  co m*/
protected String readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
    Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
    return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
}

From source file:com.hbztc.middleware.util.Utf8StringHttpMessageConverter.java

@Override
protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException {
    Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
    return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));
}

From source file:gumga.framework.presentation.exceptionhandler.ErrorMessageHandlerExceptionResolver.java

/**
 * Copied from/*w w w.  j  av  a  2  s . c  o m*/
 * {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver}
 */
@SuppressWarnings("unchecked")
private ModelAndView handleResponseBody(Object returnValue, ServletWebRequest webRequest)
        throws ServletException, IOException {

    HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest());
    List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
    if (acceptedMediaTypes.isEmpty()) {
        acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
    }
    MediaType.sortByQualityValue(acceptedMediaTypes);
    try (ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(webRequest.getResponse())) {
        Class<?> returnValueType = returnValue.getClass();
        if (this.messageConverters != null) {
            for (MediaType acceptedMediaType : acceptedMediaTypes) {
                for (HttpMessageConverter messageConverter : this.messageConverters) {
                    if (messageConverter.canWrite(returnValueType, acceptedMediaType)) {
                        messageConverter.write(returnValue, acceptedMediaType, outputMessage);
                        return new ModelAndView();
                    }
                }
            }
        }
        if (logger.isWarnEnabled()) {
            logger.warn("Could not find HttpMessageConverter that supports return type [" + returnValueType
                    + "] and " + acceptedMediaTypes);
        }
    }

    return null;
}

From source file:biz.c24.io.spring.http.C24HttpMessageConverter.java

public ComplexDataObject read(Class<? extends ComplexDataObject> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {

    HttpHeaders headers = inputMessage.getHeaders();
    MediaType contentType = headers.getContentType();

    Source source = getSourceFor(inputMessage.getBody(), contentType);
    ComplexDataObject result = source.readObject(model.getElementFor(clazz));

    return C24Utils.potentiallyUnwrapDocumentRoot(result);
}

From source file:org.ssoup.backend.web.RdfModelConverter.java

@Override
protected Model readInternal(Class<? extends Model> aClass, HttpInputMessage httpInputMessage)
        throws IOException, HttpMessageNotReadableException {
    Model model = ModelFactory.createDefaultModel();
    Lang rdfLanguage = mimeTypeToJenaLanguage(httpInputMessage.getHeaders().getContentType(), Lang.JSONLD);
    RDFDataMgr.read(model, httpInputMessage.getBody(), "", rdfLanguage);
    return model;
}

From source file:net.sf.jsog.spring.StringJsogHttpMessageConverter.java

@Override
public JSOG read(Class<? extends JSOG> clazz, HttpInputMessage input)
        throws IOException, HttpMessageNotReadableException {
    HttpHeaders headers = input.getHeaders();
    MediaType contentType = headers.getContentType();
    Charset encoding = contentType.getCharSet();

    if (encoding == null) {
        encoding = this.encoding;
    }/*from w  w w .j a va  2 s.  c  om*/

    // Read in the JSON
    String json = IOUtils.toString(input.getBody(), encoding.name());

    // Parse the JSON and return a JSOG.
    try {
        return JSOG.parse(json);
    } catch (IOException e) {
        throw new HttpMessageNotReadableException("Unable to parse JSON.", e);
    }
}