Search in sources :

Example 6 with JAXBOMDataSource

use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.

the class TestDataHandlerSerializationWithoutMTOM method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFactory factory = metaFactory.getSOAP11Factory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    // Construct the original message
    DocumentBean orgObject = new DocumentBean();
    orgObject.setId("123456");
    orgObject.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
    SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
    OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, orgObject));
    orgEnvelope.getBody().addChild(element);
    // Serialize the message
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    orgEnvelope.serialize(out);
    assertFalse(element.isExpanded());
    SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(new ByteArrayInputStream(out.toByteArray()), null).getSOAPEnvelope();
    DocumentBean object = (DocumentBean) context.createUnmarshaller().unmarshal(envelope.getBody().getFirstElement().getXMLStreamReader(false));
    assertEquals("some content", IOUtils.toString(object.getContent().getInputStream(), "utf-8"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) JAXBContext(javax.xml.bind.JAXBContext) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPFactory(org.apache.axiom.soap.SOAPFactory) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 7 with JAXBOMDataSource

use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.

the class TestExceptionDuringSerialization method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omFactory = metaFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    DocumentBean object = new DocumentBean();
    object.setId("test");
    OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, object));
    XMLStreamException exception = new XMLStreamException("TEST");
    try {
        element.serialize(new ExceptionXMLStreamWriterWrapper(StAX.createNullXMLStreamWriter(), exception));
        fail("Expected XMLStreamException");
    } catch (XMLStreamException ex) {
        assertSame(exception, ex);
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) XMLStreamException(javax.xml.stream.XMLStreamException) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) JAXBContext(javax.xml.bind.JAXBContext) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 8 with JAXBOMDataSource

use of org.apache.axiom.om.ds.jaxb.JAXBOMDataSource in project webservices-axiom by apache.

the class TestGetNameFromPlainObject method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omFactory = metaFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, new DocumentBean()));
    assertEquals("http://ws.apache.org/axiom/test/jaxb", element.getNamespaceURI());
    assertEquals("document", element.getLocalName());
    assertFalse(element.isExpanded());
    // Force expansion so that OMSourcedElement compares the namespace URI and local name
    // provided by JAXBOMDataSource with the actual name of the element
    element.getFirstOMChild();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) JAXBContext(javax.xml.bind.JAXBContext) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)8 JAXBOMDataSource (org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)8 OMFactory (org.apache.axiom.om.OMFactory)6 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)6 DocumentBean (org.apache.axiom.ts.jaxb.beans.DocumentBean)6 DataHandler (javax.activation.DataHandler)4 OMElement (org.apache.axiom.om.OMElement)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OMText (org.apache.axiom.om.OMText)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 SOAPFactory (org.apache.axiom.soap.SOAPFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStream (java.io.OutputStream)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 MemoryBlob (org.apache.axiom.blob.MemoryBlob)1 MultipartBody (org.apache.axiom.mime.MultipartBody)1 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)1 LinkIdentitiesType (org.example.identity.LinkIdentitiesType)1 ObjectFactory (org.example.identity.ObjectFactory)1