Example usage for org.springframework.oxm.jaxb Jaxb2Marshaller Jaxb2Marshaller

List of usage examples for org.springframework.oxm.jaxb Jaxb2Marshaller Jaxb2Marshaller

Introduction

In this page you can find the example usage for org.springframework.oxm.jaxb Jaxb2Marshaller Jaxb2Marshaller.

Prototype

Jaxb2Marshaller

Source Link

Usage

From source file:org.agatom.springatom.data.xml.OXMLConfiguration.java

/**
 * <p>getJaxbMarshaller.</p>
 *
 * @return a {@link org.springframework.oxm.jaxb.Jaxb2Marshaller} object.
 *//*  ww w .  j a  v a 2s  .com*/
@Bean(name = "jaxbMarshaller")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public Jaxb2Marshaller getJaxbMarshaller() {
    final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setLazyInit(this.environment.getProperty("springatom.oxm.lazyInit", Boolean.class));
    jaxb2Marshaller.setPackagesToScan(
            StringUtils.split(this.environment.getProperty("springatom.oxm.packagesToScan"), ","));
    jaxb2Marshaller.setCheckForXmlRootElement(true);
    jaxb2Marshaller.setProcessExternalEntities(true);
    return jaxb2Marshaller;
}

From source file:py.una.pol.karaku.test.configuration.WebServiceTestConfiguration.java

/**
 * @return/*from   www . j  a va2 s .  com*/
 */
private Jaxb2Marshaller jaxb2Marshaller() {

    if (marshaller == null) {
        marshaller = new Jaxb2Marshaller();
        marshaller.setClassesToBeBound(getClassesToBound());
    }
    return marshaller;
}

From source file:py.una.pol.karaku.test.test.services.KarakuFaultMessageResolverTest.java

@Test
public void testResolvXteFault_NormalException() throws Exception {

    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(HTTPExceptionDTO.class);

    KarakuFaultMessageResolver resolver = new KarakuFaultMessageResolver(marshaller);
    // @formatter:off
    SOAPMessage message = getFromString(
            "" + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
                    + "   <SOAP-ENV:Header/> " + "   <SOAP-ENV:Body> " + "      <SOAP-ENV:Fault> "
                    + "         <faultcode>SOAP-ENV:Client</faultcode> "
                    + "         <faultstring xml:lang=\"en\">Invalid request</faultstring> "
                    + "      </SOAP-ENV:Fault>" + "   </SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>");
    // @formatter:on

    SaajSoapMessage ssm = new SaajSoapMessage(message);
    try {/*from  ww w .j ava2s  .c o m*/
        resolver.resolveFault(ssm);
        fail();
    } catch (SoapFaultClientException exception) {
        assertEquals("Client", exception.getFaultCode().getLocalPart());
        assertEquals("Invalid request", exception.getFaultStringOrReason());
    }
}

From source file:com.hp.autonomy.types.idol.AbstractParsingTest.java

@Test
public void symmetry() throws IOException, SAXException {
    final ResponseParser responseParser = getResponseParser(marshallerFactory, type);
    final Autnresponse autnresponse = responseParser
            .parseResponse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));

    final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setClassesToBeBound(Autnresponse.class, type);

    final String generatedXml;
    try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        jaxb2Marshaller.marshal(autnresponse, new StreamResult(outputStream));
        generatedXml = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
    }/*from  w w w . j a v a 2  s.c  om*/

    // Void equates to an empty responsedata element which we can't regenerate
    if (!Void.class.equals(type)) {
        XMLUnit.setIgnoreWhitespace(true);
        XMLUnit.setIgnoreComments(true);
        XMLUnit.setIgnoreAttributeOrder(true);
        final Diff diff = new Diff(xml, generatedXml);
        diff.overrideDifferenceListener(new XMLDifferenceListener());
        assertXMLEqual(diff, true);
    }
}

From source file:org.cleverbus.common.Tools.java

/**
 * Unmarshals XML into object graph./*from   w  w  w  .j  av a 2  s  . c o m*/
 *
 * @param xml the input string
 * @param targetClass the target class
 * @return object graph
 * @see XmlConverter
 */
@SuppressWarnings("unchecked")
public static <T> T unmarshalFromXml(String xml, Class<T> targetClass) {
    Jaxb2Marshaller jaxb2 = new Jaxb2Marshaller();
    jaxb2.setContextPath(targetClass.getPackage().getName());

    return (T) jaxb2.unmarshal(new StreamSource(new StringReader(xml)));
}

From source file:org.osgpfoundation.osgp.webdemoapp.infra.platform.SoapRequestHelper.java

/**
 * Initializes the JaxB Marshaller/* w ww. j  a  v a  2s  .  c om*/
 *
 * @param marshallerContext
 */
private void initMarshaller(final String marshallerContext) {
    this.marshaller = new Jaxb2Marshaller();

    this.marshaller.setContextPath(marshallerContext);
}

From source file:org.muhia.app.psi.integ.config.ke.crba.CreditReferenceBureauAuthorityClientConfiguration.java

@Bean(name = "transunionMarshaller")
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    //        marshaller.setContextPaths(properties.getCrbaTransunionMarshallerContext().split(","));
    marshaller.setPackagesToScan(properties.getCrbaTransunionMarshallerContext().split(","));

    return marshaller;
}

From source file:edu.wisc.my.portlets.feedback.dao.InfraWebServiceFeedbackSenderImpl.java

public void afterPropertiesSet() throws Exception {
    // initialize JAXB2
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("edu.wisc.kb.infra.ws");
    marshaller.afterPropertiesSet();/* w w  w  .  java2  s  .co m*/
    webServiceTemplate.setMarshaller(marshaller);
    webServiceTemplate.setUnmarshaller(marshaller);

    // Tell webServiceTemplate to use CommonsHttpMessageSender
    CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
    // allow 4 seconds for connect timeout
    messageSender.setConnectionTimeout(4000);
    // allow 20 seconds for infra web service to return
    messageSender.setReadTimeout(20000);
    webServiceTemplate.setMessageSender(messageSender);

    // create WSDL destination provider, override locationExpression to point to correct URI
    Wsdl11DestinationProvider provider = new Wsdl11DestinationProvider();
    provider.setWsdl(wsdlResource);
    webServiceTemplate.setDestinationProvider(provider);
    LOG.info("webServiceTemplate configuration complete; wsdl: " + wsdlResource.getURI().toString());
}

From source file:org.muhia.app.psi.integ.config.ke.crba.CreditReferenceBureauAuthorityClientConfiguration.java

@Bean(name = "transunionUnmarshaller")
public Jaxb2Marshaller unmarshaller() {
    Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
    /*//from ww  w. j a v  a 2 s  .co  m
    TODO: Find out what contextPath means and how to configure
     */
    //        unmarshaller.setContextPaths(properties.getCrbaTransunionUnmarshallerContext().split(","));
    unmarshaller.setPackagesToScan(properties.getCrbaTransunionUnmarshallerContext().split(","));

    return unmarshaller;
}

From source file:org.muhia.app.psi.integ.config.ke.obopay.ObopayBulkApiClientConfiguration.java

@Bean(name = "obopayBulkApiMarshaller")
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setPackagesToScan(properties.getBulkpaymentMarshallerPackagesToscan().split(","));
    return marshaller;
}