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