Search in sources :

Example 51 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project wso2-synapse by wso2.

the class Axis2MessageContext method toString.

public String toString() {
    StringBuffer sb = new StringBuffer();
    String separator = "\n";
    if (getTo() != null) {
        sb.append("To : ").append(getTo().getAddress());
    } else {
        sb.append("To : ");
    }
    if (getFrom() != null) {
        sb.append(separator).append("From : ").append(getFrom().getAddress());
    }
    if (getWSAAction() != null) {
        sb.append(separator).append("WSAction : ").append(getWSAAction());
    }
    if (getSoapAction() != null) {
        sb.append(separator).append("SOAPAction : ").append(getSoapAction());
    }
    if (getReplyTo() != null) {
        sb.append(separator).append("ReplyTo : ").append(getReplyTo().getAddress());
    }
    if (getMessageID() != null) {
        sb.append(separator).append("MessageID : ").append(getMessageID());
    }
    SOAPHeader soapHeader = getEnvelope().getHeader();
    if (soapHeader != null) {
        sb.append(separator).append("Headers : ");
        for (Iterator iter = soapHeader.examineAllHeaderBlocks(); iter.hasNext(); ) {
            Object o = iter.next();
            if (o instanceof SOAPHeaderBlock) {
                SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) o;
                sb.append(separator).append("\t").append(headerBlock.getLocalName()).append(" : ").append(headerBlock.getText());
            } else if (o instanceof OMElement) {
                OMElement headerElem = (OMElement) o;
                sb.append(separator).append("\t").append(headerElem.getLocalName()).append(" : ").append(headerElem.getText());
            }
        }
    }
    SOAPBody soapBody = getEnvelope().getBody();
    if (soapBody != null) {
        sb.append(separator).append("Body : ").append(soapBody.toString());
    }
    return sb.toString();
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 52 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project wso2-synapse by wso2.

the class SynapseDebugManager method getAxis2Properties.

protected JSONObject getAxis2Properties() throws JSONException, IOException {
    JSONObject result = new JSONObject();
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_TO, synCtx.getTo() != null ? synCtx.getTo().getAddress() : "");
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_FROM, synCtx.getFrom() != null ? synCtx.getFrom().getAddress() : "");
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_WSACTION, synCtx.getWSAAction() != null ? synCtx.getWSAAction() : "");
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_SOAPACTION, synCtx.getSoapAction() != null ? synCtx.getSoapAction() : "");
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_REPLY_TO, synCtx.getReplyTo() != null ? synCtx.getReplyTo().getAddress() : "");
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_MESSAGE_ID, synCtx.getMessageID() != null ? synCtx.getMessageID() : "");
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_DIRECTION, synCtx.isResponse() ? "response" : "request");
    Object messageTypeProperty = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty("messageType");
    if (messageTypeProperty != null && ((String) messageTypeProperty).contains("json")) {
        InputStream jsonPayloadStream = JsonUtil.getJsonPayload(((Axis2MessageContext) synCtx).getAxis2MessageContext());
        if (jsonPayloadStream != null) {
            StringWriter writer = new StringWriter();
            String encoding = null;
            IOUtils.copy(jsonPayloadStream, writer, encoding);
            String jsonPayload = writer.toString();
            result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_ENVELOPE, jsonPayload != null ? jsonPayload : synCtx.getEnvelope().toString());
        } else {
            result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_ENVELOPE, synCtx.getEnvelope() != null ? synCtx.getEnvelope().toString() : "");
        }
    } else {
        result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_ENVELOPE, synCtx.getEnvelope() != null ? synCtx.getEnvelope().toString() : "");
    }
    String axis2MessageContextKey = getAxis2MessagePropertiesKey(((Axis2MessageContext) synCtx).getAxis2MessageContext());
    if (addedPropertyValuesMap.containsKey(axis2MessageContextKey)) {
        Map scopePropertyMap = (Map) addedPropertyValuesMap.get(axis2MessageContextKey);
        if (scopePropertyMap.containsKey(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_AXIS2)) {
            Set<String> propertyKeySet = (Set<String>) scopePropertyMap.get(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_AXIS2);
            for (String key : propertyKeySet) {
                result.put(key, ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(key));
            }
        }
    }
    JSONObject soapHeader = new JSONObject();
    if (synCtx.getEnvelope() != null) {
        SOAPHeader header = synCtx.getEnvelope().getHeader();
        if (header != null) {
            for (Iterator iter = header.examineAllHeaderBlocks(); iter.hasNext(); ) {
                Object o = iter.next();
                if (o instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock headerBlk = (SOAPHeaderBlock) o;
                    soapHeader.put(headerBlk.getLocalName(), headerBlk.getText());
                } else if (o instanceof OMElement) {
                    OMElement headerElem = (OMElement) o;
                    soapHeader.put(headerElem.getLocalName(), headerElem.getText());
                }
            }
        }
    }
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_SOAPHEADER, soapHeader);
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_EXCESS_TRANSPORT_HEADERS, ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty("EXCESS_TRANSPORT_HEADERS"));
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_MESSAGE_TYPE, ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty("messageType"));
    result.put(SynapseDebugCommandConstants.AXIS2_PROPERTY_CONTENT_TYPE, ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty("ContentType"));
    return result;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InputStream(java.io.InputStream) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) JSONObject(org.codehaus.jettison.json.JSONObject) StringWriter(java.io.StringWriter) Iterator(java.util.Iterator) JSONObject(org.codehaus.jettison.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) SOAPHeader(org.apache.axiom.soap.SOAPHeader) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 53 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project wso2-synapse by wso2.

