/** @param synCtx */ public void evaluate(MessageContext synCtx) { String result; if (value != null) { result = value; } else if (expression != null) { result = expression.stringValueOf(synCtx); } else { throw new SynapseException("A value or expression must be specified"); } if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) { synCtx.setProperty(name, result); } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) { // Setting property into the Axis2 Message Context Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.setProperty(name, result); } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope)) { // Setting property into the Axis2 Message Context client options Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.getOptions().setProperty(name, result); } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) { // 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(name, result); } if (headers == null) { Map headersMap = new HashMap(); headersMap.put(name, result); axis2MessageCtx.setProperty( org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap); } } }
/** * Sets a property into the current (local) Synapse Context or into the Axis Message Context or * into Transports Header and removes above properties from the corresponding locations. * * @param synCtx the message context * @return true always */ public boolean mediate(MessageContext synCtx) { SynapseLog synLog = getLog(synCtx); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Start : Property mediator"); if (synLog.isTraceTraceEnabled()) { synLog.traceTrace("Message : " + synCtx.getEnvelope()); } } if (action == ACTION_SET) { Object resultValue = getResultValue(synCtx); // if the result value is a String we can apply a reguar expression to // choose part of it if (resultValue instanceof String && pattern != null) { resultValue = getMatchedValue((String) resultValue, synLog); } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug( "Setting property : " + name + " at scope : " + (scope == null ? "default" : scope) + " to : " + resultValue + " (i.e. " + (value != null ? "constant : " + value : "result of expression : " + expression) + ")"); } if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) { // Setting property into the Synapse Context synCtx.setProperty(name, resultValue); } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope) && synCtx instanceof Axis2MessageContext) { // Setting property into the Axis2 Message Context Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.setProperty(name, resultValue); } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope) && synCtx instanceof Axis2MessageContext) { // Setting property into the Axis2 Message Context client options Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.getOptions().setProperty(name, resultValue); } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) { // 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(name, resultValue); } if (headers == null) { Map headersMap = new HashMap(); headersMap.put(name, resultValue); axis2MessageCtx.setProperty( org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap); } } else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope) && synCtx instanceof Axis2MessageContext) { // Setting Transport Headers Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2smc.getAxis2MessageContext().getOperationContext().setProperty(name, resultValue); } } else { if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug( "Removing property : " + name + " (scope:" + (scope == null ? "default" : scope) + ")"); } if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) { // Removing property from the Synapse Context Set pros = synCtx.getPropertyKeySet(); if (pros != null) { pros.remove(name); } } else if ((XMLConfigConstants.SCOPE_AXIS2.equals(scope) || XMLConfigConstants.SCOPE_CLIENT.equals(scope)) && synCtx instanceof Axis2MessageContext) { // Removing property from the Axis2 Message Context Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.removeProperty(name); } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) { // 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(name); } else { synLog.traceOrDebug("No transport headers found for the message"); } } } synLog.traceOrDebug("End : Property mediator"); return true; }