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

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

Introduction

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

Prototype

public StringHttpMessageConverter() 

Source Link

Document

A default constructor that uses "ISO-8859-1" as the default charset.

Usage

From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientV1.java

/**
 * Get message converters to use for supporting legacy Micro Cloud Foundry 1.1 and older
 *
 * @return List of message converters/*from   w  w  w  .  ja va  2  s  . com*/
 */
private List<HttpMessageConverter<?>> getLegacyMessageConverters() {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new ResourceHttpMessageConverter());
    messageConverters.add(new UploadApplicationPayloadHttpMessageConverter());
    FormHttpMessageConverter formPartsMessageConverter = new CloudFoundryFormHttpMessageConverter();
    List<HttpMessageConverter<?>> partConverters = new ArrayList<HttpMessageConverter<?>>();
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverterWithoutMediaType();
    stringConverter.setWriteAcceptCharset(false);
    partConverters.add(stringConverter);
    partConverters.add(new ResourceHttpMessageConverter());
    partConverters.add(new UploadApplicationPayloadHttpMessageConverter());
    formPartsMessageConverter.setPartConverters(partConverters);
    messageConverters.add(formPartsMessageConverter);
    messageConverters.add(new MappingJacksonHttpMessageConverter());
    return messageConverters;
}

From source file:com.auditbucket.test.functional.TestAuditIntegration.java

private String runQuery(QueryParams queryParams) throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());

    HttpHeaders httpHeaders = AbRestClient.getHeaders("mike", "123");
    HttpEntity<QueryParams> requestEntity = new HttpEntity<>(queryParams, httpHeaders);

    try {/*from  w  ww. j a v a 2s .co  m*/
        return restTemplate.exchange("http://localhost:9081/ab-search/v1/query/", HttpMethod.POST,
                requestEntity, String.class).getBody();
    } catch (HttpClientErrorException e) {
        logger.error("AB Client Audit error {}", e);
    } catch (HttpServerErrorException e) {
        logger.error("AB Server Audit error {}", e);

    }
    return null;
}

From source file:org.cloudfoundry.identity.uaa.test.TestAccountSetup.java

private OAuth2RestTemplate createRestTemplate(OAuth2ProtectedResourceDetails resource,
        AccessTokenRequest accessTokenRequest) {
    OAuth2ClientContext context = new DefaultOAuth2ClientContext(accessTokenRequest);
    OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context);
    client.setRequestFactory(new SimpleClientHttpRequestFactory() {
        @Override// w w w. java  2s.  c o  m
        protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
            super.prepareConnection(connection, httpMethod);
            connection.setInstanceFollowRedirects(false);
        }
    });
    client.setErrorHandler(new OAuth2ErrorHandler(client.getResource()) {
        // Pass errors through in response entity for status code analysis
        @Override
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });
    List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>();
    list.add(new StringHttpMessageConverter());
    list.add(new MappingJackson2HttpMessageConverter());
    client.setMessageConverters(list);
    return client;
}

From source file:org.encuestame.oauth1.support.OAuth1Support.java

/**
 * Constructs an OAuth1Template./*from ww  w .  j a  va  2  s . c o  m*/
 * @param oauth10a if true this template operates against an OAuth 1.0a provider. If false, it works in OAuth 1.0 mode.
 */
public OAuth1Support(String consumerKey, String consumerSecret, String requestTokenUrl, String authorizeUrl,
        String accessTokenUrl, boolean oauth10a) {
    super(Arrays.<HttpMessageConverter<?>>asList(new StringHttpMessageConverter(),
            new FormHttpMessageConverter()));
    this.consumerKey = consumerKey;
    this.consumerSecret = consumerSecret;
    this.requestTokenUrl = requestTokenUrl;
    this.oauth10a = oauth10a;
    this.authorizeUrlTemplate = new UriTemplate(authorizeUrl);
    this.accessTokenUrl = accessTokenUrl;

}

From source file:org.flockdata.client.FdTemplate.java

public RestTemplate getRestTemplate() {
    if (restTemplate == null) {
        restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
    }/*w  w  w.  ja  v a  2s  .  c  o  m*/
    return restTemplate;
}

From source file:org.springframework.cloud.netflix.zuul.filters.route.support.ZuulProxyTestBase.java

@SuppressWarnings("deprecation")
@Test// w w  w  . j  a va  2 s .c o m
public void javascriptEncodedFormParams() {
    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ArrayList<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters
            .addAll(Arrays.asList(new StringHttpMessageConverter(), new NoEncodingFormHttpMessageConverter()));
    testRestTemplate.getRestTemplate().setMessageConverters(converters);

    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("foo", "(bar)");
    ResponseEntity<String> result = testRestTemplate
            .postForEntity("http://localhost:" + this.port + "/simple/local", map, String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Posted [(bar)] and Content-Length was: 13!", result.getBody());
}

From source file:org.springframework.data.document.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.java

public AnnotationMethodHandlerAdapter() {
    // no restriction of HTTP methods by default
    // MLP/*from w ww .  j  a v a 2s.com*/
    super(false);

    // See SPR-7316
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    messageConverters = new HttpMessageConverter[] { new ByteArrayHttpMessageConverter(),
            stringHttpMessageConverter, new SourceHttpMessageConverter(),
            new XmlAwareFormHttpMessageConverter() };
}

From source file:org.springframework.http.converter.FormHttpMessageConverter.java

public FormHttpMessageConverter() {
    this.supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
    this.supportedMediaTypes.add(MediaType.MULTIPART_FORM_DATA);

    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316

    this.partConverters.add(new ByteArrayHttpMessageConverter());
    this.partConverters.add(stringHttpMessageConverter);
    this.partConverters.add(new ResourceHttpMessageConverter());

    applyDefaultCharset();/*w w  w. j  a va  2 s .c o m*/
}

From source file:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.java

public AnnotationMethodHandlerAdapter() {
    // no restriction of HTTP methods by default
    super(false);

    // See SPR-7316
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    this.messageConverters = new HttpMessageConverter<?>[] { new ByteArrayHttpMessageConverter(),
            stringHttpMessageConverter, new SourceHttpMessageConverter<Source>(),
            new org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter() };
}

From source file:org.springframework.web.servlet.mvc.annotation.MyAnnotationMethodHandlerAdapter.java

public MyAnnotationMethodHandlerAdapter() {
    // no restriction of HTTP methods by default
    super(false);

    // See SPR-7316
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    this.messageConverters = new HttpMessageConverter[] { new ByteArrayHttpMessageConverter(),
            stringHttpMessageConverter, new SourceHttpMessageConverter(),
            new XmlAwareFormHttpMessageConverter() };
}