use of org.springframework.http.converter.StringHttpMessageConverter in project paascloud-master by paascloud.
the class QQOAuth2Template method createRestTemplate.
/**
* Create rest template rest template.
*
* @return the rest template
*/
@Override
protected RestTemplate createRestTemplate() {
RestTemplate restTemplate = super.createRestTemplate();
restTemplate.getMessageConverters().add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
return restTemplate;
}
use of org.springframework.http.converter.StringHttpMessageConverter in project snow-owl by b2ihealthcare.
the class SnowOwlApiConfig method configureMessageConverters.
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
final StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charsets.UTF_8);
stringConverter.setWriteAcceptCharset(false);
converters.add(stringConverter);
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new ResourceHttpMessageConverter());
converters.add(new CsvMessageConverter());
// XXX using null value here as Spring calls a proxied method anyway which returns an already configured instance, see mapping2JacksonHttpMessageConverter Bean method
converters.add(mapping2JacksonHttpMessageConverter(null));
}
use of org.springframework.http.converter.StringHttpMessageConverter in project littlefisher-system by littlefishercoder.
the class WebSpringMvcConfig method configureMessageConverters.
/**
* Description: 消息转换器配置
*
* @param converters converters
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper om = jacksonConverter.getObjectMapper();
om.setDateFormat(new SimpleDateFormat(DateUtil.DATETIME_FORMAT_1));
om.setLocale(Locale.CHINA);
om.setTimeZone(TimeZone.getTimeZone("GMT+8"));
List<MediaType> mediaTypeList = Lists.newArrayList();
mediaTypeList.add(new MediaType(MediaType.APPLICATION_JSON, Charsets.UTF_8));
mediaTypeList.add(new MediaType(MediaType.TEXT_HTML, Charsets.UTF_8));
jacksonConverter.setSupportedMediaTypes(mediaTypeList);
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charsets.UTF_8);
stringConverter.setWriteAcceptCharset(false);
// 保持以下顺序
// "application/json" "application/*+json"
converters.add(jacksonConverter);
// "application/xml" "text/xml" "application/*+xml"
converters.add(new Jaxb2RootElementHttpMessageConverter());
// "application/xml" "text/xml" "application/*+xml"
converters.add(new SourceHttpMessageConverter<>());
// "application/x-www-form-urlencoded" "multipart/form-data"
converters.add(new AllEncompassingFormHttpMessageConverter());
// "application/octet-stream" "*/*"
converters.add(new ByteArrayHttpMessageConverter());
// "text/plain" "*/*"
converters.add(stringConverter);
// "*/*"
converters.add(new ResourceHttpMessageConverter());
}
use of org.springframework.http.converter.StringHttpMessageConverter in project pancm_project by xuwujing.
the class RestTemplateHelper method getDefaultRestTemplate.
private RestTemplate getDefaultRestTemplate(int connectTimeoutSeconds, int readTimeoutSeconds) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(connectTimeoutSeconds * 1000);
requestFactory.setReadTimeout(readTimeoutSeconds * 1000);
// HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
// httpRequestFactory.setConnectionRequestTimeout(connectTimeoutSeconds * 1000);
// httpRequestFactory.setConnectTimeout(readTimeoutSeconds * 1000);
// httpRequestFactory.setReadTimeout(readTimeoutSeconds * 1000);
RestTemplate restTemplate = new RestTemplate(requestFactory);
// 换上fastjson
List<HttpMessageConverter<?>> httpMessageConverterList = restTemplate.getMessageConverters();
Iterator<HttpMessageConverter<?>> iterator = httpMessageConverterList.iterator();
if (iterator.hasNext()) {
HttpMessageConverter<?> converter = iterator.next();
// 原有的String是ISO-8859-1编码 去掉
if (converter instanceof StringHttpMessageConverter) {
iterator.remove();
}
// 由于系统中默认有jackson 在转换json时自动会启用 但是我们不想使用它 可以直接移除或者将fastjson放在首位
if (converter instanceof GsonHttpMessageConverter || converter instanceof MappingJackson2HttpMessageConverter) {
iterator.remove();
}
}
httpMessageConverterList.add(new StringHttpMessageConverter(Charset.forName("utf-8")));
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON);
fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
httpMessageConverterList.add(0, fastJsonHttpMessageConverter);
return restTemplate;
}
use of org.springframework.http.converter.StringHttpMessageConverter in project pancm_project by xuwujing.
the class RestTemplateHelper method getHttpsDefaultRestTemplate.
private RestTemplate getHttpsDefaultRestTemplate(int connectTimeoutSeconds, int readTimeoutSeconds) {
HttpsClientRequestFactory requestFactory = new HttpsClientRequestFactory();
requestFactory.setConnectTimeout(connectTimeoutSeconds * 1000);
requestFactory.setReadTimeout(readTimeoutSeconds * 1000);
// HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
// httpRequestFactory.setConnectionRequestTimeout(connectTimeoutSeconds * 1000);
// httpRequestFactory.setConnectTimeout(readTimeoutSeconds * 1000);
// httpRequestFactory.setReadTimeout(readTimeoutSeconds * 1000);
RestTemplate restTemplate = new RestTemplate(requestFactory);
// 换上fastjson
List<HttpMessageConverter<?>> httpMessageConverterList = restTemplate.getMessageConverters();
Iterator<HttpMessageConverter<?>> iterator = httpMessageConverterList.iterator();
if (iterator.hasNext()) {
HttpMessageConverter<?> converter = iterator.next();
// 原有的String是ISO-8859-1编码 去掉
if (converter instanceof StringHttpMessageConverter) {
iterator.remove();
}
// 由于系统中默认有jackson 在转换json时自动会启用 但是我们不想使用它 可以直接移除或者将fastjson放在首位
if (converter instanceof GsonHttpMessageConverter || converter instanceof MappingJackson2HttpMessageConverter) {
iterator.remove();
}
}
httpMessageConverterList.add(new StringHttpMessageConverter(Charset.forName("utf-8")));
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON);
fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
httpMessageConverterList.add(0, fastJsonHttpMessageConverter);
return restTemplate;
}
Aggregations