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");
}
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")));
}
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;
}
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;
}
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());
}
Aggregations