Example usage for org.springframework.http HttpOutputMessage getHeaders

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

Introduction

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

Prototype

HttpHeaders getHeaders();

Source Link

Document

Return the headers of this message.

Usage

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

private static Charset getCharset(HttpOutputMessage outputMessage) {
    Charset charset = outputMessage.getHeaders().getContentType().getCharSet();

    if (charset == null) {
        charset = DEFAULT_CHARSET;//w w  w  . jav a2s. com
    }

    return charset;
}

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

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    outputMessage.getHeaders().setContentType(CONTENT_TYPE);
    super.writeInternal(s, outputMessage);
}

From source file:com.boundlessgeo.geoserver.api.converters.YsldMessageConverter.java

@Override
protected void writeInternal(StyledLayerDescriptor sld, HttpOutputMessage message)
        throws IOException, HttpMessageNotWritableException {
    message.getHeaders().setContentType(MEDIA_TYPE);
    new YsldHandler().encode(sld, null, true, message.getBody());
}

From source file:org.cloudfoundry.client.lib.util.StringHttpMessageConverterWithoutMediaType.java

@Override
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
    if (writeAcceptCharset) {
        outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
    }//from   www  .  j a  v a  2 s .c om
    MediaType contentType = outputMessage.getHeaders().getContentType();
    Charset charset = contentType != null && contentType.getCharSet() != null ? contentType.getCharSet()
            : DEFAULT_CHARSET;
    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:org.cloudfoundry.client.lib.rest.UploadApplicationPayloadHttpMessageConverter.java

private void setOutputContentType(MediaType contentType, HttpOutputMessage outputMessage) {
    HttpHeaders headers = outputMessage.getHeaders();
    if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
        contentType = MediaType.APPLICATION_OCTET_STREAM;
    }//from   w w w  .j a  v a  2  s . com
    if (contentType != null) {
        headers.setContentType(contentType);
    }
}

From source file:fi.helsinki.opintoni.config.http.converter.CsvHttpMessageConverter.java

@Override
protected void writeInternal(CsvResponse<T> response, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    outputMessage.getHeaders().set("Content-Disposition", "attachment; filename=" + response.filename);

    String csv = getCsv(response);
    StreamUtils.copy(csv, Charset.forName("UTF-8"), outputMessage.getBody());
}

From source file:org.spearal.spring.rest.SpearalMessageConverter.java

public void write(Object obj, MediaType contentType, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    outputMessage.getHeaders().setContentType(SpearalSpring.APPLICATION_SPEARAL_TYPE);

    SpearalEncoder encoder = factory.newEncoder(outputMessage.getBody());

    if (obj instanceof SpearalEntity) {
        ((SpearalEntity<?>) obj).applyClientPropertyFilter(encoder.getPropertyFilter());

        obj = ((SpearalEntity<?>) obj).getBody();
    }//from w  w w.j av a 2  s .  c  o m

    encoder.writeAny(obj);
}

From source file:org.cloudfoundry.client.lib.util.UploadApplicationPayloadHttpMessageConverter.java

public void write(UploadApplicationPayload t, MediaType contentType, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    HttpHeaders headers = outputMessage.getHeaders();
    if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
        contentType = MediaType.APPLICATION_OCTET_STREAM;
    }//  w ww  . j  a va2  s  .  co  m
    if (contentType != null) {
        headers.setContentType(contentType);
    }
    FileCopyUtils.copy(t.getInputStream(), outputMessage.getBody());
    outputMessage.getBody().flush();
}

From source file:com.iflytek.edu.cloud.frame.spring.MappingJackson2HttpMessageConverterExt.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    outputMessage.getHeaders().setContentType(MediaType.parseMediaType("application/json"));
    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.getObjectMapper().getFactory().createGenerator(outputMessage.getBody(),
            encoding);/*from   w ww  . j  a v  a 2  s  .  c  o m*/

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

    String callBack = (String) RestContextHolder.getContext().getParam(Constants.SYS_PARAM_KEY_CALLBACK);
    try {
        if (StringUtils.hasText(callBack)) {
            String json = this.getObjectMapper().writeValueAsString(object);
            json = callBack + "( " + json + " )";
            outputMessage.getBody().write(json.getBytes(Charset.forName("UTF-8")));
            outputMessage.getBody().flush();
        } else {
            this.getObjectMapper().writeValue(jsonGenerator, object);
        }
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}