Search in sources :

Example 16 with SynapseLog

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

the class InvokeMediator method mediate.

private boolean mediate(MessageContext synCtx, boolean executePreFetchingSequence) {
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Invoking Target EIP Sequence " + targetTemplate + " paramNames : " + pName2ExpressionMap.keySet());
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    // get the target function template and invoke by passing populated
    // parameters
    Mediator mediator = synCtx.getSequenceTemplate(targetTemplate);
    if (mediator == null) {
        handleException("Sequence template " + targetTemplate + " cannot be found", synCtx);
    }
    // setting the log appender when external template executor is called a sequence template inside a car file
    if (mediator instanceof TemplateMediator) {
        CustomLogSetter.getInstance().setLogAppender(((TemplateMediator) mediator).getArtifactContainerName());
    }
    // executing key reference if found defined at configuration.
    if (executePreFetchingSequence && key != null) {
        String defaultConfiguration = key.evaluateValue(synCtx);
        Mediator m = synCtx.getDefaultConfiguration(defaultConfiguration);
        if (m == null) {
            handleException("Sequence named " + key + " cannot be found", synCtx);
        } else {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Executing with key " + key);
            }
            ContinuationStackManager.addReliantContinuationState(synCtx, 1, getMediatorPosition());
            boolean result = m.mediate(synCtx);
            if (result) {
                ContinuationStackManager.removeReliantContinuationState(synCtx);
            } else {
                return false;
            }
        }
    }
    if (mediator != null && mediator instanceof TemplateMediator) {
        populateParameters(synCtx, ((TemplateMediator) mediator).getName());
        if (executePreFetchingSequence) {
            ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
        }
        boolean result = mediator.mediate(synCtx);
        if (result && executePreFetchingSequence) {
            ContinuationStackManager.removeReliantContinuationState(synCtx);
        }
        return result;
    }
    return false;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator)

Example 17 with SynapseLog

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

the class TemplateMediator 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 : EIP Sequence " + "paramNames : " + paramNames);
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    pushFuncContextTo(synCtx);
    boolean result = false;
    try {
        result = super.mediate(synCtx);
    } finally {
        if (result) {
            popFuncContextFrom(synCtx);
        }
    }
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog)

Example 18 with SynapseLog

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

the class DBReportMediator method processStatement.

protected void processStatement(Statement stmnt, MessageContext msgCtx) {
    SynapseLog synLog = getLog(msgCtx);
    Connection con = null;
    boolean threadInTx = false;
    try {
        if (TranscationManger.isThreadHasEnlistment() || useTransaction) {
            threadInTx = true;
            try {
                con = TranscationManger.addConnection(this.getDataSource());
                if (useTransaction) {
                    TranscationManger.bindConnection(con);
                }
            } catch (Exception e) {
                handleException("SQL Error while bind connection to tx : " + stmnt.getRawStatement() + " against DataSource : " + getDSName(), e, msgCtx);
            }
        } else {
            con = this.getDataSource().getConnection();
        }
        PreparedStatement ps = getPreparedStatement(stmnt, con, msgCtx);
        int count = ps.executeUpdate();
        if (count > 0) {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Inserted " + count + " row/s using statement : " + stmnt.getRawStatement());
            }
        } else {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("No rows were inserted for statement : " + stmnt.getRawStatement());
            }
        }
        if (!(threadInTx || useTransaction)) {
            if (!con.getAutoCommit()) {
                con.commit();
            }
        }
    } catch (SQLException e) {
        handleException("SQL Error while executing insert statement : " + stmnt.getRawStatement() + " against DataSource : " + getDSName(), e, msgCtx);
    } catch (Exception e) {
        handleException("Error while executing insert statement : " + stmnt.getRawStatement() + " against DataSource : " + getDSName(), e, msgCtx);
    } finally {
        if (con != null && !(threadInTx || useTransaction)) {
            try {
                con.close();
            } catch (SQLException ignore) {
            }
        }
    }
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 19 with SynapseLog

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

the class AggregateMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState contState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Aggregate mediator : Mediating from ContinuationState");
    }
    boolean result;
    SequenceMediator onCompleteSequence = getOnCompleteSequence();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (!contState.hasChild()) {
        result = onCompleteSequence.mediate(synCtx, contState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) onCompleteSequence.getChild(contState.getPosition());
        result = mediator.mediate(synCtx, contState.getChildContState());
        if (isStatisticsEnabled) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    if (isStatisticsEnabled) {
        onCompleteSequence.reportCloseStatistics(synCtx, null);
    }
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) 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)

Example 20 with SynapseLog

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

the class CallMediator method handleNonBlockingCall.

/**
 * Send request in non-blocking manner
 *
 * @param synInCtx message context
 * @return  continue the mediation flow or not
 */
private boolean handleNonBlockingCall(MessageContext synInCtx) {
    SynapseLog synLog = getLog(synInCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Start : Call mediator - Non Blocking Call");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synInCtx.getEnvelope());
        }
    }
    // Set the last sequence fault handler for future use
    synInCtx.setProperty(SynapseConstants.LAST_SEQ_FAULT_HANDLER, getLastSequenceFaultHandler(synInCtx));
    // clear the message context properties related to endpoint in last service invocation
    Set keySet = synInCtx.getPropertyKeySet();
    if (keySet != null) {
        keySet.remove(SynapseConstants.RECEIVING_SEQUENCE);
        keySet.remove(EndpointDefinition.DYNAMIC_URL_VALUE);
        keySet.remove(SynapseConstants.LAST_ENDPOINT);
    }
    boolean outOnlyMessage = "true".equals(synInCtx.getProperty(SynapseConstants.OUT_ONLY));
    // Prepare the outgoing message context
    MessageContext synOutCtx = null;
    if (outOnlyMessage) {
        try {
            synOutCtx = MessageHelper.cloneMessageContext(synInCtx);
        } catch (AxisFault axisFault) {
            handleException("Error occurred while cloning msg context", axisFault, synInCtx);
        }
    } else {
        synOutCtx = synInCtx;
    }
    synOutCtx.setProperty(SynapseConstants.CONTINUATION_CALL, true);
    ContinuationStackManager.updateSeqContinuationState(synOutCtx, getMediatorPosition());
    // If no endpoints are defined, send where implicitly stated
    if (endpoint == null) {
        if (synLog.isTraceOrDebugEnabled()) {
            StringBuffer sb = new StringBuffer();
            sb.append("Calling ").append(synOutCtx.isResponse() ? "response" : "request").append(" message using implicit message properties..");
            sb.append("\nCalling To: ").append(synOutCtx.getTo() != null ? synOutCtx.getTo().getAddress() : "null");
            sb.append("\nSOAPAction: ").append(synOutCtx.getWSAAction() != null ? synOutCtx.getWSAAction() : "null");
            synLog.traceOrDebug(sb.toString());
        }
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Envelope : " + synOutCtx.getEnvelope());
        }
        synOutCtx.getEnvironment().send(null, synOutCtx);
    } else {
        endpoint.send(synOutCtx);
    }
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("End : Call mediator - Non Blocking Call");
    }
    if (outOnlyMessage) {
        // otherwise flow should stop from here
        return true;
    }
    return false;
}
Also used : AxisFault(org.apache.axis2.AxisFault) SynapseLog(org.apache.synapse.SynapseLog) Set(java.util.Set) MessageContext(org.apache.synapse.MessageContext)

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