Package org.apache.axiom.om

Examples of org.apache.axiom.om.OMSourcedElement


        // Make sure the Axiom structure is intact
        SOAPEnvelope env = axisMC.getEnvelope();
        SOAPBody body = env.getBody();
        OMElement child = body.getFirstElement();
        assertTrue(child instanceof OMSourcedElement);
        OMSourcedElement omse = (OMSourcedElement) child;
        assertTrue(!omse.isExpanded());
        OMDataSource ds = omse.getDataSource();
        assertTrue(ds instanceof JAXBBlockImpl);
       
        // Now simulate persisting the message
        File theFile = null;
        String theFilename = null;
        theFile = File.createTempFile("MessagePersistTest", null);
        //theFile.deleteOnExit();
        theFilename = theFile.getName();
        System.out.println("temp file = [" + theFilename + "]");
       
        // Setup an output stream to a physical file
        FileOutputStream outStream = new FileOutputStream(theFile);

        // Attach a stream capable of writing objects to the
        // stream connected to the file
        ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);

        // Try to save the message context
        System.out.println("saving message context.....");
        outObjStream.writeObject(axisMC);

        // Close out the streams
        outObjStream.flush();
        outObjStream.close();
        outStream.flush();
        outStream.close();
        System.out.println("....saved message context.....");
        long filesize = theFile.length();
        System.out.println("file size after save [" + filesize
                + "]   temp file = [" + theFilename + "]");
       
        // Make sure the Axiom structure is intact. 
        env = axisMC.getEnvelope();
        body = env.getBody();
        child = body.getFirstElement();
        assertTrue(child instanceof OMSourcedElement);
        omse = (OMSourcedElement) child;
        assertTrue(!omse.isExpanded());
        ds = omse.getDataSource();
        assertTrue(ds instanceof JAXBBlockImpl);
       
        // Simulate transport
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OMOutputFormat outputFormat = new OMOutputFormat();
View Full Code Here


        // Make sure the Axiom structure is intact
        SOAPEnvelope env = axisMC.getEnvelope();
        SOAPBody body = env.getBody();
        OMElement child = body.getFirstElement();
        assertTrue(child instanceof OMSourcedElement);
        OMSourcedElement omse = (OMSourcedElement) child;
        assertTrue(!omse.isExpanded());
        OMDataSource ds = omse.getDataSource();
        assertTrue(ds instanceof JAXBBlockImpl);
       
        // Now simulate persisting the message in memory
        SOAPEnvelope env2 = CopyUtils.copy(env);
       
        // Make sure the Axiom structure is intact. 
        env = axisMC.getEnvelope();
        body = env.getBody();
        child = body.getFirstElement();
        assertTrue(child instanceof OMSourcedElement);
        omse = (OMSourcedElement) child;
        assertTrue(!omse.isExpanded());
        ds = omse.getDataSource();
        assertTrue(ds instanceof JAXBBlockImpl);
       
        // Simulate transport
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OMOutputFormat outputFormat = new OMOutputFormat();
        outputFormat.setDoOptimize(true);
        outputFormat.setMimeBoundary("MIMEBoundary_Axis2Rocks");
        env.serializeAndConsume(baos, outputFormat);

        String newText = baos.toString();
        System.out.println(newText);
        assertTrue(newText.contains("soap"));
        assertTrue(newText.contains("Envelope"));
        assertTrue(newText.contains("Body"));
        assertTrue(newText.indexOf("MIMEBoundary_Axis2Rocks") > 0);
        assertTrue(newText.indexOf(sampleText) > 0);
        assertTrue(newText.indexOf("<soapenv:Body><sendImage xmlns=\"urn://mtom.test.org\"><input><imageData><xop:Include") > 0);    
       
        // Now check the copied envelope
        body = env2.getBody();
        child = body.getFirstElement();
        assertTrue(child instanceof OMSourcedElement);
        omse = (OMSourcedElement) child;
        assertTrue(!omse.isExpanded());
        ds = omse.getDataSource();
        assertTrue(ds instanceof JAXBDataSource);
       
        // Simulate transport on the copied message
        baos = new ByteArrayOutputStream();
        outputFormat = new OMOutputFormat();
