Search in sources :

Example 96 with OMNode

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

the class OMTestUtils method walkThrough.

public static void walkThrough(OMElement element) {
    Assert.assertFalse("Expected " + element.getQName() + " to be incomplete", element.isComplete());
    for (Iterator<OMAttribute> it = element.getAllAttributes(); it.hasNext(); ) {
        Assert.assertNotNull(it.next());
    }
    OMNode child = element.getFirstOMChild();
    while (child != null) {
        if (child instanceof OMElement) {
            walkThrough((OMElement) child);
        }
        child = child.getNextOMSibling();
    }
    Assert.assertTrue(element.isComplete());
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 97 with OMNode

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

the class TestCommentInEpilog method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(soapFactory.getDefaultEnvelope() + "<!--comment-->")).getSOAPEnvelope();
    OMNode sibling = envelope.getNextOMSibling();
    assertTrue(sibling instanceof OMComment);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) StringReader(java.io.StringReader) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 98 with OMNode

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

the class TestCommentInProlog method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = SOAPSampleSet.COMMENT_IN_PROLOG.getMessage(spec).getAdapter(SOAPSampleAdapter.class).getSOAPMessage(metaFactory);
    OMNode firstChild = message.getFirstOMChild();
    assertTrue(firstChild instanceof OMComment);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) SOAPSampleAdapter(org.apache.axiom.ts.soap.SOAPSampleAdapter) SOAPMessage(org.apache.axiom.soap.SOAPMessage)

Example 99 with OMNode

use of org.apache.axiom.om.OMNode in project carbon-business-process by wso2.

the class SOAPUtils method convertSOAP11toSOAP12.

/**
 * Converts the version of the the message context to 1.2.
 * <br />
 * <b>Message Changes:</b>
 * <ol>
 *     <li>Convert envelope, header elements</li>
 *     <li>For each header block convert attribute actor to role</li>
 *     <li>For each header block convert mustUnderstand value type</li>
 *     <li>For each header block remove 1.1 namespaced other attributes</li>
 * </ol>
 *
 * <b>Fault Changes:</b>
 * <ol>
 *     <li>Convert fault element</li>
 *     <li>faultcode to Fault/Code</li>
 *     <li>faultstring to First Fault/Reason/Text with lang=en</li>
 * </ol>
 *
 * @param axisOutMsgCtx message context to be converted
 * @throws AxisFault incase conversion process fails
 */
