use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method responseBodyArgMismatch.
@PathPatternsParameterizedTest
void responseBodyArgMismatch(boolean usePathPatterns) throws Exception {
initDispatcherServlet(RequestBodyArgMismatchController.class, usePathPatterns, wac -> {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(A.class, B.class);
try {
marshaller.afterPropertiesSet();
} catch (Exception ex) {
throw new BeanCreationException(ex.getMessage(), ex);
}
MarshallingHttpMessageConverter messageConverter = new MarshallingHttpMessageConverter(marshaller);
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
adapterDef.getPropertyValues().add("messageConverters", messageConverter);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "<b/>";
request.setContent(requestBody.getBytes(StandardCharsets.UTF_8));
request.addHeader("Content-Type", "application/xml; charset=utf-8");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(400);
}
use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.
the class MarshallingMessageConverterTests method createMarshaller.
@BeforeEach
public void createMarshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(MyBean.class);
marshaller.afterPropertiesSet();
this.converter = new MarshallingMessageConverter(marshaller);
}
use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.
the class OxmNamespaceHandlerTests method jaxb2ClassesToBeBoundMarshaller.
@Test
public void jaxb2ClassesToBeBoundMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ClassesMarshaller", Jaxb2Marshaller.class);
assertThat(jaxb2Marshaller).isNotNull();
}
use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.
the class OxmNamespaceHandlerTests method jaxb2ContextPathMarshaller.
@Test
public void jaxb2ContextPathMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ContextPathMarshaller", Jaxb2Marshaller.class);
assertThat(jaxb2Marshaller).isNotNull();
}
use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.
the class ViewResolutionTests method xmlOnly.
@Test
void xmlOnly() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
WebTestClient testClient = MockMvcWebTestClient.bindToController(new PersonController()).singleView(new MarshallingView(marshaller)).build();
testClient.get().uri("/person/Corea").exchange().expectStatus().isOk().expectHeader().contentType(MediaType.APPLICATION_XML).expectBody().xpath("/person/name/text()").isEqualTo("Corea");
}
Aggregations