Here are the examples of the java api org.springframework.oxm.jaxb.Jaxb2Marshaller taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
102 Examples
19
View Source File : ViewResolutionTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testXmlOnly() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(Person.clreplaced);
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")));
}
19
View Source File : MarshallingMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Before
public void createMarshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(MyBean.clreplaced);
marshaller.afterPropertiesSet();
this.converter = new MarshallingMessageConverter(marshaller);
}
19
View Source File : JaxbElementWrapperTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void processEmptyRegistry() {
// given
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(EmptyRegistry.clreplaced);
JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller);
Object input = new Empty();
// when
Object processed = jaxbElementWrapper.process(input);
// then
replacedertThat(processed, is(input));
}
19
View Source File : JaxbElementWrapperTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void processEmptySecondEmptyWithRegistryAndWrapperCache() {
// given
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(Registry.clreplaced);
JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller);
Object input = new Empty();
Object input2 = new SecondEmpty();
// when
Object processed = jaxbElementWrapper.process(input);
Object processed2 = jaxbElementWrapper.process(input2);
// then
replacedertTrue(processed instanceof JAXBElement);
replacedertThat(((JAXBElement) processed).getValue(), is(input));
replacedertTrue(processed2 instanceof JAXBElement);
replacedertThat(((JAXBElement) processed2).getValue(), is(input2));
Set<Map.Entry<Clreplaced<?>, Object>> wrapperCache = jaxbElementWrapper.getWrapperCache().entrySet();
replacedertThat(wrapperCache, hreplacedize(1));
Map.Entry<Clreplaced<?>, Object> wrapper = wrapperCache.iterator().next();
replacedertEquals(Registry.clreplaced, wrapper.getKey());
replacedertThat(wrapper.getValue(), notNullValue());
}
19
View Source File : JaxbElementWrapperTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void processEmptyWithRegistry() {
// given
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(Registry.clreplaced);
JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller);
Object input = new Empty();
// when
Object processed = jaxbElementWrapper.process(input);
// then
replacedertTrue(processed instanceof JAXBElement);
replacedertThat(((JAXBElement) processed).getValue(), is(input));
}
19
View Source File : JaxbElementWrapperTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void processJaxbElement() {
// given
Jaxb2Marshaller marshaller = mock(Jaxb2Marshaller.clreplaced);
JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller);
Object input = new JAXBElement<>(new QName("localPart"), Empty.clreplaced, new Empty());
// when
Object processed = jaxbElementWrapper.process(input);
// then
verify(marshaller, never()).getContextPath();
verify(marshaller, never()).getClreplacedesToBeBound();
replacedertThat(processed, is(input));
}
19
View Source File : JaxbElementWrapperTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void processRootWithCache() {
// given
Jaxb2Marshaller marshaller = mock(Jaxb2Marshaller.clreplaced);
JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller);
Object input = new Root();
// when
Object processed = jaxbElementWrapper.process(input);
jaxbElementWrapper.process(input);
// then
verify(marshaller, never()).getContextPath();
verify(marshaller, never()).getClreplacedesToBeBound();
replacedertThat(processed, is(input));
}
19
View Source File : JaxbElementWrapperTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void processEmptyWithWrapperMethodCache() {
// given
Jaxb2Marshaller marshaller = mock(Jaxb2Marshaller.clreplaced);
when(marshaller.getClreplacedesToBeBound()).thenReturn(new Clreplaced[] {});
JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller);
Object input = new Empty();
// when
Object processed = jaxbElementWrapper.process(input);
jaxbElementWrapper.process(input);
// then
verify(marshaller).getContextPath();
verify(marshaller).getClreplacedesToBeBound();
replacedertThat(processed, is(input));
}
19
View Source File : Jaxb2PrinterTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void serializeJaxbElement() {
// given
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClreplacedesToBeBound(Empty.clreplaced);
Jaxb2Printer jaxb2Printer = new Jaxb2Printer(jaxb2Marshaller);
Empty empty = new Empty();
empty.setValue("value");
JAXBElement<Empty> jaxbElement = new JAXBElement<>(new QName("localPart"), Empty.clreplaced, empty);
// when
String xml = jaxb2Printer.serialize(jaxbElement);
// then
replacedertThat(xml, is("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><localPart><value>value</value></localPart>"));
}
19
View Source File : Jaxb2PrinterTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test(expected = MarshallingFailureException.clreplaced)
public void serializeXmlEmpty() {
// given
Jaxb2Marshaller jaxb2Marshaller = mock(Jaxb2Marshaller.clreplaced);
doThrow(new MarshallingFailureException("")).when(jaxb2Marshaller).marshal(any(), any());
Jaxb2Printer jaxb2Printer = new Jaxb2Printer(jaxb2Marshaller);
Empty empty = new Empty();
empty.setValue("value");
// when
jaxb2Printer.serialize(empty);
// then expected exception
}
19
View Source File : Jaxb2PrinterTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test(expected = XmlMappingException.clreplaced)
public void serializeXmlNotRoot() {
// given
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClreplacedesToBeBound(Root.clreplaced);
Jaxb2Printer jaxb2Printer = new Jaxb2Printer(jaxb2Marshaller);
NotRoot notRoot = new NotRoot();
notRoot.setValue("value");
// when
jaxb2Printer.serialize(notRoot);
// then expected exception
}
19
View Source File : Jaxb2PrinterTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void serializeRoot() {
// given
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClreplacedesToBeBound(Root.clreplaced);
Jaxb2Printer jaxb2Printer = new Jaxb2Printer(jaxb2Marshaller);
Root root = new Root();
root.setValue("value");
// when
String xml = jaxb2Printer.serialize(root);
// then
replacedertThat(xml, is("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><someName><value>value</value></someName>"));
}
19
View Source File : Jaxb2PrinterTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test(expected = MarshallingFailureException.clreplaced)
public void serializeException() {
// given
Jaxb2Marshaller jaxb2Marshaller = mock(Jaxb2Marshaller.clreplaced);
doThrow(new MarshallingFailureException("")).when(jaxb2Marshaller).marshal(any(), any());
Jaxb2Printer jaxb2Printer = new Jaxb2Printer(jaxb2Marshaller);
Root root = new Root();
root.setValue("value");
// when
jaxb2Printer.serialize(root);
// then expected exception
}
19
View Source File : LogInSimpleLoggerTest.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
@Test
public void printers() {
// given
Printer inLogPrinter = new Printer() {
@Override
protected String serialize(Object input) {
return "!";
}
};
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(Dto.clreplaced);
// when
SimpleLogger logger = new SimpleLoggerBuilder().method(methodWithParameters).parameterNames("s", "i", "dto").arguments("s", 1, new Dto()).levels(DEBUG, OFF, DEBUG).printers(nCopies(3, inLogPrinter)).parameterLog(DEBUG, OFF, DEBUG, new JacksonPrinter(new ObjectMapper())).parameterLog(null).parameterLog(DEBUG, OFF, DEBUG, new Jaxb2Printer(marshaller)).effectiveLevel(DEBUG).buildAndInvokeAndGet();
// then
verify(logger.getLoggerFacadeFactory().getLoggerFacade(any())).log(DEBUG, "> s=\"s\", i=!, dto=<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><dto><i>0</i></dto>");
}
19
View Source File : JaxbElementWrapper.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
private Clreplaced<?>[] findWrapperClreplacedes(Jaxb2Marshaller jaxb2Marshaller) {
String contextPath = jaxb2Marshaller.getContextPath();
if (!hasText(contextPath)) {
return jaxb2Marshaller.getClreplacedesToBeBound();
}
List<Clreplaced<?>> clreplacedes = new ArrayList<>();
for (String path : contextPath.split(":")) {
for (Resource resource : pathToResources(path)) {
if (resource.isReadable()) {
clreplacedes.add(forName(resource));
}
}
}
return clreplacedes.toArray(new Clreplaced[clreplacedes.size()]);
}
19
View Source File : JaxbElementWrapper.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
private Object wrap(Jaxb2Marshaller jaxb2Marshaller, Object input) {
Clreplaced<?> clazz = input.getClreplaced();
Object cached = wrapperMethodCache.get(clazz);
if (nonNull(cached)) {
return cached == EMPTY_METHOD ? input : wrap(input, (Method) cached);
}
Clreplaced<?>[] wrapperClreplacedes = findWrapperClreplacedes(jaxb2Marshaller);
if (isNull(wrapperClreplacedes)) {
wrapperMethodCache.put(clazz, EMPTY_METHOD);
return input;
}
Method method = findMethod(wrapperClreplacedes, clazz);
if (isNull(method)) {
wrapperMethodCache.put(clazz, EMPTY_METHOD);
return input;
}
wrapperMethodCache.put(clazz, method);
return wrap(input, method);
}
19
View Source File : Jaxb2Printer.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
/**
* @author Vyacheslav Klapatnyuk
*/
public clreplaced Jaxb2Printer extends Printer {
private final Jaxb2Marshaller jaxb2Marshaller;
public Jaxb2Printer(Jaxb2Marshaller jaxb2Marshaller) {
this.jaxb2Marshaller = jaxb2Marshaller;
}
@Override
protected String serialize(Object input) throws XmlMappingException {
StringWriter writer = new StringWriter();
jaxb2Marshaller.marshal(input, new StreamResult(writer));
return writer.toString();
}
}
19
View Source File : MarshallingMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@BeforeEach
public void createMarshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(MyBean.clreplaced);
marshaller.afterPropertiesSet();
this.converter = new MarshallingMessageConverter(marshaller);
}
19
View Source File : JaxbConfiguration.java
License : GNU Affero General Public License v3.0
Project Creator : progilone
License : GNU Affero General Public License v3.0
Project Creator : progilone
@Bean
public Jaxb2Marshaller getMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("fr.progilone");
return marshaller;
}
19
View Source File : SharePointConfiguration.java
License : MIT License
Project Creator : PreCyz
License : MIT License
Project Creator : PreCyz
@Bean
Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("pg.gipter.toolkit.ws");
return marshaller;
}
19
View Source File : WebApplicationContextConfig.java
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
@Bean
public MarshallingView xmlView() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(Product.clreplaced);
MarshallingView xmlView = new MarshallingView(marshaller);
return xmlView;
}
19
View Source File : JasperWirelessConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
@Bean
public Jaxb2Marshaller marshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPaths("com.jasperwireless.api.ws.service");
return marshaller;
}
19
View Source File : NotificationClientConfigBase.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
@Bean
public DefaultWebServiceTemplateFactory createWebServiceTemplateFactory(final Jaxb2Marshaller marshaller) {
final DefaultWebServiceTemplateFactory.Builder builder = new DefaultWebServiceTemplateFactory.Builder();
builder.setMarshaller(marshaller).setMessageFactory(this.messageFactory()).setTargetUri(this.webserviceNotificationUrl).setMaxConnectionsPerRoute(this.maxConnectionsPerRoute).setMaxConnectionsTotal(this.maxConnectionsTotal).setApplicationName(this.applicationName).setSecurityEnabled(this.webserviceNotificationSecurityEnabled);
if (this.webserviceNotificationSecurityEnabled) {
builder.setKeyStoreType(this.webserviceKeystoreType).setKeyStoreLocation(this.webserviceKeystoreLocation).setKeyStorePreplacedword(this.webserviceKeystorePreplacedword).setTrustStoreFactory(this.webServiceTrustStoreFactory());
}
return builder.build();
}
19
View Source File : NotificationWebServiceTemplateFactory.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
private void setMarshaller(final WebServiceTemplate template, final String contextPath) {
final Jaxb2Marshaller marshaller = this.createMarshaller(contextPath);
template.setMarshaller(marshaller);
template.setUnmarshaller(marshaller);
}
19
View Source File : AbstractAsyncRequestBuilder.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
public abstract clreplaced AbstractAsyncRequestBuilder<T> {
protected String deviceIdentification;
protected String correlationUid;
protected Clreplaced<?> contextClreplaced;
protected Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
public AbstractAsyncRequestBuilder(final Clreplaced<?> contextClreplaced) {
super();
this.contextClreplaced = contextClreplaced;
}
public AbstractAsyncRequestBuilder<T> withDeviceidentification(final String deviceIdentification) {
this.deviceIdentification = deviceIdentification;
return this;
}
public AbstractAsyncRequestBuilder<T> withCorrelationUid(final String correlationUid) {
this.correlationUid = correlationUid;
return this;
}
public AbstractAsyncRequestBuilder<T> fromContext() {
this.correlationUid = (String) ScenarioContext.current().get(PlatformKeys.KEY_CORRELATION_UID);
this.deviceIdentification = (String) ScenarioContext.current().get(PlatformKeys.KEY_DEVICE_IDENTIFICATION);
return this;
}
public abstract T build();
}
19
View Source File : MvcAutoConfiguration.java
License : Apache License 2.0
Project Creator : MaxKeyTop
License : Apache License 2.0
Project Creator : MaxKeyTop
/**
* marshallingHttpMessageConverter .
* @return marshallingHttpMessageConverter
*/
@Bean(name = "marshallingHttpMessageConverter")
public MarshallingHttpMessageConverter marshallingHttpMessageConverter(Jaxb2Marshaller jaxb2Marshaller) {
MarshallingHttpMessageConverter marshallingHttpMessageConverter = new MarshallingHttpMessageConverter();
marshallingHttpMessageConverter.setMarshaller(jaxb2Marshaller);
marshallingHttpMessageConverter.setUnmarshaller(jaxb2Marshaller);
ArrayList<MediaType> mediaTypesList = new ArrayList<MediaType>();
mediaTypesList.add(MediaType.APPLICATION_XML);
mediaTypesList.add(MediaType.TEXT_XML);
mediaTypesList.add(MediaType.TEXT_PLAIN);
marshallingHttpMessageConverter.setSupportedMediaTypes(mediaTypesList);
return marshallingHttpMessageConverter;
}
19
View Source File : MvcAutoConfiguration.java
License : Apache License 2.0
Project Creator : MaxKeyTop
License : Apache License 2.0
Project Creator : MaxKeyTop
/**
* jaxb2Marshaller .
* @return jaxb2Marshaller
*/
@Bean(name = "jaxb2Marshaller")
public Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClreplacedesToBeBound(org.maxkey.domain.xml.UserInfoXML.clreplaced);
;
return jaxb2Marshaller;
}
19
View Source File : CustomerConfig.java
License : GNU General Public License v3.0
Project Creator : kbastani
License : GNU General Public License v3.0
Project Creator : kbastani
@Bean
public CustomerClient weatherClient(Jaxb2Marshaller marshaller) {
CustomerClient client = new CustomerClient();
client.setDefaultUri(String.format("%s/v1/customers", customerUri));
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
19
View Source File : TestEnphaseSystemInfoConfig.java
License : Mozilla Public License 2.0
Project Creator : dlmcpaul
License : Mozilla Public License 2.0
Project Creator : dlmcpaul
@Bean
public Unmarshaller enphaseMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(EnvoyInfo.clreplaced, EnvoyPackage.clreplaced, EnvoyDevice.clreplaced);
return marshaller;
}
19
View Source File : EnphaseSystemInfoConfig.java
License : Mozilla Public License 2.0
Project Creator : dlmcpaul
License : Mozilla Public License 2.0
Project Creator : dlmcpaul
@Bean
public Unmarshaller enphaseMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(EnvoyInfo.clreplaced, EnvoyPackage.clreplaced, EnvoyDevice.clreplaced, BuildInfo.clreplaced);
return marshaller;
}
18
View Source File : ViewResolutionTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testContentNegotiation() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClreplacedesToBeBound(Person.clreplaced);
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();
MockMvc mockMvc = standaloneSetup(new PersonController()).setViewResolvers(cnViewResolver, new InternalResourceViewResolver()).build();
mockMvc.perform(get("/person/Corea")).andExpect(status().isOk()).andExpect(model().size(1)).andExpect(model().attributeExists("person")).andExpect(forwardedUrl("person/show"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.person.name").value("Corea"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_XML)).andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
18
View Source File : OxmNamespaceHandlerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void jaxb2ClreplacedesToBeBoundMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ClreplacedesMarshaller", Jaxb2Marshaller.clreplaced);
replacedertNotNull(jaxb2Marshaller);
}
18
View Source File : OxmNamespaceHandlerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void jaxb2ContextPathMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ContextPathMarshaller", Jaxb2Marshaller.clreplaced);
replacedertNotNull(jaxb2Marshaller);
}
18
View Source File : JaxbElementWrapper.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
License : Apache License 2.0
Project Creator : TinkoffCreditSystems
/**
* @author Vyacheslav Klapatnyuk
*/
public clreplaced JaxbElementWrapper implements PrinterPreProcessor {
/**
* Incorrect method for empty cache stub.
*/
private static final Method EMPTY_METHOD = BeanUtils.findMethod(JaxbElementWrapper.clreplaced, "process", Object.clreplaced);
private static final ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
private static final MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
private final Map<Clreplaced<?>, Method> wrapperMethodCache = new ConcurrentHashMap<>();
private final Map<Clreplaced<?>, Object> wrapperCache = new ConcurrentHashMap<>();
private final Jaxb2Marshaller jaxb2Marshaller;
public JaxbElementWrapper(Jaxb2Marshaller jaxb2Marshaller) {
this.jaxb2Marshaller = jaxb2Marshaller;
}
@Override
public Object process(Object input) {
if (input instanceof JAXBElement) {
return input;
}
if (nonNull(input.getClreplaced().getAnnotation(XmlRootElement.clreplaced))) {
return input;
}
return wrap(jaxb2Marshaller, input);
}
Map<Clreplaced<?>, Object> getWrapperCache() {
return wrapperCache;
}
private Object wrap(Jaxb2Marshaller jaxb2Marshaller, Object input) {
Clreplaced<?> clazz = input.getClreplaced();
Object cached = wrapperMethodCache.get(clazz);
if (nonNull(cached)) {
return cached == EMPTY_METHOD ? input : wrap(input, (Method) cached);
}
Clreplaced<?>[] wrapperClreplacedes = findWrapperClreplacedes(jaxb2Marshaller);
if (isNull(wrapperClreplacedes)) {
wrapperMethodCache.put(clazz, EMPTY_METHOD);
return input;
}
Method method = findMethod(wrapperClreplacedes, clazz);
if (isNull(method)) {
wrapperMethodCache.put(clazz, EMPTY_METHOD);
return input;
}
wrapperMethodCache.put(clazz, method);
return wrap(input, method);
}
private Clreplaced<?>[] findWrapperClreplacedes(Jaxb2Marshaller jaxb2Marshaller) {
String contextPath = jaxb2Marshaller.getContextPath();
if (!hasText(contextPath)) {
return jaxb2Marshaller.getClreplacedesToBeBound();
}
List<Clreplaced<?>> clreplacedes = new ArrayList<>();
for (String path : contextPath.split(":")) {
for (Resource resource : pathToResources(path)) {
if (resource.isReadable()) {
clreplacedes.add(forName(resource));
}
}
}
return clreplacedes.toArray(new Clreplaced[clreplacedes.size()]);
}
private Resource[] pathToResources(String path) {
String resourcePath = ClreplacedUtils.convertClreplacedNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(path));
String packageSearchPath = ResourcePatternResolver.CLreplacedPATH_ALL_URL_PREFIX + resourcePath + "/*.clreplaced";
try {
return resourcePatternResolver.getResources(packageSearchPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private Clreplaced<?> forName(Resource resource) {
try {
String clreplacedName = metadataReaderFactory.getMetadataReader(resource).getClreplacedMetadata().getClreplacedName();
return Clreplaced.forName(clreplacedName);
} catch (IOException | ClreplacedNotFoundException e) {
throw new RuntimeException(e);
}
}
private Method findMethod(Clreplaced<?>[] clreplacedes, Clreplaced<?> parameterClreplaced) {
for (Clreplaced<?> clazz : clreplacedes) {
if (nonNull(clazz.getAnnotation(XmlRegistry.clreplaced))) {
for (Method method : ReflectionUtils.getAllDeclaredMethods(clazz)) {
if (byParameterType(method, parameterClreplaced) && byReturnType(method, parameterClreplaced) && byAnnotation(method)) {
return method;
}
}
}
}
return null;
}
private boolean byParameterType(Method method, Clreplaced<?> parameterClreplaced) {
return method.getParameterCount() == 1 && method.getParameterTypes()[0].equals(parameterClreplaced);
}
private boolean byReturnType(Method method, Clreplaced<?> parameterClreplaced) {
Type genericReturnType = method.getGenericReturnType();
if (genericReturnType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericReturnType;
if (parameterizedType.getRawType().equals(JAXBElement.clreplaced)) {
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
if (actualTypeArguments.length == 1 && actualTypeArguments[0].equals(parameterClreplaced)) {
return true;
}
}
}
return false;
}
private boolean byAnnotation(Method method) {
return nonNull(method.getAnnotation(XmlElementDecl.clreplaced));
}
private Object wrap(Object input, Method method) {
Clreplaced<?> wrapperClreplaced = method.getDeclaringClreplaced();
Object wrapper = wrapperCache.computeIfAbsent(wrapperClreplaced, BeanUtils::instantiate);
return ReflectionUtils.invokeMethod(method, wrapper, input);
}
}
18
View Source File : BatchConfig.java
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
@Bean("writer2")
public ItemWriter<Permanent> xmlWriter() {
StaxEvenreplacedemWriter<Permanent> xmlFileWriter = new StaxEvenreplacedemWriter<>();
String exportFilePath = "./src/main/resources/emps.xml";
xmlFileWriter.setResource(new FileSystemResource(exportFilePath));
xmlFileWriter.setRootTagName("employees");
Jaxb2Marshaller empMarshaller = new Jaxb2Marshaller();
empMarshaller.setClreplacedesToBeBound(Permanent.clreplaced);
xmlFileWriter.setMarshaller(empMarshaller);
System.out.println("marshalling");
;
return xmlFileWriter;
}
18
View Source File : SoapClientConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
@Bean
Jaxb2Marshaller soapClientJaxb2Marshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setContextPath(XSD_SCHEMA_PACKAGE);
return jaxb2Marshaller;
}
18
View Source File : JasperWirelessConfigTest.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
@Bean
public Jaxb2Marshaller jasperWirelessMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.jasperwireless.api.ws.service");
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for schedule management.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller tariffSwitchingScheduleManagementMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.environment.getRequiredProperty(PROPERTY_NAME_MARSHALLER_CONTEXT_PATH_TARIFF_SWITCHING_SCHEDULE_MANAGEMENT));
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for schedule management.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller tariffSwitchingAdHocManagementMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.environment.getRequiredProperty(PROPERTY_NAME_MARSHALLER_CONTEXT_PATH_TARIFF_SWITCHING_AD_HOC_MANAGEMENT));
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for smart metering adhoc.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringAdhocMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.marshallerContextPathAdhoc);
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for smart metering monitoring.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringMonitoringMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.marshallerContextPathMonitoring);
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for smart metering configuration.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringConfigurationMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.marshallerContextPathConfiguration);
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for smart metering bundle.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringBundleMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.marshallerContextPathBundle);
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
// Client WS code
/**
* Method for creating the Marshaller for smart metering management.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringManagementMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.marshallerContextPathManagement);
return marshaller;
}
18
View Source File : WebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for smart metering installation.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringInstallationMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.marshallerContextPathInstallation);
return marshaller;
}
18
View Source File : NotificationClientConfigBase.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
public Jaxb2Marshaller notificationSenderMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.marshallerContextPathNotification);
return marshaller;
}
18
View Source File : NotificationWebServiceTemplateFactory.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
private Jaxb2Marshaller createMarshaller(final String contextPath) {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(contextPath);
return marshaller;
}
18
View Source File : SmartMeteringNotificationWebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
@Bean
public Jaxb2Marshaller smartMeteringNotificationMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.contextPathSmartMeteringNotification);
return marshaller;
}
18
View Source File : SmartMeteringMonitoringWebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for SmartMetering Monitoring
* webservice.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringMonitoringMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.configuration.contextPathSmartMeteringMonitoring);
return marshaller;
}
18
View Source File : SmartMeteringManagementWebServiceConfig.java
License : Apache License 2.0
Project Creator : OSGP
License : Apache License 2.0
Project Creator : OSGP
/**
* Method for creating the Marshaller for SmartMetering Management.
*
* @return Jaxb2Marshaller
*/
@Bean
public Jaxb2Marshaller smartMeteringManagementMarshaller() {
final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(this.configuration.contextPathSmartMeteringManagement);
return marshaller;
}
See More Examples