Package org.apache.axis2.om

Examples of org.apache.axis2.om.OMElement


    private OMElement createEnvelope(String fileName) throws Exception {

        DataHandler expectedDH;
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("http://example.org/mtom/data", "x");
        OMElement data = fac.createOMElement("Data", omNs);

        File dataFile = new File(fileName);
        FileDataSource dataSource = new FileDataSource(dataFile);
        expectedDH = new DataHandler(dataSource);
        OMText textData = fac.createText(expectedDH, true);
        data.addChild(textData);
        return data;
    }
View Full Code Here


        return data;
    }

    public OMElement testEchoXMLSync(String fileName) throws Exception {

        OMElement payload = createEnvelope(fileName);
        Options options = new Options();

        options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
        options.setTo(targetEPR);
        // enabling MTOM in the client side
View Full Code Here

    public void testArray() throws Exception {
        InputStream is = new FileInputStream("test-resources/xmls/array1.xml");
        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(is);

        StAXOMBuilder builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), reader);
        OMElement el = builder.getDocumentElement();
        XMLStreamReader omReader = el.getXMLStreamReaderWithoutCaching();
        omReader.next();
        DeserializationContext context = new DeserializationContext();

        TypeDesc typeDesc = BeanManager.getTypeDesc(TestBean.class);
        BeanDeserializer dser = new BeanDeserializer(typeDesc);
View Full Code Here

        org.apache.axis2.om.impl.OMOutputImpl baseOutput = new OMOutputImpl(new FileOutputStream(outBase64File),
                false);

        OMNamespaceImpl soap = new OMNamespaceImpl(
                "http://schemas.xmlsoap.org/soap/envelope/", "soap");
        OMElement envelope = new OMElementImpl("Envelope", soap);
        OMElement body = new OMElementImpl("Body", soap);

        OMNamespaceImpl dataName = new OMNamespaceImpl(
                "http://www.example.org/stuff", "m");
        OMElement data = new OMElementImpl("data", dataName);

        expectedImage =
                new ImageIO().loadImage(
                        new FileInputStream(
                                getTestResourceFile(imageInFileName)));
        ImageDataSource dataSource = new ImageDataSource("WaterLilies.jpg",
                expectedImage);
        expectedDH = new DataHandler(dataSource);
        OMText binaryNode = new OMTextImpl(expectedDH, true);

        envelope.addChild(body);
        body.addChild(data);
        data.addChild(binaryNode);

        envelope.serialize(baseOutput);
        baseOutput.flush();

        envelope.serialize(mtomOutput);
