Search in sources :

Example 16 with OMXMLParserWrapper

use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.

the class TestBuilder method runTest.

@Override
protected void runTest() throws Throwable {
    String soap12Message = "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">\n" + "   <env:Header>\n" + "       <test:echoOk xmlns:test=\"http://example.org/ts-tests\"\n" + "                    env:role=\"http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver\"\n" + "                    env:mustUnderstand=\"true\">\n" + "                       foo\n" + "       </test:echoOk>\n" + "   </env:Header>\n" + "   <env:Body>\n" + "       <env:Fault>\n" + "           <env:Code>\n" + "               <env:Value>env:Sender</env:Value>\n" + "               <env:Subcode>\n" + "                   <env:Value>m:MessageTimeout</env:Value>\n" + "                   <env:Subcode>\n" + "                       <env:Value>m:MessageTimeout</env:Value>\n" + "                   </env:Subcode>\n" + "               </env:Subcode>\n" + "           </env:Code>\n" + "           <env:Reason>\n" + "               <env:Text>Sender Timeout</env:Text>\n" + "           </env:Reason>\n" + "           <env:Node>\n" + "               http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver\n" + "           </env:Node>\n" + "           <env:Role>\n" + "               ultimateReceiver\n" + "           </env:Role>\n" + "           <env:Detail xmlns:m=\"http:www.sample.org\">\n" + "               Details of error\n" + "               <m:MaxTime m:detail=\"This is only a test\">\n" + "                   P5M\n" + "               </m:MaxTime>\n" + "               <m:AveTime>\n" + "                   <m:Time>\n" + "                       P3M\n" + "                   </m:Time>\n" + "               </m:AveTime>\n" + "           </env:Detail>\n" + "       </env:Fault>\n" + "   </env:Body>\n" + "</env:Envelope>";
    OMXMLParserWrapper soap12Builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(soap12Message));
    SOAPEnvelope soap12Envelope = (SOAPEnvelope) soap12Builder.getDocumentElement();
    assertTrue("SOAP 1.2 :- envelope local name mismatch", soap12Envelope.getLocalName().equals(SOAPConstants.SOAPENVELOPE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- envelope namespace uri mismatch", soap12Envelope.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    SOAPHeader header = soap12Envelope.getHeader();
    assertTrue("SOAP 1.2 :- Header local name mismatch", header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Header namespace uri mismatch", header.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) header.getFirstElement();
    assertTrue("SOAP 1.2 :- Header block name mismatch", headerBlock.getLocalName().equals("echoOk"));
    assertTrue("SOAP 1.2 :- Header block name space uri mismatch", headerBlock.getNamespace().getNamespaceURI().equals("http://example.org/ts-tests"));
    assertEquals("SOAP 1.2 :- Header block text mismatch", headerBlock.getText().trim(), "foo");
    // Attribute iteration is not in any guaranteed order.
    // Use QNames to get the OMAttributes.
    QName roleQName = new QName(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI, SOAP12Constants.SOAP_ROLE);
    QName mustUnderstandQName = new QName(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI, SOAP12Constants.ATTR_MUSTUNDERSTAND);
    OMAttribute roleAttribute = headerBlock.getAttribute(roleQName);
    OMAttribute mustUnderstandAttribute = headerBlock.getAttribute(mustUnderstandQName);
    assertTrue("SOAP 1.2 :- Role attribute name not found", roleAttribute != null);
    assertTrue("SOAP 1.2 :- Role value mismatch", roleAttribute.getAttributeValue().trim().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI + "/" + SOAP12Constants.SOAP_ROLE + "/" + "ultimateReceiver"));
    assertTrue("SOAP 1.2 :- Mustunderstand attribute not found", mustUnderstandAttribute != null);
    assertTrue("SOAP 1.2 :- Mustunderstand value mismatch", mustUnderstandAttribute.getAttributeValue().equals(SOAPConstants.ATTR_MUSTUNDERSTAND_TRUE));
    SOAPBody body = soap12Envelope.getBody();
    assertTrue("SOAP 1.2 :- Body local name mismatch", body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Body namespace uri mismatch", body.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    SOAPFault fault = body.getFault();
    assertTrue("SOAP 1.2 :- Fault local name mismatch", fault.getLocalName().equals(SOAPConstants.SOAPFAULT_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault namespace uri mismatch", fault.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    Iterator<OMNode> iteratorInFault = fault.getChildren();
    iteratorInFault.next();
    SOAPFaultCode code = (SOAPFaultCode) iteratorInFault.next();
    assertTrue("SOAP 1.2 :- Fault code local name mismatch", code.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", code.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    Iterator<OMNode> iteratorInCode = code.getChildren();
    iteratorInCode.next();
    SOAPFaultValue value1 = (SOAPFaultValue) iteratorInCode.next();
    assertTrue("SOAP 1.2 :- Fault code value local name mismatch", value1.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", value1.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.2 :- Value1 text mismatch", value1.getText().equals("env:Sender"));
    QName valueQName = value1.getTextAsQName();
    assertTrue("SOAP 1.2 :- Fault code value's qname local name mismatch", valueQName.getLocalPart().equals("Sender"));
    assertTrue("SOAP 1.2 :- Fault code value's qname namespace uri mismatch", valueQName.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    iteratorInCode.next();
    SOAPFaultSubCode subCode1 = (SOAPFaultSubCode) iteratorInCode.next();
    assertTrue("SOAP 1.2 :- Fault sub code local name mismatch", subCode1.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault subcode namespace uri mismatch", subCode1.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    Iterator<OMNode> iteratorInSubCode1 = subCode1.getChildren();
    iteratorInSubCode1.next();
    SOAPFaultValue value2 = (SOAPFaultValue) iteratorInSubCode1.next();
    assertTrue("SOAP 1.2 :- Fault code value local name mismatch", value2.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", value2.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.2 :- Value2 text mismatch", value2.getText().equals("m:MessageTimeout"));
    iteratorInSubCode1.next();
    SOAPFaultSubCode subCode2 = (SOAPFaultSubCode) iteratorInSubCode1.next();
    assertTrue("SOAP 1.2 :- Fault sub code local name mismatch", subCode2.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault subcode namespace uri mismatch", subCode2.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    Iterator<OMNode> iteratorInSubCode2 = subCode2.getChildren();
    iteratorInSubCode2.next();
    SOAPFaultValue value3 = (SOAPFaultValue) iteratorInSubCode2.next();
    assertTrue("SOAP 1.2 :- Fault code value local name mismatch", value3.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", value3.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.2 :- Value2 text mismatch", value3.getText().equals("m:MessageTimeout"));
    iteratorInFault.next();
    SOAPFaultReason reason = (SOAPFaultReason) iteratorInFault.next();
    assertTrue("SOAP 1.2 :- Fault reason local name mismatch", reason.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault reason namespace uri mismatch", reason.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    Iterator<OMNode> iteratorInReason = reason.getChildren();
    iteratorInReason.next();
    SOAPFaultText text = (SOAPFaultText) iteratorInReason.next();
    assertTrue("SOAP 1.2 :- Fault text local name mismatch", text.getLocalName().equals(SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Text namespace uri mismatch", text.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.2 :- Text value mismatch", text.getText().equals("Sender Timeout"));
    iteratorInFault.next();
    SOAPFaultNode node = (SOAPFaultNode) iteratorInFault.next();
    assertTrue("SOAP 1.2 :- Fault node local name mismatch", node.getLocalName().equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault node namespace uri mismatch", node.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.2 :- Node value mismatch", node.getText().trim().equals("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));
    iteratorInFault.next();
    SOAPFaultRole role = (SOAPFaultRole) iteratorInFault.next();
    assertTrue("SOAP 1.2 :- Fault role local name mismatch", role.getLocalName().equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault role namespace uri mismatch", role.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.2 :- Role value mismatch", role.getText().trim().equals("ultimateReceiver"));
    iteratorInFault.next();
    SOAPFaultDetail detail = (SOAPFaultDetail) iteratorInFault.next();
    assertTrue("SOAP 1.2 :- Fault detail local name mismatch", detail.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
    assertTrue("SOAP 1.2 :- Fault detail namespace uri mismatch", detail.getNamespace().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
    assertTrue("SOAP 1.2 :- Text in detail mismatch", detail.getText().trim().equals("Details of error"));
    Iterator<OMNode> 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().getNamespaceURI().equals("http:www.sample.org"));
    assertTrue("SOAP 1.2 :- Text value in MaxTime element mismatch", element1.getText().trim().equals("P5M"));
    Iterator<OMAttribute> attributeIterator = element1.getAllAttributes();
    OMAttribute attributeInMaxTime = attributeIterator.next();
    assertTrue("SOAP 1.2 :- Attribute local name mismatch", attributeInMaxTime.getLocalName().equals("detail"));
    assertTrue("SOAP 1.2 :- Attribute namespace mismatch", attributeInMaxTime.getNamespace().getNamespaceURI().equals("http:www.sample.org"));
    assertTrue("SOAP 1.2 :- Attribute value mismatch", attributeInMaxTime.getAttributeValue().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().getNamespaceURI().equals("http:www.sample.org"));
    Iterator<OMNode> 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().getNamespaceURI().equals("http:www.sample.org"));
    assertTrue("SOAP 1.2 :- Text value in Time element mismatch", element21.getText().trim().equals("P3M"));
    soap12Builder.close();
}
Also used : SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) SOAPFaultRole(org.apache.axiom.soap.SOAPFaultRole) QName(javax.xml.namespace.QName) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultValue(org.apache.axiom.soap.SOAPFaultValue) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFaultText(org.apache.axiom.soap.SOAPFaultText) OMNode(org.apache.axiom.om.OMNode) SOAPFaultSubCode(org.apache.axiom.soap.SOAPFaultSubCode) SOAPBody(org.apache.axiom.soap.SOAPBody) StringReader(java.io.StringReader) SOAPFault(org.apache.axiom.soap.SOAPFault) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMAttribute(org.apache.axiom.om.OMAttribute) SOAPHeader(org.apache.axiom.soap.SOAPHeader) SOAPFaultNode(org.apache.axiom.soap.SOAPFaultNode)

Example 17 with OMXMLParserWrapper

use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.

the class TestChildReDeclaringParentsDefaultNSWithPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory fac = metaFactory.getOMFactory();
    OMElement elem = fac.createOMElement("RequestSecurityToken", fac.createOMNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust", ""));
    fac.createOMElement(new QName("TokenType"), elem).setText("test");
    fac.createOMElement(new QName("RequestType"), elem).setText("test1");
    fac.createOMElement(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Entropy", "wst"), elem);
    String xml = elem.toString();
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new ByteArrayInputStream(xml.getBytes()));
    builder.getDocumentElement().build();
    // The StAX implementation may or may not have a trailing blank in the tag
    String assertText1 = "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" />";
    String assertText2 = "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"/>";
    String assertText3 = "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"></wst:Entropy>";
    assertTrue((xml.indexOf(assertText1) != -1) || (xml.indexOf(assertText2) != -1) || (xml.indexOf(assertText3) != -1));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 18 with OMXMLParserWrapper

use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.

the class TestGetChildElementsConsumed method runTest.

@Override
protected void runTest() throws Throwable {
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), TestGetChildElementsConsumed.class.getResourceAsStream("purchase-order.xml"));
    OMElement documentElement = builder.getDocumentElement();
    XMLStreamReader reader = documentElement.getXMLStreamReaderWithoutCaching();
    //building the tree
    while (reader.hasNext()) {
        reader.next();
    }
    //error since the underlying stream is fully consumed without building the object tree
    try {
        Iterator<OMElement> childElements = documentElement.getChildElements();
        while (childElements.hasNext()) {
            childElements.next();
        }
        fail("Expected NodeUnavailableException");
    } catch (NodeUnavailableException ex) {
    // Expected
    }
    documentElement.close(false);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) NodeUnavailableException(org.apache.axiom.om.NodeUnavailableException) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 19 with OMXMLParserWrapper

use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.

the class ConvertLLOMToDOOMTest method testConvert.

public void testConvert() throws Exception {
    String origXML = "<?xml version='1.0' encoding='UTF-8'?>\n" + "   <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">\n" + "      <soapenv:Header>\n" + "         <wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" soapenv:mustUnderstand=\"1\">\n" + "            <ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" Id=\"Signature-6426875\">\n" + "               <ds:SignedInfo>\n" + "                  <ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" />\n" + "                  <ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" />\n" + "                  <ds:Reference URI=\"#id-3083604\">\n" + "                     <ds:Transforms>\n" + "                        <ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" />\n" + "                     </ds:Transforms>\n" + "                     <ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" />\n" + "                     <ds:DigestValue>lDeZJk0/r6u4tOOhOKbN0IEvwi0=</ds:DigestValue>\n" + "                  </ds:Reference>\n" + "               </ds:SignedInfo>\n" + "               <ds:SignatureValue>KhUeWMoUxUFe5jeTlqLdIEIG2Z7Q2q2mh9HT3IAYwbCev+FzXcuLSiPSsb7/+PSDM2SD0gl9tMp+dHjfPxmq7WiduH9mbnP6gkrxxu0T5rR916WsboshJGJKiPlj71bwpMsrrZohx4evHPdQ2SZHthlNb6jZyjq+LS7qFydppHk=</ds:SignatureValue>\n" + "               <ds:KeyInfo Id=\"KeyId-2529687\">\n" + "                  <wsse:SecurityTokenReference xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"STRId-31966667\">\n" + "                     <ds:X509Data>\n" + "                        <ds:X509IssuerSerial>\n" + "                           <ds:X509IssuerName>CN=OASIS Interop Test CA,O=OASIS</ds:X509IssuerName>\n" + "                           <ds:X509SerialNumber>68652640310044618358965661752471103641</ds:X509SerialNumber>\n" + "                        </ds:X509IssuerSerial>\n" + "                     </ds:X509Data>\n" + "                  </wsse:SecurityTokenReference>\n" + "               </ds:KeyInfo>\n" + "            </ds:Signature>\n" + "            <wsu:Timestamp xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"Timestamp-13986615\">\n" + "               <wsu:Created>2006-03-31T15:34:38.699Z</wsu:Created>\n" + "               <wsu:Expires>2006-03-31T15:39:38.699Z</wsu:Expires>\n" + "            </wsu:Timestamp>\n" + "         </wsse:Security>\n" + "         <wsa:To xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">http://localhost:9080/axis2/services/Service</wsa:To>\n" + "         <wsa:ReplyTo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">\n" + "            <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>\n" + "         </wsa:ReplyTo>\n" + "         <wsa:MessageID xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">urn:uuid:049875A6E153FCAAF011438192785862</wsa:MessageID>\n" + "         <wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT</wsa:Action>\n" + "      </soapenv:Header>\n" + "      <soapenv:Body xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"id-3083604\">\n" + "         <RequestSecurityToken xmlns=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" Context=\"http://get.optional.attrs.working\">\n" + "            <TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</TokenType>\n" + "            <RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</RequestType>\n" + "         </RequestSecurityToken>\n" + "      </soapenv:Body>\n" + "   </soapenv:Envelope>";
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(new ByteArrayInputStream(origXML.getBytes()), null);
    SOAPEnvelope env = builder.getSOAPEnvelope();
    env.build();
    SOAPModelBuilder doomBuilder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM), env.getXMLStreamReader());
    SOAPEnvelope doomEnv = doomBuilder.getSOAPEnvelope();
    doomEnv.build();
    OMElement payload = doomEnv.getBody().getFirstElement();
    OMXMLParserWrapper llomBuilder = OMXMLBuilderFactory.createStAXOMBuilder(payload.getXMLStreamReaderWithoutCaching());
    OMElement llomPayload = llomBuilder.getDocumentElement();
    llomPayload.build();
    String xml = llomPayload.toString();
    assertTrue("Conversion failed", xml.indexOf("</RequestSecurityToken>") != -1);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 20 with OMXMLParserWrapper

use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.

the class TestStandaloneConfiguration method runTest.

@Override
protected void runTest() throws Throwable {
    InputStream is = TestStandaloneConfiguration.class.getResourceAsStream("web_w_dtd2.xml");
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.STANDALONE, is);
    OMElement root = builder.getDocumentElement();
    assertTrue(root.getLocalName().equals("web-app"));
    OMDocument document = builder.getDocument();
    Iterator<OMNode> i = document.getChildren();
    OMDocType docType = null;
    while (docType == null && i.hasNext()) {
        OMNode obj = i.next();
        if (obj instanceof OMDocType) {
            docType = (OMDocType) obj;
        }
    }
    assertTrue(docType != null);
    root.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMDocType(org.apache.axiom.om.OMDocType) InputStream(java.io.InputStream) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)37 OMElement (org.apache.axiom.om.OMElement)21 StringReader (java.io.StringReader)12 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMFactory (org.apache.axiom.om.OMFactory)8 InputSource (org.xml.sax.InputSource)8 OMNode (org.apache.axiom.om.OMNode)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 QName (javax.xml.namespace.QName)3 OMAttribute (org.apache.axiom.om.OMAttribute)3 OMDocument (org.apache.axiom.om.OMDocument)3 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 DOMSource (javax.xml.transform.dom.DOMSource)2 SAXSource (javax.xml.transform.sax.SAXSource)2 NodeUnavailableException (org.apache.axiom.om.NodeUnavailableException)2 OMException (org.apache.axiom.om.OMException)2 OMNamespace (org.apache.axiom.om.OMNamespace)2