Search in sources :

Example 1 with SynapseLog

use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.

the class EnqueueMediator method mediate.

public boolean mediate(MessageContext synCtx) {
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    SynapseLog log = getLog(synCtx);
    if (log.isTraceOrDebugEnabled()) {
        log.traceOrDebug("Start: enqueue mediator");
    }
    assert executorName != null : "executor name shouldn't be null";
    PriorityExecutor executor = synCtx.getConfiguration().getPriorityExecutors().get(executorName);
    if (executor == null) {
        log.auditWarn("Cannot find executor " + executorName + ". Using existing thread for mediation");
        Mediator m = synCtx.getSequence(sequenceName);
        if (m != null && m instanceof SequenceMediator) {
            return m.mediate(synCtx);
        } else {
            handleException("Sequence cannot be found : " + sequenceName, synCtx);
            return false;
        }
    }
    Mediator m = synCtx.getSequence(sequenceName);
    if (m != null && m instanceof SequenceMediator) {
        MediatorWorker worker = new MediatorWorker(m, synCtx);
        try {
            // execute with the given priority
            executor.execute(worker, priority);
        } catch (RejectedExecutionException ex) {
            // if RejectedExecutionException, jump to fault handler
            handleException("Unable to process message in priority executor " + executorName + " with priority " + priority + ". Thread pool exhausted.", synCtx);
        }
        // with the nio transport, this causes the listener not to write a 202
        // Accepted response, as this implies that Synapse does not yet know if
        // a 202 or 200 response would be written back.
        ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
        if (log.isTraceOrDebugEnabled()) {
            log.traceOrDebug("End: enqueue mediator");
        }
        return true;
    } else {
        handleException("Sequence cannot be found : " + sequenceName, synCtx);
        return false;
    }
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) MediatorWorker(org.apache.synapse.mediators.MediatorWorker) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 2 with SynapseLog

use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.

the class PropertyMediator method mediate.

/**
 * 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) {
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    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);
        // 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
            if (resultValue != null && resultValue instanceof OMElement) {
                ((OMElement) resultValue).build();
            }
            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);
            MediatorPropertyUtils.handleSpecialProperties(name, resultValue, axis2MessageCtx);
        } 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 null is passed as header value at AbstractHTTPSender in Axis2 when header
                 * value is read causes a null-pointer issue
                 */
            if (resultValue == null) {
                resultValue = "";
            }
            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 (XMLConfigConstants.SCOPE_REGISTRY.equals(scope) && synCtx instanceof Axis2MessageContext) {
            String[] args = name.split("@");
            String path = "";
            String propertyName = "";
            // with the property mentioned and the value as its value
            if (args.length == 1) {
                path = args[0];
            } else if (args.length == 2) {
                path = args[0];
                propertyName = args[1];
            }
            Registry registry = synCtx.getConfiguration().getRegistry();
            registry.newNonEmptyResource(path, false, CONTENT_TYPE, resultValue.toString(), propertyName);
        }
    } 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) && 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_CLIENT.equals(scope) && synCtx instanceof Axis2MessageContext) {
            // Removing property from the Axis2-client Message Context
            Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
            org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
            // Property value is set to null since axis2MessageCtx.getOptions()
            // does not have an option to remove properties
            axis2MessageCtx.getOptions().setProperty(name, null);
        } 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");
            }
        } else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope) && synCtx instanceof Axis2MessageContext) {
            // Removing operation scope headers
            Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
            org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
            OperationContext axis2oc = axis2MessageCtx.getOperationContext();
            axis2oc.removeProperty(name);
        }
    }
    synLog.traceOrDebug("End : Property mediator");
    return true;
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) Set(java.util.Set) HashMap(java.util.HashMap) OMElement(org.apache.axiom.om.OMElement) Registry(org.apache.synapse.registry.Registry) SynapseLog(org.apache.synapse.SynapseLog) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 3 with SynapseLog

use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.

the class RespondMediator method mediate.

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 : Respond Mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    synCtx.setTo(null);
    synCtx.setResponse(true);
    Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
    org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
    axis2MessageCtx.getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
    Axis2Sender.sendBack(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("End : Respond Mediator");
    }
    return false;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 4 with SynapseLog

use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.

the class ValidateMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Validate mediator : Mediating from ContinuationState");
    }
    boolean result;
    if (!continuationState.hasChild()) {
        result = super.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
        if (RuntimeStatisticCollector.isStatisticsEnabled()) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator) AbstractListMediator(org.apache.synapse.mediators.AbstractListMediator)

Example 5 with SynapseLog

use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.

the class AbstractDBMediator method mediate.

/**
 * Process each SQL statement against the current message
 *
 * @param synCtx the current message
 * @return true, always
 */
public boolean mediate(MessageContext synCtx) {
    // before DataSourceService in tenant mode
    if (!initialized) {
        synchronized (lock) {
            if (!initialized && dataSourceName != null) {
                dataSource = lookupDataSource(dataSourceName, jndiProperties);
                if (dataSource != null) {
                    initialized = true;
                }
            }
        }
    }
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    String name = (this instanceof DBLookupMediator ? "DBLookup" : "DBReport");
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Start : " + name + " mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    for (Statement aStatement : statementList) {
        if (aStatement != null) {
            processStatement(aStatement, synCtx);
        }
    }
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("End : " + name + " mediator");
    }
    return true;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SynapseLog (org.apache.synapse.SynapseLog)53 Mediator (org.apache.synapse.Mediator)16 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)13 SynapseException (org.apache.synapse.SynapseException)10 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)9 MessageContext (org.apache.synapse.MessageContext)8 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)8 OMNode (org.apache.axiom.om.OMNode)7 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)6 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)6 JaxenException (org.jaxen.JaxenException)5 PreparedStatement (java.sql.PreparedStatement)4 Set (java.util.Set)4 AxisFault (org.apache.axis2.AxisFault)4 OperationContext (org.apache.axis2.context.OperationContext)4 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 ReliantContinuationState (org.apache.synapse.continuation.ReliantContinuationState)3 Endpoint (org.apache.synapse.endpoints.Endpoint)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2