use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter in project earth-snow by justlive1.
the class WebConfig method xmlConverter.
@Bean
public Jaxb2RootElementHttpMessageConverter xmlConverter() {
Jaxb2RootElementHttpMessageConverter converter = new Jaxb2RootElementHttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_XML));
return converter;
}
use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter in project molgenis by molgenis.
the class HttpClientConfig method converters.
private List<HttpMessageConverter<?>> converters() {
List<HttpMessageConverter<?>> result = Lists.newArrayList();
result.add(new ByteArrayHttpMessageConverter());
result.add(new StringHttpMessageConverter());
result.add(new ResourceHttpMessageConverter());
result.add(new SourceHttpMessageConverter<>());
result.add(new AllEncompassingFormHttpMessageConverter());
result.add(new Jaxb2RootElementHttpMessageConverter());
result.add(gsonHttpMessageConverter);
return result;
}
use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method httpEntityWithContentType.
// SPR-16172
@PathPatternsParameterizedTest
void httpEntityWithContentType(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ResponseEntityController.class, usePathPatterns, wac -> {
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
adapterDef.getPropertyValues().add("messageConverters", messageConverters);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test-entity");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeader("Content-Type")).isEqualTo("application/xml");
assertThat(response.getContentAsString()).isEqualTo("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<testEntity><name>Foo Bar</name></testEntity>");
}
use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method produces.
@PathPatternsParameterizedTest
void produces(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ProducesController.class, usePathPatterns, wac -> {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
converters.add(new Jaxb2RootElementHttpMessageConverter());
RootBeanDefinition beanDef;
beanDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
beanDef.getPropertyValues().add("messageConverters", converters);
wac.registerBeanDefinition("handlerAdapter", beanDef);
beanDef = new RootBeanDefinition(ExceptionHandlerExceptionResolver.class);
beanDef.getPropertyValues().add("messageConverters", converters);
wac.registerBeanDefinition("requestMappingResolver", beanDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/something");
request.addHeader("Accept", "text/html");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("html");
request = new MockHttpServletRequest("GET", "/something");
request.addHeader("Accept", "application/xml");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("xml");
request = new MockHttpServletRequest("GET", "/something");
request.addHeader("Accept", "application/xml, text/html");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("xml");
request = new MockHttpServletRequest("GET", "/something");
request.addHeader("Accept", "text/html;q=0.9, application/xml");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("xml");
request = new MockHttpServletRequest("GET", "/something");
request.addHeader("Accept", "application/msword");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(406);
// SPR-16318
request = new MockHttpServletRequest("GET", "/something");
request.addHeader("Accept", "text/csv,application/problem+json");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.getContentType()).isEqualTo("application/problem+json");
assertThat(response.getContentAsString()).isEqualTo("{\"reason\":\"error\"}");
}
use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method addDefaultHttpMessageConverters.
/**
* Adds a set of default HttpMessageConverter instances to the given list.
* Subclasses can call this method from {@link #configureMessageConverters}.
* @param messageConverters the list to add the default message converters to
*/
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
messageConverters.add(new ResourceHttpMessageConverter());
messageConverters.add(new ResourceRegionHttpMessageConverter());
if (!shouldIgnoreXml) {
try {
messageConverters.add(new SourceHttpMessageConverter<>());
} catch (Throwable ex) {
// Ignore when no TransformerFactory implementation is available...
}
}
messageConverters.add(new AllEncompassingFormHttpMessageConverter());
if (romePresent) {
messageConverters.add(new AtomFeedHttpMessageConverter());
messageConverters.add(new RssChannelHttpMessageConverter());
}
if (!shouldIgnoreXml) {
if (jackson2XmlPresent) {
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.xml();
if (this.applicationContext != null) {
builder.applicationContext(this.applicationContext);
}
messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.build()));
} else if (jaxb2Present) {
messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
}
}
if (kotlinSerializationJsonPresent) {
messageConverters.add(new KotlinSerializationJsonHttpMessageConverter());
}
if (jackson2Present) {
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
if (this.applicationContext != null) {
builder.applicationContext(this.applicationContext);
}
messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
} else if (gsonPresent) {
messageConverters.add(new GsonHttpMessageConverter());
} else if (jsonbPresent) {
messageConverters.add(new JsonbHttpMessageConverter());
}
if (jackson2SmilePresent) {
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.smile();
if (this.applicationContext != null) {
builder.applicationContext(this.applicationContext);
}
messageConverters.add(new MappingJackson2SmileHttpMessageConverter(builder.build()));
}
if (jackson2CborPresent) {
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.cbor();
if (this.applicationContext != null) {
builder.applicationContext(this.applicationContext);
}
messageConverters.add(new MappingJackson2CborHttpMessageConverter(builder.build()));
}
}
Aggregations