Search in sources :

Example 71 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project books by aidanwhiteley.

the class GoogleBooksDaoSync method searchGoogBooksByTitle.

public BookSearchResult searchGoogBooksByTitle(String title) {
    String encodedTitle;
    encodedTitle = URLEncoder.encode(title, StandardCharsets.UTF_8);
    googleBooksRestTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
    final String searchString = googleBooksApiConfig.getSearchUrl() + encodedTitle + "&" + googleBooksApiConfig.getCountryCode() + "&" + googleBooksApiConfig.getMaxResults();
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Google Books API called with API called: {}", searchString);
    }
    BookSearchResult result = googleBooksRestTemplate.getForObject(searchString, BookSearchResult.class);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Result of Google Books API call: {}", result);
    }
    return result;
}
Also used : BookSearchResult(com.aidanwhiteley.books.domain.googlebooks.BookSearchResult) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 72 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project plumdo-work by wengwh.

the class CustomerErrorHandler method restTemplate.

@Bean
@ConditionalOnMissingBean({ RestOperations.class, RestTemplate.class })
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory());
    restTemplate.setErrorHandler(new CustomerErrorHandler());
    List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
    messageConverters.removeIf(converter -> converter instanceof StringHttpMessageConverter);
    messageConverters.add(new StringHttpMessageConverter(Charset.forName(CoreConstant.DEFAULT_CHARSET)));
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 73 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project tutorials by eugenp.

the class WebConfig method configureMessageConverters.

// 
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
    final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
    messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
    messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
    messageConverters.add(createXmlHttpMessageConverter());
    // messageConverters.add(new MappingJackson2HttpMessageConverter());
    messageConverters.add(new ProtobufHttpMessageConverter());
    messageConverters.add(new KryoHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    super.configureMessageConverters(messageConverters);
}
Also used : ProtobufHttpMessageConverter(org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Jackson2ObjectMapperBuilder(org.springframework.http.converter.json.Jackson2ObjectMapperBuilder) KryoHttpMessageConverter(org.baeldung.config.converter.KryoHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) SimpleDateFormat(java.text.SimpleDateFormat) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 74 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project new-cloud by xie-summer.

the class QQOAuth2Template method createRestTemplate.

/**
 * 坑,日志debug模式才打印出来 处理qq返回的text/html 类型数据
 *
 * @return
 */
@Override
protected RestTemplate createRestTemplate() {
    RestTemplate restTemplate = super.createRestTemplate();
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 75 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project ontrack by nemerosa.

the class WebConfig method configureMessageConverters.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.clear();
    // Plain text
    converters.add(new StringHttpMessageConverter());
    // Documents
    converters.add(new DocumentHttpMessageConverter());
    // JSON
    converters.add(new ResourceHttpMessageConverter(uriBuilder, securityService, resourceModules));
}
Also used : StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Aggregations

StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)93 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)48 ArrayList (java.util.ArrayList)38 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)27 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)24 RestTemplate (org.springframework.web.client.RestTemplate)23 Test (org.junit.jupiter.api.Test)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)18 Test (org.junit.Test)16 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)16 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)11 MediaType (org.springframework.http.MediaType)9 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)9 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)7 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)7 URI (java.net.URI)7 HashMap (java.util.HashMap)7 MethodParameter (org.springframework.core.MethodParameter)7 MapPropertySource (org.springframework.core.env.MapPropertySource)7 StandardEnvironment (org.springframework.core.env.StandardEnvironment)7