use of org.springframework.http.converter.HttpMessageConverter in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class XmlContentRequestMatchersIntegrationTests method setup.
@BeforeEach
public void setup() {
List<Person> composers = Arrays.asList(new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN));
this.people = new PeopleWrapper(composers);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new Jaxb2RootElementHttpMessageConverter());
this.restTemplate = new RestTemplate();
this.restTemplate.setMessageConverters(converters);
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class XpathRequestMatchersIntegrationTests method setup.
@BeforeEach
public void setup() {
List<Person> composers = Arrays.asList(new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN));
List<Person> performers = Arrays.asList(new Person("Vladimir Ashkenazy").setSomeBoolean(false), new Person("Yehudi Menuhin").setSomeBoolean(true));
this.people = new PeopleWrapper(composers, performers);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new Jaxb2RootElementHttpMessageConverter());
this.restTemplate = new RestTemplate();
this.restTemplate.setMessageConverters(converters);
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class RouterFunctionMapping method initMessageConverters.
/**
* Initializes a default set of {@linkplain HttpMessageConverter message converters}.
*/
private void initMessageConverters() {
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(4);
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
try {
messageConverters.add(new SourceHttpMessageConverter<>());
} catch (Error err) {
// Ignore when no TransformerFactory implementation is available
}
messageConverters.add(new AllEncompassingFormHttpMessageConverter());
this.messageConverters = messageConverters;
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class TestPathHelper method verifyMessageConverters.
@SuppressWarnings("unchecked")
private void verifyMessageConverters(Object bean, boolean hasDefaultRegistrations) {
assertThat(bean).isNotNull();
Object value = new DirectFieldAccessor(bean).getPropertyValue("messageConverters");
assertThat(value).isNotNull();
assertThat(value instanceof List).isTrue();
List<HttpMessageConverter<?>> converters = (List<HttpMessageConverter<?>>) value;
if (hasDefaultRegistrations) {
assertThat(converters.size() > 2).as("Default and custom converter expected").isTrue();
} else {
assertThat(converters.size() == 2).as("Only custom converters expected").isTrue();
}
assertThat(converters.get(0) instanceof StringHttpMessageConverter).isTrue();
assertThat(converters.get(1) instanceof ResourceHttpMessageConverter).isTrue();
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class ServletAnnotationControllerHandlerMethodTests method produces.
@Test
public void produces() throws Exception {
initServlet(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);
}, ProducesController.class);
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\"}");
}
Aggregations