Example usage for org.springframework.http HttpOutputMessage getBody

List of usage examples for org.springframework.http HttpOutputMessage getBody

Introduction

In this page you can find the example usage for org.springframework.http HttpOutputMessage getBody.

Prototype

OutputStream getBody() throws IOException;

Source Link

Document

Return the body of the message as an output stream.

Usage

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

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    if (this.writeAcceptCharset) {
        outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    }/* w w w . ja v a 2s .co m*/
    Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
    StreamUtils.copy(s, charset, outputMessage.getBody());
}

From source file:demo.SourceHttpMessageConverter.java

@Override
protected void writeInternal(T t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    try {/*from   w w w.ja v a  2 s  . c  o m*/
        Result result = new StreamResult(outputMessage.getBody());
        transform(t, result);
    } catch (TransformerException ex) {
        throw new HttpMessageNotWritableException("Could not transform [" + t + "] to output message", ex);
    }
}

From source file:com.careerly.common.support.msgconverter.JsonpHttpMessageConverter.java

@Override
protected void writeInternal(JsonpResponse t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    ServletServerHttpResponse response = (ServletServerHttpResponse) outputMessage;
    response.getServletResponse().setCharacterEncoding("UTF-8");
    BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(outputMessage.getBody(), Charset.forName("UTF-8")));
    try {/*from  w w w .  j av a 2s .  co m*/
        if (StringUtils.isNotBlank(t.getCallback())) {
            bw.write(StringEscapeUtils.escapeHtml(t.getCallback()));
            bw.write("(");
        }
        bw.write(JsonUtils.marshalToString(t.getJson()));
        if (StringUtils.isNotBlank(t.getCallback())) {
            bw.write(")");
        }
    } finally {
        bw.close();
    }
}

From source file:com.nextbook.config.ConfigurableStringHttpMessageConverter.java

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    if (writeAcceptCharset) {
        outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    }//ww  w  . ja v a 2  s  . c  o m
    Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
    FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
}

From source file:org.kwet.giteway.mapper.PrettyMappingJacksonHttpMessageConverter.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory()
            .createJsonGenerator(outputMessage.getBody(), encoding);
    try {//from  w  w  w.  java 2  s.c  om
        if (this.prefixJson) {
            jsonGenerator.writeRaw("{} && ");
        }
        /**added by a.couette to enable prettyprint**/
        jsonGenerator.useDefaultPrettyPrinter();
        this.objectMapper.writeValue(jsonGenerator, object);
    } catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

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

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    if (this.writeAcceptCharset) {
        outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    }/*www  . j a  v a2  s .c o  m*/
    Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
    FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
}

From source file:model.ConfigurableStringHttpMessageConverter.java

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    MediaType contentType = outputMessage.getHeaders().getContentType();
    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
    FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
}

From source file:com.lingcaibao.web.interceptor.StringHttpMessageConverter.java

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    if (this.writeAcceptCharset) {
        outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    }/*from www .ja  v  a  2 s  .com*/
    Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
    System.out.println(s);
    StreamUtils.copy(s, charset, outputMessage.getBody());
}

From source file:com.github.hateoas.forms.spring.uber.UberJackson2HttpMessageConverter.java

@Override
protected void writeInternal(Object t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    UberMessageModel uberModel = new UberMessageModel(t);
    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(),
            encoding);/*from  w  w  w.  j  a  va2  s.co m*/

    // A workaround for JsonGenerators not applying serialization features
    // https://github.com/FasterXML/jackson-databind/issues/12
    if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
        jsonGenerator.useDefaultPrettyPrinter();
    }

    try {
        this.objectMapper.writeValue(jsonGenerator, uberModel);
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

From source file:com.careerly.common.support.msgconverter.JacksonHttpMessageConverter.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    if (!prettyPrinting) {
        super.writeInternal(object, outputMessage);
        return;/*from w  w  w.  jav  a  2s  . c o m*/
    }

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = getObjectMapper().getJsonFactory()
            .createJsonGenerator(outputMessage.getBody(), encoding).useDefaultPrettyPrinter();
    try {
        getObjectMapper().writeValue(jsonGenerator, object);
    } catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}