View Full Code Here

                        new BufferedReader(
                                new InputStreamReader(
                                        mimeHelper
                .getSOAPPartInputStream())));
        builder = new MTOMStAXSOAPModelBuilder(reader, mimeHelper, null);
        OMElement root = builder.getDocumentElement();
        OMElement body = (OMElement) root.getFirstChild();
        OMElement data = (OMElement) body.getFirstChild();
        OMText blob = (OMText) data.getFirstChild();
        /*
         * Following is the procedure the user has to follow to read objects in
         * OBBlob User has to know the object type & whether it is serializable.
         * If it is not he has to use a Custom Defined DataSource to get the
         * Object.
 
View Full Code Here

        }
        Iterator elementOneChildren = elementOne.getChildren();
        while (elementOneChildren.hasNext()) {
            OMNode omNode = (OMNode) elementOneChildren.next();
            if (omNode instanceof OMElement) {
                OMElement elementOneChild = (OMElement) omNode;
                OMElement elementTwoChild = null;
                //Do the comparison only if the element is not ignorable
                if (!isIgnorable(elementOneChild)) {
                    Iterator elementTwoChildren = elementTwo.getChildren();
                    while (elementTwoChildren.hasNext() ) {
                        status = false;
                        OMNode node = (OMNode) elementTwoChildren.next();
                        if (node.getType() == OMNode.ELEMENT_NODE) {
                            elementTwoChild = (OMElement) node;
                            if (elementTwoChild.getLocalName().equals(elementOneChild.getLocalName())) {
                                //Do the comparison only if the element is not ignorable
                                if (!isIgnorable(elementTwoChild)) {
                                    if (elementTwoChild == null) {
                                        return false;
                                    }
View Full Code Here

    public void testGetText() {
        try {
            StAXSOAPModelBuilder soapBuilder = getOMBuilder(
                    "soap/OMElementTest.xml");
            SOAPEnvelope soapEnvelope = (SOAPEnvelope) soapBuilder.getDocumentElement();
            OMElement wsaTo = soapEnvelope.getHeader().getFirstChildWithName(
                    new QName(WSA_URI, WSA_TO));

            String expectedString = "http://localhost:8081/axis/services/BankPort";
            assertEquals("getText is not returning the correct value",
                    wsaTo.getText().trim(),
                    expectedString);
        } catch (Exception e) {
            log.info(e.getMessage());
        }
    }
View Full Code Here

    }

    public void testConstructors(){

        try {
            OMElement elementWithNoLocalName = factory.createOMElement("", null);
            fail("This should fail as OMElement should not be allowed to create without a local name ");
        } catch (Exception e) {
            assertTrue(true);
        }
View Full Code Here

    String ns = "http://testuri.org";
    OMNamespace namespace = factory.createOMNamespace(ns,"tst");
   
    String ln = "Child";
   
    OMElement bodyChild = factory.createOMElement(ln,namespace);
    bodyChild.addChild(factory.createText(value));
   
    envelope.getBody().addChild(bodyChild);


    ByteArrayOutputStream byteOutStr = new ByteArrayOutputStream();
   
    XMLStreamWriter writer = XMLOutputFactory
        .newInstance().createXMLStreamWriter(byteOutStr,UTF_16);
    OMOutputImpl outputImpl = new OMOutputImpl(writer);
        outputImpl.setCharSetEncoding(UTF_16);
    envelope.serializeWithCache(outputImpl);
    outputImpl.flush();
   
    ByteArrayInputStream byteInStr = new ByteArrayInputStream(byteOutStr.toByteArray());
   
    StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(XMLInputFactory.newInstance().createXMLStreamReader(byteInStr, UTF_16),null);

    SOAPEnvelope resultEnv = builder.getSOAPEnvelope();
   
    OMElement bodyChildResult = resultEnv.getBody().getFirstElement();
   
    assertNotNull("No child in body element", bodyChildResult);
   
    String result = bodyChildResult.getText();
   
    assertNotNull("No value for testParam param", result);
   
    assertEquals("Expected result not received.", expected, result);
 
View Full Code Here

                    detail.getText().trim().equals("Details of error"));

            Iterator iteratorInDetail = detail.getChildren();

            iteratorInDetail.next();
            OMElement element1 = (OMElement) iteratorInDetail.next();
            assertTrue("SOAP 1.2 :- MaxTime element mismatch",
                    element1.getLocalName().equals("MaxTime"));
            assertTrue("SOAP 1.2 :- MaxTime element namespace mismatch",
                    element1.getNamespace().getName().equals(
                            "http:www.sample.org"));
            assertTrue("SOAP 1.2 :- Text value in MaxTime element mismatch",
                    element1.getText().trim().equals("P5M"));

            Iterator attributeIterator = element1.getAttributes();
            OMAttribute attributeInMaxTime = (OMAttribute) attributeIterator.next();
            assertTrue("SOAP 1.2 :- Attribute local name mismatch",
                    attributeInMaxTime.getLocalName().equals("detail"));
            assertTrue("SOAP 1.2 :- Attribute namespace mismatch",
                    attributeInMaxTime.getNamespace().getName().equals(
                            "http:www.sample.org"));
            assertTrue("SOAP 1.2 :- Attribute value mismatch",
                    attributeInMaxTime.getValue().trim().equals("This is only a test"));

            iteratorInDetail.next();
            OMElement element2 = (OMElement) iteratorInDetail.next();
            assertTrue("SOAP 1.2 :- AveTime element mismatch",
                    element2.getLocalName().equals("AveTime"));
            assertTrue("SOAP 1.2 :- AveTime element namespace mismatch",
                    element2.getNamespace().getName().equals(
                            "http:www.sample.org"));

            Iterator iteratorInAveTimeElement = element2.getChildren();

            iteratorInAveTimeElement.next();
            OMElement element21 = (OMElement) iteratorInAveTimeElement.next();
            assertTrue("SOAP 1.2 :- Time element mismatch",
                    element21.getLocalName().equals("Time"));
            assertTrue("SOAP 1.2 :- Time element namespace mismatch",
                    element21.getNamespace().getName().equals(
                            "http:www.sample.org"));
            assertTrue("SOAP 1.2 :- Text value in Time element mismatch",
                    element21.getText().trim().equals("P3M"));

            XMLStreamReader sopa11Parser = XMLInputFactory.newInstance()
                    .createXMLStreamReader(new StringReader(soap11Message));
            OMXMLParserWrapper soap11Builder = new StAXSOAPModelBuilder(sopa11Parser, null);
            SOAPEnvelope soap11Envelope = (SOAPEnvelope) soap11Builder.getDocumentElement();
//            soap11Envelope.build();
//            writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
//            soap11Envelope.serialize(writer);
//        writer.flush();

            assertTrue("SOAP 1.1 :- envelope local name mismatch",
                    soap11Envelope.getLocalName().equals(
                            SOAPConstants.SOAPENVELOPE_LOCAL_NAME));
            assertTrue("SOAP 1.1 :- envelope namespace uri mismatch",
                    soap11Envelope.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

            header = soap11Envelope.getHeader();
            assertTrue("SOAP 1.1 :- Header local name mismatch",
                    header.getLocalName().equals(
                            SOAPConstants.HEADER_LOCAL_NAME));
            assertTrue("SOAP 1.1 :- Header namespace uri mismatch",
                    header.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

            headerBlock = (SOAPHeaderBlock) header.getFirstElement();
            assertTrue("SOAP 1.1 :- Header block name mismatch",
                    headerBlock.getLocalName().equals("echoOk"));
            assertTrue("SOAP 1.1 :- Header block name space uri mismatch",
                    headerBlock.getNamespace().getName().equals(
                            "http://example.org/ts-tests"));
            assertTrue("SOAP 1.1 :- Headaer block text mismatch",
                    headerBlock.getText().trim().equals("foo"));

            headerBlockAttributes = headerBlock.getAttributes();

            mustUnderstandAttribute =
                    (OMAttribute) headerBlockAttributes.next();
            assertTrue("SOAP 1.1 :- Mustunderstand attribute name mismatch",
                    mustUnderstandAttribute.getLocalName().equals(
                            SOAPConstants.ATTR_MUSTUNDERSTAND));
            assertTrue("SOAP 1.1 :- Mustunderstand value mismatch",
                    mustUnderstandAttribute.getValue().equals(
                            SOAPConstants.ATTR_MUSTUNDERSTAND_1));
            assertTrue(
                    "SOAP 1.1 :- Mustunderstand attribute namespace uri mismatch",
                    mustUnderstandAttribute.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

            OMAttribute actorAttribute = (OMAttribute) headerBlockAttributes.next();
            assertTrue("SOAP 1.1 :- Actor attribute name mismatch",
                    actorAttribute.getLocalName().equals(
                            SOAP11Constants.ATTR_ACTOR));
            assertTrue("SOAP 1.1 :- Actor value mismatch",
                    actorAttribute.getValue().trim().equals(
                            "http://schemas.xmlsoap.org/soap/" +
                    SOAP11Constants.ATTR_ACTOR +
                    "/" +
                    "next"));
            assertTrue("SOAP 1.1 :- Actor attribute namespace uri mismatch",
                    actorAttribute.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

            body = soap11Envelope.getBody();
            assertTrue("SOAP 1.1 :- Body local name mismatch",
                    body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));
            assertTrue("SOAP 1.1 :- Body namespace uri mismatch",
                    body.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

            fault = body.getFault();
            assertTrue("SOAP 1.1 :- Fault namespace uri mismatch",
                    fault.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

            iteratorInFault = fault.getChildren();

            iteratorInFault.next();
            code = (SOAPFaultCode) iteratorInFault.next();
            assertEquals("SOAP Fault code local name mismatch",
                    code.getLocalName(),
                    (SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
            assertTrue("SOAP 1.1 :- Fault code namespace uri mismatch",
                    code.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
            assertEquals("SOAP 1.1 :- Fault code value mismatch", code.getValue().getText().trim(),
                    "env:Sender");

            iteratorInFault.next();
            reason = (SOAPFaultReason) iteratorInFault.next();
            assertTrue("SOAP 1.1 :- Fault string local name mismatch",
                    reason.getLocalName().equals(
                            SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
            assertTrue("SOAP 1.2 :- Fault string namespace uri mismatch",
                    reason.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
            assertTrue("SOAP 1.1 :- Fault string value mismatch",
                    reason.getSOAPText().getText().trim().equals("Sender Timeout"));

            iteratorInFault.next();
            role = (SOAPFaultRole) iteratorInFault.next();
            assertTrue("SOAP 1.1 :- Fault actor local name mismatch",
                    role.getLocalName().equals(
                            SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
            assertTrue("SOAP 1.1 :- Fault actor namespace uri mismatch",
                    role.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
            assertTrue("SOAP 1.1 :- Actor value mismatch",
                    role.getText().trim().equals(
                            "http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver"));

            iteratorInFault.next();
            detail = (SOAPFaultDetail) iteratorInFault.next();
            assertTrue("SOAP 1.1 :- Fault detail local name mismatch",
                    detail.getLocalName().equals(
                            SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
            assertTrue("SOAP 1.1 :- Fault detail namespace uri mismatch",
                    detail.getNamespace().getName().equals(
                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
            assertTrue("SOAP 1.2 :- Text in detail mismatch",
                    detail.getText().trim().equals("Details of error"));

            iteratorInDetail = detail.getChildren();

            iteratorInDetail.next();
            element1 = (OMElement) iteratorInDetail.next();
            assertTrue("SOAP 1.1 :- MaxTime element mismatch",
                    element1.getLocalName().equals("MaxTime"));
            assertTrue("SOAP 1.1 :- MaxTime element namespace mismatch",
                    element1.getNamespace().getName().equals(
                            "http:www.sample.org"));
            assertTrue("SOAP 1.1 :- Text value in MaxTime element mismatch",
                    element1.getText().trim().equals("P5M"));

            attributeIterator = element1.getAttributes();
            attributeInMaxTime = (OMAttribute) attributeIterator.next();
            assertTrue("SOAP 1.1 :- Attribute local name mismatch",
                    attributeInMaxTime.getLocalName().equals("detail"));
            assertTrue("SOAP 1.1 :- Attribute namespace mismatch",
                    attributeInMaxTime.getNamespace().getName().equals(
                            "http:www.sample.org"));
            assertTrue("SOAP 1.1 :- Attribute value mismatch",
                    attributeInMaxTime.getValue().equals("This is only a test"));

            iteratorInDetail.next();
            element2 = (OMElement) iteratorInDetail.next();
            assertTrue("SOAP 1.1 :- AveTime element mismatch",
                    element2.getLocalName().equals("AveTime"));
            assertTrue("SOAP 1.1 :- AveTime element namespace mismatch",
                    element2.getNamespace().getName().equals(
                            "http:www.sample.org"));

            iteratorInAveTimeElement = element2.getChildren();

            iteratorInAveTimeElement.next();
            element21 = (OMElement) iteratorInAveTimeElement.next();
            assertTrue("SOAP 1.1 :- Time element mismatch",
                    element21.getLocalName().equals("Time"));
            assertTrue("SOAP 1.1 :- Time element namespace mismatch",
                    element21.getNamespace().getName().equals(
                            "http:www.sample.org"));
            assertTrue("SOAP 1.1 :- Text value in Time element mismatch",
                    element21.getText().trim().equals("P3M"));

            iteratorInFault.next();
            OMElement testElement = (OMElement) iteratorInFault.next();
            assertTrue("SOAP 1.1 :- Test element mismatch",
                    testElement.getLocalName().equals("Test"));
            assertTrue("SOAP 1.1 :- Test element namespace mismatch",
                    testElement.getNamespace().getName().equals(
                            "http:www.Test.org"));

            OMElement childOfTestElement = testElement.getFirstElement();
            assertTrue("SOAP 1.1 :- Test element child local name mismatch",
                    childOfTestElement.getLocalName().equals("TestElement"));
            assertTrue("SOAP 1.1 :- Test element child namespace mismatch",
                    childOfTestElement.getNamespace().getName().equals(
                            "http:www.Test.org"));
            assertTrue("SOAP 1.1 :- Test element child value mismatch",
                    childOfTestElement.getText().trim().equals("This is only a test"));

        } catch (XMLStreamException e) {
            log.info(e.getMessage());
            fail("Test failed. Reason -> " + e.getMessage());
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.axis2.om.OMElement

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.