use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method responseBodyArgMismatch.
@Test
public void responseBodyArgMismatch() throws ServletException, IOException {
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
@Override
public void initialize(GenericWebApplicationContext 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);
}
}, RequestBodyArgMismatchController.class);
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "<b/>";
request.setContent(requestBody.getBytes("UTF-8"));
request.addHeader("Content-Type", "application/xml; charset=utf-8");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals(400, response.getStatus());
}
use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project sic by belluccifranco.
the class App method marshaller.
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage> specified in pom.xml
marshaller.setContextPaths("afip.wsaa.wsdl", "afip.wsfe.wsdl");
return marshaller;
}
use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project uPortal by Jasig.
the class JaxbPortalDataHandlerServiceTest method testUpgradeThenImport.
@Test
public void testUpgradeThenImport() throws Exception {
final ClassPathResource importDataResource = new ClassPathResource("/org/apereo/portal/io/xml/user/test_3-2.user.xml");
when(resourceLoader.getResource("classpath:/org/apereo/portal/io/xml/user/test_3-2.user.xml")).thenReturn(importDataResource);
final ClassPathResource xslResource = new ClassPathResource("/org/apereo/portal/io/xml/user/upgrade-user_3-2.xsl");
final IDataUpgrader xsltDataUpgrader = createXsltDataUpgrader(xslResource, UserPortalDataType.IMPORT_32_DATA_KEY);
dataImportExportService.setDataUpgraders(Arrays.asList(xsltDataUpgrader));
final Jaxb2Marshaller userJaxb2Marshaller = new Jaxb2Marshaller();
userJaxb2Marshaller.setContextPath("org.apereo.portal.io.xml.user");
userJaxb2Marshaller.afterPropertiesSet();
final IDataImporter<ExternalUser> userDataImporter = mock(IDataImporter.class);
when(userDataImporter.getImportDataKeys()).thenReturn(Collections.singleton(UserPortalDataType.IMPORT_40_DATA_KEY));
when(userDataImporter.getUnmarshaller()).thenReturn(userJaxb2Marshaller);
Collection<IDataImporter<?>> dataImporters = new LinkedList<IDataImporter<?>>();
dataImporters.add(userDataImporter);
dataImportExportService.setDataImporters(dataImporters);
final Resource resource = resourceLoader.getResource("classpath:/org/apereo/portal/io/xml/user/test_3-2.user.xml");
dataImportExportService.importData(resource);
final ArgumentCaptor<ExternalUser> userArgumentCaptor = ArgumentCaptor.forClass(ExternalUser.class);
verify(userDataImporter).importData(userArgumentCaptor.capture());
final ExternalUser externalUser = userArgumentCaptor.getValue();
assertNotNull(externalUser);
assertEquals("student", externalUser.getUsername());
assertEquals("defaultTemplateUser", externalUser.getDefaultUser());
assertEquals("(MD5)mhmjKvf2F3gPizS9DrA+CsFmqj74oTSb", externalUser.getPassword());
assertNull(externalUser.getLastPasswordChange());
}
Aggregations