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.bremersee.common.spring.autoconfigure.JaxbAutoConfiguration.java

public static Jaxb2Marshaller createJaxbMarshaller(final Collection<String> packages) {
    final Set<String> packageSet = createPackageSet(packages);
    Jaxb2Marshaller m = new Jaxb2Marshaller();
    Map<String, Object> marshallerProperties = new HashMap<>();
    marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setMarshallerProperties(marshallerProperties);
    m.setContextPaths(packageSet.toArray(new String[packageSet.size()]));
    return m;/*from w  w  w. j  a v a2s .c  o  m*/
}

From source file:no.digipost.api.xml.Marshalling.java

public static Jaxb2Marshaller createNewMarshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setPackagesToScan(new String[] { packageName(StandardBusinessDocument.class),
            packageName(Envelope.class), packageName(org.w3.soap.Envelope.class),
            packageName(org.w3.xmldsig.Reference.class), packageName(Messaging.class),
            packageName(NonRepudiationInformation.class), packageName(SDPKvittering.class),
            packageName(XAdESSignatures.class), packageName(QualifyingProperties.class) });
    marshaller.setSchemas(Schemas.allSchemaResources());
    return marshaller;
}

From source file:org.openwms.core.app.ModuleConfiguration.java

public @Bean Unmarshaller unmarshaller() {
    Jaxb2Marshaller um = new Jaxb2Marshaller();
    um.setContextPath("org.openwms.core.configuration.file");
    return um;/*w w  w.j  a v a 2s .c o  m*/
}

From source file:frk.gpssimulator.GpsSimulatorApplication.java

@Bean
public Jaxb2Marshaller getMarshaller() {
    Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setClassesToBeBound(Kml.class);

    final Map<String, Object> map = new HashMap<>();
    map.put("jaxb.formatted.output", true);

    jaxb2Marshaller.setMarshallerProperties(map);
    return jaxb2Marshaller;
}

From source file:demo.GpsSimulatorApplication.java

@Bean
public Jaxb2Marshaller getMarshaller() {
    final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setClassesToBeBound(Kml.class);

    final Map<String, Object> map = new HashMap<>();
    map.put("jaxb.formatted.output", true);

    jaxb2Marshaller.setMarshallerProperties(map);
    return jaxb2Marshaller;
}

From source file:org.springsource.greenbeans.examples.edawithspring.etailer.common.MarshallingTests.java

private Marshaller jaxb2Marshaller() throws Exception {
    Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setClassesToBeBound(PurchaseProcessingRequest.class, PurchaseLineItem.class);
    jaxb2Marshaller.setSchema(new ClassPathResource("/partner-schema.xsd"));
    jaxb2Marshaller.afterPropertiesSet();
    jaxb2Marshaller.setBeanClassLoader(Thread.currentThread().getContextClassLoader());
    return jaxb2Marshaller;
}

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

/**
 * Marshals object graph into XML.// w w  w  .  j  ava  2s  .  c  o  m
 *
 * @param obj the object graph
 * @param sourceClass the input class
 * @return XML as string
 * @see XmlConverter
 */
public static String marshalToXml(Object obj, Class sourceClass) {
    Jaxb2Marshaller jaxb2 = new Jaxb2Marshaller();
    jaxb2.setContextPath(sourceClass.getPackage().getName());

    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);

    jaxb2.marshal(obj, result);

    return writer.toString();
}

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

/**
 * Test method for//from   w w  w.ja  v a  2  s .com
 * {@link py.una.pol.karaku.services.client.KarakuFaultMessageResolver#resolveFault(org.springframework.ws.WebServiceMessage)}
 * .
 */
@Test
public void testResolveFault_HTTPException() 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> " + "         <detail> "
            + "            <ns4:HTTPException xmlns:ns4=\"http://sigh.med.una.py/2013/schemas/base\"> "
            + "               <code>1</code>" + "               <summary>2</summary>"
            + "            </ns4:HTTPException>" + "         </detail>" + "      </SOAP-ENV:Fault>"
            + "   </SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>");
    // @formatter:on

    SaajSoapMessage ssm = new SaajSoapMessage(message);
    try {
        resolver.resolveFault(ssm);
        fail();
    } catch (HTTPException exception) {
        assertEquals("1", exception.getCode());
        assertEquals("2", exception.getShortDescription());
    }
}

From source file:com.example.job.CustomerJobConfiguration.java

@Bean(name = "customerMarshaller")
public Unmarshaller itemMarshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(Customer.class);
    return marshaller;
}

From source file:org.osgp.adapter.protocol.dlms.infra.ws.JasperWirelessConfigTest.java

@Bean
public Jaxb2Marshaller jasperWirelessMarshaller() {
    final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("com.jasperwireless.api.ws.service");
    return marshaller;
}