use of org.springframework.http.converter.StringHttpMessageConverter in project alf.io by alfio-event.
the class MvcConfiguration method configureMessageConverters.
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(jacksonMessageConverter(objectMapper));
StringHttpMessageConverter converter = new StringHttpMessageConverter();
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
converters.add(converter);
}
use of org.springframework.http.converter.StringHttpMessageConverter in project chassis by Kixeye.
the class SharedTest method testClassPath.
@Test
public void testClassPath() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("admin.enabled", "true");
properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("admin.hostname", "localhost");
properties.put("websocket.enabled", "true");
properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("websocket.hostname", "localhost");
properties.put("http.enabled", "true");
properties.put("http.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("http.hostname", "localhost");
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("default", properties));
context.setEnvironment(environment);
context.register(PropertySourcesPlaceholderConfigurer.class);
context.register(TransportConfiguration.class);
context.register(MetricsConfiguration.class);
RestTemplate httpClient = new RestTemplate();
try {
context.refresh();
httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR));
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) {
messageConverters.add(new SerDeHttpMessageConverter(messageSerDe));
}
messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
httpClient.setMessageConverters(messageConverters);
ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/admin/classpath"), String.class);
logger.info("Got response: [{}]", response);
Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value());
Assert.assertTrue(response.getBody().length() > 0);
} finally {
context.close();
}
}
use of org.springframework.http.converter.StringHttpMessageConverter in project chassis by Kixeye.
the class SharedTest method testProperties.
@Test
public void testProperties() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("admin.enabled", "true");
properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("admin.hostname", "localhost");
properties.put("websocket.enabled", "true");
properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("websocket.hostname", "localhost");
properties.put("http.enabled", "true");
properties.put("http.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("http.hostname", "localhost");
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("default", properties));
context.setEnvironment(environment);
context.register(PropertySourcesPlaceholderConfigurer.class);
context.register(TransportConfiguration.class);
context.register(MetricsConfiguration.class);
RestTemplate httpClient = new RestTemplate();
try {
context.refresh();
httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR));
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) {
messageConverters.add(new SerDeHttpMessageConverter(messageSerDe));
}
messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
httpClient.setMessageConverters(messageConverters);
ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/admin/properties"), String.class);
logger.info("Got response: [{}]", response);
Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value());
Assert.assertTrue(response.getBody().contains("user.dir=" + System.getProperty("user.dir")));
} finally {
context.close();
}
}
use of org.springframework.http.converter.StringHttpMessageConverter in project paascloud-master by paascloud.
the class WeixinImpl method getMessageConverters.
/**
* 默认注册的StringHttpMessageConverter字符集为ISO-8859-1,而微信返回的是UTF-8的,所以覆盖了原来的方法。
*
* @return the message converters
*/
@Override
protected List<HttpMessageConverter<?>> getMessageConverters() {
List<HttpMessageConverter<?>> messageConverters = super.getMessageConverters();
messageConverters.remove(0);
messageConverters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
return messageConverters;
}
use of org.springframework.http.converter.StringHttpMessageConverter in project paascloud-master by paascloud.
the class WeixinOAuth2Template method createRestTemplate.
/**
* 微信返回的contentType是html/text,添加相应的HttpMessageConverter来处理。
*
* @return the rest template
*/
@Override
protected RestTemplate createRestTemplate() {
RestTemplate restTemplate = super.createRestTemplate();
restTemplate.getMessageConverters().add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
return restTemplate;
}
Aggregations