View Full Code Here

            OMNamespace ns = factory.createOMNamespace(namespace, reader.getPrefix());
           
            Object jaxb = jdsContext.unmarshal(reader);
           
            OMDataSource ds = new JAXBDataSource(jaxb, jdsContext);
            OMSourcedElement omse = factory.createOMElement(ds, localPart, ns);
           
            parent.addChild(omse);
            JAXBCustomBuilderMonitor.updateTotalCreates();
            return omse;
        } catch (JAXBException e) {
View Full Code Here

    public void testGetTextAsStreamWithOMSourcedElement() throws Exception {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        DataSource ds = new RandomDataSource(445566, 32, 128, 20000000);
        QName qname = new QName("a");
        Charset cs = Charset.forName("ascii");
        OMSourcedElement element = new OMSourcedElementImpl(qname, factory,
                new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, cs));
        Reader in = ElementHelper.getTextAsStream(element, true);
        assertFalse(in instanceof StringReader);
        compareStreams(new InputStreamReader(ds.getInputStream(), cs), in);
    }
View Full Code Here

   
    public void testWriteTextToWithOMSourcedElement() throws Exception {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        DataSource ds = new RandomDataSource(665544, 32, 128, 20000000);
        QName qname = new QName("a");
        OMSourcedElement element = new OMSourcedElementImpl(qname, factory,
                new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, Charset.forName("ascii")));
        Reader in = new InputStreamReader(ds.getInputStream(), "ascii");
        Writer out = new CharacterStreamComparator(in);
        ElementHelper.writeTextTo(element, out, true); // cache doesn't matter here
        out.close();
View Full Code Here

        }
        String testData = buffer.toString();
        QName qname = new QName("data");
        OMDataSource ds = new WrappedTextNodeOMDataSourceFromReader(qname, new StringReader(testData));
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMSourcedElement element = new OMSourcedElementImpl(qname, factory, ds);
        assertEquals(testData, element.getText());
    }
View Full Code Here

            SOAPFaultDetail detail = factory.createSOAPFaultDetail(soapFault);
            if (!ignoreDetailBlocks) {
                for (int i = 0; i < blocks.length; i++) {
                    // A Block implements OMDataSource.  So create OMSourcedElements
                    // for each of the Blocks.
                    OMSourcedElement element =
                            factory.createOMElement(blocks[i], blocks[i].getQName());
                    detail.addChild(element);
                }
            }
        }
View Full Code Here

        writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);

        // Now use StreamingOMSerializer to write the input stream to the output stream
        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
        SOAPBody body = env.getBody();
        OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
       
        StreamingOMSerializer serializer = new StreamingOMSerializer();
        serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
                             writer);
        writer.flush();

        String outputString = new String(byteArrayOutputStream.toByteArray());
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString != null && !"".equals(outputString) && outputString.length() > 1);
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("axis2:input"));
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("This is some text"));
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("Some Other Text"));
       
        assertTrue("Expectation is that an OMSourcedElement was created for the payload",
                omse != null);
        assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
                !omse.isExpanded());
    }
View Full Code Here

        writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);

        // Now use StreamingOMSerializer to write the input stream to the output stream
        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
        SOAPBody body = env.getBody();
        OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
       
        StreamingOMSerializer serializer = new StreamingOMSerializer();
        serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
                             writer);
        writer.flush();

        String outputString = new String(byteArrayOutputStream.toByteArray());
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString != null && !"".equals(outputString) && outputString.length() > 1);
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("Hello World"));
       
        assertTrue("Expectation is that an OMSourcedElement was created for the payload",
                omse != null);
        assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
                !omse.isExpanded());
    }
View Full Code Here

        writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);

        // Now use StreamingOMSerializer to write the input stream to the output stream
        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
        SOAPBody body = env.getBody();
        OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
       
        StreamingOMSerializer serializer = new StreamingOMSerializer();
        serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
                             writer);
        writer.flush();

        String outputString = new String(byteArrayOutputStream.toByteArray());
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString != null && !"".equals(outputString) && outputString.length() > 1);
        int indexHelloWorld = outputString.indexOf("Hello World");
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                indexHelloWorld > 0);
        int indexHelloWorld2 = outputString.indexOf("Hello World", indexHelloWorld+1);
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                indexHelloWorld2 < 0);

        assertTrue("Expectation is that an OMSourcedElement was created for the payload",
                omse != null);
        assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
                !omse.isExpanded());
    }
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.OMSourcedElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.