the class CommonScriptMessageContext method addHeader.

/**
 * Add a new SOAP header to the message.
 *
 * @param mustUnderstand the value for the <code>soapenv:mustUnderstand</code> attribute
 * @param content the XML for the new header
 * @throws ScriptException if an error occurs when converting the XML to OM
 */
@Override
public void addHeader(boolean mustUnderstand, Object content) throws ScriptException {
    SOAPEnvelope envelope = mc.getEnvelope();
    SOAPFactory factory = (SOAPFactory) envelope.getOMFactory();
    SOAPHeader header = envelope.getHeader();
    if (header == null) {
        header = factory.createSOAPHeader(envelope);
    }
    OMElement element = xmlHelper.toOMElement(content);
    // We can't add the element directly to the SOAPHeader. Instead, we need to copy the
    // information over to a SOAPHeaderBlock.
    SOAPHeaderBlock headerBlock = header.addHeaderBlock(element.getLocalName(), element.getNamespace());
    for (Iterator it = element.getAllAttributes(); it.hasNext(); ) {
        headerBlock.addAttribute((OMAttribute) it.next());
    }
    headerBlock.setMustUnderstand(mustUnderstand);
    OMNode child = element.getFirstOMChild();
    while (child != null) {
        // Get the next child before addChild will detach the node from its original place.
        OMNode next = child.getNextOMSibling();
        headerBlock.addChild(child);
        child = next;
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 54 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project wso2-synapse by wso2.

the class MessageHelper method removeProcessedHeaders.

/**
 * Remove the headers that are marked as processed.
 * @param axisMsgCtx the Axis2 Message context
 * @param preserveAddressing if true preserve the addressing headers
 */
public static void removeProcessedHeaders(org.apache.axis2.context.MessageContext axisMsgCtx, boolean preserveAddressing) {
    SOAPEnvelope env = axisMsgCtx.getEnvelope();
    SOAPHeader soapHeader = env.getHeader();
    if (soapHeader != null) {
        Iterator it = soapHeader.getChildElements();
        while (it.hasNext()) {
            Object o = it.next();
            if (o instanceof SOAPHeaderBlock) {
                SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) o;
                if (!preserveAddressing) {
                    // if we don't need to preserve addressing headers remove without checking
                    if (headerBlock.isProcessed()) {
                        headerBlock.detach();
                    }
                } else {
                    // else remove only if not an addressing header
                    if (!isAddressingHeader(headerBlock)) {
                        if (headerBlock.isProcessed()) {
                            headerBlock.detach();
                        }
                    }
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 55 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project wso2-synapse by wso2.

the class MessageHelper method removeAddressingHeaders.

/**
 * Removes Submission and Final WS-Addressing headers and return the SOAPEnvelope from the given
 * message context
 *
 * @param axisMsgCtx the Axis2 Message context
 * @return the resulting SOAPEnvelope
 */
public static SOAPEnvelope removeAddressingHeaders(org.apache.axis2.context.MessageContext axisMsgCtx) {
    SOAPEnvelope env = axisMsgCtx.getEnvelope();
    SOAPHeader soapHeader = env.getHeader();
    ArrayList addressingHeaders;
    if (soapHeader != null) {
        addressingHeaders = soapHeader.getHeaderBlocksWithNSURI(AddressingConstants.Submission.WSA_NAMESPACE);
        if (addressingHeaders != null && addressingHeaders.size() != 0) {
            detachAddressingInformation(addressingHeaders);
        } else {
            addressingHeaders = soapHeader.getHeaderBlocksWithNSURI(AddressingConstants.Final.WSA_NAMESPACE);
            if (addressingHeaders != null && addressingHeaders.size() != 0) {
                detachAddressingInformation(addressingHeaders);
            }
        }
    }
    return env;
}
Also used : ArrayList(java.util.ArrayList) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Aggregations

SOAPHeader (org.apache.axiom.soap.SOAPHeader)56 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)33 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)32 OMElement (org.apache.axiom.om.OMElement)18 OMNamespace (org.apache.axiom.om.OMNamespace)15 QName (javax.xml.namespace.QName)13 Iterator (java.util.Iterator)10 OMNode (org.apache.axiom.om.OMNode)10 SOAPFactory (org.apache.axiom.soap.SOAPFactory)9 SOAPBody (org.apache.axiom.soap.SOAPBody)8 SOAPFault (org.apache.axiom.soap.SOAPFault)5 OMException (org.apache.axiom.om.OMException)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)4 OMAttribute (org.apache.axiom.om.OMAttribute)3 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)3 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)3 SOAPFaultReason (org.apache.axiom.soap.SOAPFaultReason)3 BooleanAttributeAccessor (org.apache.axiom.ts.soap.BooleanAttributeAccessor)3 Element (org.w3c.dom.Element)3 StringReader (java.io.StringReader)2