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();
}
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;
}
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;
}
}
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();
}
}
}
}
}
}
}
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;
}
Aggregations