use of org.apache.axis2.addressing.RelatesTo in project wso2-synapse by wso2.
the class HeaderMediator method mediate.
/**
* Sets/Removes a SOAP header on the current message
*
* @param synCtx the current message which is altered as necessary
* @return true always
*/
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : Header mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
String value = (getExpression() == null ? getValue() : expression.stringValueOf(synCtx));
if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
if (action == ACTION_SET) {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Set SOAP header : " + qName + " to : " + value);
}
if (!isImplicit() && (qName.getNamespaceURI() == null || "".equals(qName.getNamespaceURI()))) {
// is this a "well known" Synapse header?
if (SynapseConstants.HEADER_TO.equals(qName.getLocalPart())) {
synCtx.setTo(new EndpointReference(value));
} else if (SynapseConstants.HEADER_FROM.equals(qName.getLocalPart())) {
synCtx.setFrom(new EndpointReference(value));
} else if (SynapseConstants.HEADER_ACTION.equals(qName.getLocalPart())) {
synCtx.setWSAAction(value);
} else if (SynapseConstants.HEADER_FAULT.equals(qName.getLocalPart())) {
synCtx.setFaultTo(new EndpointReference(value));
} else if (SynapseConstants.HEADER_REPLY_TO.equals(qName.getLocalPart())) {
synCtx.setReplyTo(new EndpointReference(value));
} else if (SynapseConstants.HEADER_RELATES_TO.equals(qName.getLocalPart())) {
synCtx.setRelatesTo(new RelatesTo[] { new RelatesTo(value) });
} else {
addCustomHeader(synCtx, value);
}
} else {
addCustomHeader(synCtx, value);
}
} else {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Removing SOAP Header : " + qName);
}
if (qName.getNamespaceURI() == null || "".equals(qName.getNamespaceURI())) {
// is this a "well known" Synapse header?
if (SynapseConstants.HEADER_TO.equals(qName.getLocalPart())) {
synCtx.setTo(null);
} else if (SynapseConstants.HEADER_FROM.equals(qName.getLocalPart())) {
synCtx.setFrom(null);
} else if (SynapseConstants.HEADER_ACTION.equals(qName.getLocalPart())) {
synCtx.setWSAAction(null);
} else if (SynapseConstants.HEADER_FAULT.equals(qName.getLocalPart())) {
synCtx.setFaultTo(null);
} else if (SynapseConstants.HEADER_REPLY_TO.equals(qName.getLocalPart())) {
synCtx.setReplyTo(null);
} else if (SynapseConstants.HEADER_RELATES_TO.equals(qName.getLocalPart())) {
synCtx.setRelatesTo(null);
} else {
SOAPEnvelope envelope = synCtx.getEnvelope();
if (envelope != null) {
SOAPHeader header = envelope.getHeader();
if (header != null) {
removeFromHeaderList(header.getHeaderBlocksWithNSURI(""));
}
}
}
} else {
SOAPEnvelope envelope = synCtx.getEnvelope();
if (envelope != null) {
SOAPHeader header = envelope.getHeader();
if (header != null) {
removeFromHeaderList(header.getHeaderBlocksWithNSURI(qName.getNamespaceURI()));
}
}
}
}
} else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) {
String headerName = qName.getLocalPart();
if (action == ACTION_SET) {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Set HTTP header : " + headerName + " to : " + value);
}
// Setting Transport Headers
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
headersMap.put(headerName, value);
}
if (headers == null) {
Map headersMap = new HashMap();
headersMap.put(headerName, value);
axis2MessageCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
}
} else {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Removing HTTP Header : " + qName);
}
// Removing transport headers
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
headersMap.remove(headerName);
} else {
synLog.traceOrDebug("No transport headers found for the message");
}
}
}
// NOTE: We dont' use an else here because the HTTPMediatorFactory should capture cases where scope is not default or transport.
synLog.traceOrDebug("End : Header mediator");
return true;
}
use of org.apache.axis2.addressing.RelatesTo in project wso2-synapse by wso2.
the class SynapseCallbackReceiver method receive.
/**
* Everytime a response message is received this method gets invoked. It will then select
* the outgoing *Synapse* message context for the reply we received, and determine what action
* to take at the Synapse level
*
* @param messageCtx the Axis2 message context of the reply received
* @throws AxisFault
*/
public void receive(MessageContext messageCtx) throws AxisFault {
String messageID = null;
/**
* In an Out-only scenario if the client receives a HTTP 202 accepted we need to
* remove the call back/s registered for that request.
* This if will check weather this is a message sent in a that scenario and remove the callback
*/
if (messageCtx.getProperty(NhttpConstants.HTTP_202_RECEIVED) != null && "true".equals(messageCtx.getProperty(NhttpConstants.HTTP_202_RECEIVED))) {
if (callbackStore.containsKey(messageCtx.getMessageID())) {
AsyncCallback callback = (AsyncCallback) callbackStore.remove(messageCtx.getMessageID());
if (RuntimeStatisticCollector.isStatisticsEnabled()) {
CallbackStatisticCollector.callbackCompletionEvent(callback.getSynapseOutMsgCtx(), messageCtx.getMessageID());
}
if (log.isDebugEnabled()) {
log.debug("CallBack registered with Message id : " + messageCtx.getMessageID() + " removed from the " + "callback store since we got an accepted Notification");
}
}
return;
}
if (messageCtx.getOptions() != null && messageCtx.getOptions().getRelatesTo() != null) {
// never take a chance with a NPE at this stage.. so check at each level :-)
Options options = messageCtx.getOptions();
if (options != null) {
RelatesTo relatesTo = options.getRelatesTo();
if (relatesTo != null) {
messageID = relatesTo.getValue();
}
}
} else if (messageCtx.getProperty(SynapseConstants.SANDESHA2_SEQUENCE_KEY) == null) {
messageID = (String) messageCtx.getProperty(SynapseConstants.RELATES_TO_FOR_POX);
}
if (messageID != null) {
AsyncCallback callback = (AsyncCallback) callbackStore.remove(messageID);
if (log.isDebugEnabled()) {
log.debug("Callback removed for request message id : " + messageID + ". Pending callbacks count : " + callbackStore.size());
}
RelatesTo[] relates = messageCtx.getRelationships();
if (relates != null && relates.length > 1) {
// we set a relates to to the response message so that if WSA is not used, we
// could still link back to the original message. But if WSA was used, this
// gets duplicated, and we should remove it
removeDuplicateRelatesTo(messageCtx, relates);
}
if (callback != null) {
org.apache.synapse.MessageContext SynapseOutMsgCtx = callback.getSynapseOutMsgCtx();
ConcurrencyThrottlingUtils.decrementConcurrencyThrottleAccessController(SynapseOutMsgCtx);
synchronized (callback) {
if (callback.isMarkedForRemoval()) {
return;
}
callback.setMarkedForRemoval();
}
if (RuntimeStatisticCollector.isStatisticsEnabled()) {
CallbackStatisticCollector.updateParentsForCallback(SynapseOutMsgCtx, messageID);
handleMessage(messageID, messageCtx, SynapseOutMsgCtx, (AsyncCallback) callback);
if (log.isDebugEnabled()) {
log.debug("Finished handling the callback.");
}
CallbackStatisticCollector.reportCallbackHandlingCompletion(SynapseOutMsgCtx, messageID);
} else {
handleMessage(messageID, messageCtx, SynapseOutMsgCtx, (AsyncCallback) callback);
}
} else {
// TODO invoke a generic synapse error handler for this message
log.warn("Synapse received a response for the request with message Id : " + messageID + " But a callback is not registered (anymore) to process this response");
}
} else if (!messageCtx.isPropertyTrue(NhttpConstants.SC_ACCEPTED)) {
// TODO invoke a generic synapse error handler for this message
log.warn("Synapse received a response message without a message Id");
}
}
Aggregations