Search in sources :

Example 6 with Jaxb2Marshaller

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());
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MarshallingHttpMessageConverter(org.springframework.http.converter.xml.MarshallingHttpMessageConverter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 7 with Jaxb2Marshaller

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;
}
Also used : Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) Bean(org.springframework.context.annotation.Bean)

Example 8 with Jaxb2Marshaller

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());
}
Also used : ExternalUser(org.apereo.portal.io.xml.user.ExternalUser) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) ClassPathResource(org.springframework.core.io.ClassPathResource) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)8 Test (org.junit.Test)6 MarshallingView (org.springframework.web.servlet.view.xml.MarshallingView)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ServletException (javax.servlet.ServletException)1 ExternalUser (org.apereo.portal.io.xml.user.ExternalUser)1 Before (org.junit.Before)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 Bean (org.springframework.context.annotation.Bean)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1 MarshallingHttpMessageConverter (org.springframework.http.converter.xml.MarshallingHttpMessageConverter)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1