public static void convertSOAP11toSOAP12(org.apache.axis2.context.MessageContext axisOutMsgCtx) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("convert SOAP11 to SOAP12");
    }
    SOAPEnvelope oldEnvelope = axisOutMsgCtx.getEnvelope();
    SOAPFactory soap12Factory = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope newEnvelope = soap12Factory.getDefaultEnvelope();
    if (oldEnvelope.getHeader() != null) {
        Iterator itr = oldEnvelope.getHeader().getChildren();
        while (itr.hasNext()) {
            OMNode omNode = (OMNode) itr.next();
            if (omNode instanceof SOAPHeaderBlock) {
                SOAPHeaderBlock soapHeader = (SOAPHeaderBlock) omNode;
                SOAPHeaderBlock newSOAPHeader = soap12Factory.createSOAPHeaderBlock(soapHeader.getLocalName(), soapHeader.getNamespace());
                Iterator allAttributes = soapHeader.getAllAttributes();
                while (allAttributes.hasNext()) {
                    OMAttribute attr = (OMAttribute) allAttributes.next();
                    if (attr.getNamespace() != null && SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(attr.getNamespace().getNamespaceURI())) {
                        String attrName = attr.getLocalName();
                        if (SOAP_ATR_ACTOR.equals(attrName)) {
                            OMAttribute newAtr = omNode.getOMFactory().createOMAttribute(SOAP_ATR_ROLE, newEnvelope.getNamespace(), attr.getAttributeValue());
                            newSOAPHeader.addAttribute(newAtr);
                        } else if (SOAP_ATR_MUST_UNDERSTAND.equals(attrName)) {
                            boolean isMustUnderstand = soapHeader.getMustUnderstand();
                            newSOAPHeader.setMustUnderstand(isMustUnderstand);
                        } else {
                            log.warn("removed unsupported attribute from SOAP 1.1 " + "namespace when converting to SOAP 1.2:" + attrName);
                        }
                    } else {
                        newSOAPHeader.addAttribute(attr);
                    }
                    Iterator itrChildren = soapHeader.getChildren();
                    while (itrChildren.hasNext()) {
                        OMNode node = (OMNode) itrChildren.next();
                        itrChildren.remove();
                        newSOAPHeader.addChild(node);
                    }
                    newEnvelope.getHeader().addChild(newSOAPHeader);
                }
            // while(allAttributes.hasNext())
            } else {
                itr.remove();
                newEnvelope.getHeader().addChild(omNode);
            }
        }
    // while (itr.hasNext())
    }
    if (oldEnvelope.getBody() != null) {
        Iterator itrBodyChildren = oldEnvelope.getBody().getChildren();
        while (itrBodyChildren.hasNext()) {
            OMNode omNode = (OMNode) itrBodyChildren.next();
            if (omNode != null && omNode instanceof SOAPFault) {
                SOAPFault soapFault = (SOAPFault) omNode;
                SOAPFault newSOAPFault = soap12Factory.createSOAPFault();
                newEnvelope.getBody().addChild(newSOAPFault);
                // get the existing envelope
                SOAPFaultCode code = soapFault.getCode();
                if (code != null) {
                    SOAPFaultCode newSOAPFaultCode = soap12Factory.createSOAPFaultCode();
                    newSOAPFault.setCode(newSOAPFaultCode);
                    QName s11Code = code.getTextAsQName();
                    if (s11Code != null) {
                        // get the corresponding SOAP12 fault code
                        // for the provided SOAP11 fault code
                        SOAPFaultValue newSOAPFaultValue = soap12Factory.createSOAPFaultValue(newSOAPFaultCode);
                        newSOAPFaultValue.setText(getMappingSOAP12Code(s11Code));
                    }
                }
                SOAPFaultReason reason = soapFault.getReason();
                if (reason != null) {
                    SOAPFaultReason newSOAPFaultReason = soap12Factory.createSOAPFaultReason(newSOAPFault);
                    String reasonText = reason.getText();
                    if (reasonText != null) {
                        SOAPFaultText newSOAPFaultText = soap12Factory.createSOAPFaultText(newSOAPFaultReason);
                        // hard coded
                        newSOAPFaultText.setLang("en");
                        newSOAPFaultText.setText(reasonText);
                    }
                    newSOAPFault.setReason(newSOAPFaultReason);
                }
                SOAPFaultDetail detail = soapFault.getDetail();
                if (detail != null) {
                    SOAPFaultDetail newSOAPFaultDetail = soap12Factory.createSOAPFaultDetail(newSOAPFault);
                    Iterator<OMElement> iter = detail.getAllDetailEntries();
                    while (iter.hasNext()) {
                        OMElement detailEntry = iter.next();
                        iter.remove();
                        newSOAPFaultDetail.addDetailEntry(detailEntry);
                    }
                    newSOAPFault.setDetail(newSOAPFaultDetail);
                }
            } else {
                itrBodyChildren.remove();
                newEnvelope.getBody().addChild(omNode);
            }
        // if (omNode instanceof SOAPFault)
        }
    // while (itrBodyChildren.hasNext())
    }
    // if (clonedOldEnv.getBody() != null)
    axisOutMsgCtx.setEnvelope(newEnvelope);
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMNode(org.apache.axiom.om.OMNode) Iterator(java.util.Iterator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 100 with OMNode

use of org.apache.axiom.om.OMNode in project carbon-business-process by wso2.

the class SOAPUtils method parseResponseFromRESTService.

public static org.apache.ode.bpel.iapi.Message parseResponseFromRESTService(BPELMessageContext partnerInvocationContext, PartnerRoleMessageExchange odePartnerMex) {
    org.apache.ode.bpel.iapi.Message messageToODE = odePartnerMex.createMessage(odePartnerMex.getOperation().getOutput().getMessage().getQName());
    BindingOperation bindingOp = getBindingOperation(partnerInvocationContext, odePartnerMex.getOperationName());
    BindingOutput bindingOutPut = getBindingOutPut(bindingOp);
    javax.wsdl.extensions.mime.MIMEContent mimeContent = getFirstExtensibilityElement(bindingOutPut, MIMEContent.class);
    if (mimeContent != null) {
        SOAPEnvelope soapEnv = partnerInvocationContext.getOutMessageContext().getEnvelope();
        Iterator childElementsItr = soapEnv.getBody().getChildElements();
        while (childElementsItr.hasNext()) {
            OMNode child = (OMNode) childElementsItr.next();
            if (child.getType() == OMNode.ELEMENT_NODE) {
                Document doc = DOMUtils.newDocument();
                Element domPart = doc.createElementNS(null, mimeContent.getPart());
                domPart.appendChild(doc.importNode(OMUtils.toDOM((OMElement) child), true));
                messageToODE.setPart(mimeContent.getPart(), domPart);
                return messageToODE;
            }
        }
    }
    throw new IllegalArgumentException("WSO2 BPS only support HTTP binding with mime output.");
}
Also used : BindingOutput(javax.wsdl.BindingOutput) MIMEContent(javax.wsdl.extensions.mime.MIMEContent) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Document(org.w3c.dom.Document) SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) OMNode(org.apache.axiom.om.OMNode) Node(org.w3c.dom.Node) OMNode(org.apache.axiom.om.OMNode) BindingOperation(javax.wsdl.BindingOperation) Iterator(java.util.Iterator)

Aggregations

OMNode (org.apache.axiom.om.OMNode)150 OMElement (org.apache.axiom.om.OMElement)87 Iterator (java.util.Iterator)28 OMText (org.apache.axiom.om.OMText)23 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 BXMLItem (org.ballerinalang.model.values.BXMLItem)18 StringReader (java.io.StringReader)17 SynapseException (org.apache.synapse.SynapseException)15 OMAttribute (org.apache.axiom.om.OMAttribute)14 OMFactory (org.apache.axiom.om.OMFactory)14 BValue (org.ballerinalang.model.values.BValue)14 BXML (org.ballerinalang.model.values.BXML)14 Test (org.testng.annotations.Test)14 QName (javax.xml.namespace.QName)13 BJSON (org.ballerinalang.model.values.BJSON)13 OMDocument (org.apache.axiom.om.OMDocument)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 SOAPHeader (org.apache.axiom.soap.SOAPHeader)10 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)10