Search in sources :

Example 26 with Jaxb2Marshaller

use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.

the class ViewResolutionTests method contentNegotiation.

@Test
void contentNegotiation() throws Exception {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(Person.class);
    List<View> viewList = new ArrayList<>();
    viewList.add(new MappingJackson2JsonView());
    viewList.add(new MarshallingView(marshaller));
    ContentNegotiationManager manager = new ContentNegotiationManager(new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));
    ContentNegotiatingViewResolver cnViewResolver = new ContentNegotiatingViewResolver();
    cnViewResolver.setDefaultViews(viewList);
    cnViewResolver.setContentNegotiationManager(manager);
    cnViewResolver.afterPropertiesSet();
    WebTestClient testClient = MockMvcWebTestClient.bindToController(new PersonController()).viewResolvers(cnViewResolver, new InternalResourceViewResolver()).build();
    EntityExchangeResult<Void> result = testClient.get().uri("/person/Corea").exchange().expectStatus().isOk().expectBody().isEmpty();
    // Further assertions on the server response
    MockMvcWebTestClient.resultActionsFor(result).andExpect(model().size(1)).andExpect(model().attributeExists("person")).andExpect(forwardedUrl("person/show"));
    testClient.get().uri("/person/Corea").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON).expectBody().jsonPath("$.person.name", "Corea");
    testClient.get().uri("/person/Corea").accept(MediaType.APPLICATION_XML).exchange().expectStatus().isOk().expectHeader().contentType(MediaType.APPLICATION_XML).expectBody().xpath("/person/name/text()").isEqualTo("Corea");
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) MockMvcWebTestClient(org.springframework.test.web.servlet.client.MockMvcWebTestClient) ArrayList(java.util.ArrayList) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) FixedContentNegotiationStrategy(org.springframework.web.accept.FixedContentNegotiationStrategy) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) View(org.springframework.web.servlet.View) MarshallingView(org.springframework.web.servlet.view.xml.MarshallingView) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) MarshallingView(org.springframework.web.servlet.view.xml.MarshallingView) ContentNegotiatingViewResolver(org.springframework.web.servlet.view.ContentNegotiatingViewResolver) HeaderContentNegotiationStrategy(org.springframework.web.accept.HeaderContentNegotiationStrategy) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Test(org.junit.jupiter.api.Test)

Example 27 with Jaxb2Marshaller

use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project spring-framework by spring-projects.

the class ViewResolutionTests method xmlOnly.

@Test
void xmlOnly() throws Exception {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(Person.class);
    standaloneSetup(new PersonController()).setSingleView(new MarshallingView(marshaller)).build().perform(get("/person/Corea")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_XML)).andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
Also used : MarshallingView(org.springframework.web.servlet.view.xml.MarshallingView) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) Test(org.junit.jupiter.api.Test)

Example 28 with Jaxb2Marshaller

use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project cas by apereo.

the class InweboServiceConfiguration method inweboConsoleAdmin.

@Bean
@ConditionalOnMissingBean(name = "inweboConsoleAdmin")
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public InweboConsoleAdmin inweboConsoleAdmin(@Qualifier(CasSSLContext.BEAN_NAME) final ObjectProvider<CasSSLContext> casSslContext, final CasConfigurationProperties casProperties) throws Exception {
    val inwebo = casProperties.getAuthn().getMfa().getInwebo();
    val marshaller = new Jaxb2Marshaller();
    val marshallerContext = getClass().getPackageName().replaceAll("config", "service.soap.generated");
    marshaller.setContextPath(marshallerContext);
    val client = new InweboConsoleAdmin(casProperties);
    client.setDefaultUri(inwebo.getConsoleAdminUrl());
    client.setMarshaller(marshaller);
    client.setUnmarshaller(marshaller);
    val messageSender = new HttpsUrlConnectionMessageSender();
    messageSender.setKeyManagers(SSLUtils.buildKeystore(inwebo.getClientCertificate()).getKeyManagers());
    if (casSslContext.getIfAvailable() != null) {
        messageSender.setTrustManagers(casSslContext.getObject().getTrustManagers());
    } else {
        val tmFactory = TrustManagerFactory.getInstance("PKIX");
        tmFactory.init((KeyStore) null);
        messageSender.setTrustManagers(tmFactory.getTrustManagers());
    }
    client.setMessageSender(messageSender);
    return client;
}
Also used : lombok.val(lombok.val) HttpsUrlConnectionMessageSender(org.springframework.ws.transport.http.HttpsUrlConnectionMessageSender) InweboConsoleAdmin(org.apereo.cas.support.inwebo.service.InweboConsoleAdmin) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 29 with Jaxb2Marshaller

use of org.springframework.oxm.jaxb.Jaxb2Marshaller in project cas by apereo.

the class SoapAuthenticationConfiguration method soapAuthenticationMarshaller.

@ConditionalOnMissingBean(name = "soapAuthenticationMarshaller")
@Bean
public Jaxb2Marshaller soapAuthenticationMarshaller() {
    val marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath(GetSoapAuthenticationRequest.class.getPackageName());
    val props = new HashMap<String, Object>();
    props.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    props.put(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
    marshaller.setMarshallerProperties(props);
    marshaller.setValidationEventHandler(new DefaultValidationEventHandler());
    return marshaller;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) GetSoapAuthenticationRequest(org.apereo.cas.authentication.soap.generated.GetSoapAuthenticationRequest) DefaultValidationEventHandler(javax.xml.bind.helpers.DefaultValidationEventHandler) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 30 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);
    dataImportExportService.init();
    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)35 Bean (org.springframework.context.annotation.Bean)13 Test (org.junit.Test)7 MarshallingView (org.springframework.web.servlet.view.xml.MarshallingView)7 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 View (org.springframework.web.servlet.View)4 MappingJackson2JsonView (org.springframework.web.servlet.view.json.MappingJackson2JsonView)4 SimpleXml (com.hack23.cia.service.external.common.impl.test.SimpleXml)3 IOException (java.io.IOException)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)3 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)3 FixedContentNegotiationStrategy (org.springframework.web.accept.FixedContentNegotiationStrategy)3 HeaderContentNegotiationStrategy (org.springframework.web.accept.HeaderContentNegotiationStrategy)3 ContentNegotiatingViewResolver (org.springframework.web.servlet.view.ContentNegotiatingViewResolver)3 InternalResourceViewResolver (org.springframework.web.servlet.view.InternalResourceViewResolver)3 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 lombok.val (lombok.val)2