use of org.apache.synapse.mediators.base.SequenceMediator 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;
}
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class CloneMediator method init.
public void init(SynapseEnvironment se) {
synapseEnv = se;
for (Target target : targets) {
ManagedLifecycle seq = target.getSequence();
if (seq != null) {
seq.init(se);
} else if (target.getSequenceRef() != null) {
SequenceMediator targetSequence = (SequenceMediator) se.getSynapseConfiguration().getSequence(target.getSequenceRef());
if (targetSequence == null || targetSequence.isDynamic()) {
se.addUnavailableArtifactRef(target.getSequenceRef());
}
}
Endpoint endpoint = target.getEndpoint();
if (endpoint != null) {
endpoint.init(se);
}
}
}
use of org.apache.synapse.mediators.base.SequenceMediator 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.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class Resource method process.
void process(MessageContext synCtx) {
Integer statisticReportingIndex = null;
boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
if (!synCtx.isResponse()) {
if (getDispatcherHelper() != null) {
synCtx.setProperty(RESTConstants.REST_URL_PATTERN, getDispatcherHelper().getString());
}
}
if (isStatisticsEnabled) {
statisticReportingIndex = OpenEventCollector.reportChildEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, getAspectConfiguration(), true);
}
if (log.isDebugEnabled()) {
log.debug("Processing message with ID: " + synCtx.getMessageID() + " through the " + "resource: " + name);
}
if (!synCtx.isResponse()) {
String method = (String) synCtx.getProperty(RESTConstants.REST_METHOD);
if (RESTConstants.METHOD_OPTIONS.equals(method) && sendOptions(synCtx)) {
if (isStatisticsEnabled) {
CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
}
return;
}
synCtx.setProperty(RESTConstants.SYNAPSE_RESOURCE, name);
String path = RESTUtils.getFullRequestPath(synCtx);
int queryIndex = path.indexOf('?');
if (queryIndex != -1) {
String query = path.substring(queryIndex + 1);
String[] entries = query.split(RESTConstants.QUERY_PARAM_DELIMITER);
String name = null, value;
for (String entry : entries) {
int index = entry.indexOf('=');
if (index != -1) {
try {
name = entry.substring(0, index);
value = URLDecoder.decode(entry.substring(index + 1), RESTConstants.DEFAULT_ENCODING);
synCtx.setProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + name, value);
} catch (UnsupportedEncodingException ignored) {
}
} else {
// If '=' sign isn't presnet in the entry means that the '&' character is part of
// the query parameter value. If so query parameter value should be updated appending
// the remaining characters.
String existingValue = (String) synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + name);
value = RESTConstants.QUERY_PARAM_DELIMITER + entry;
synCtx.setProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + name, existingValue + value);
}
}
}
}
SequenceMediator sequence = synCtx.isResponse() ? outSequence : inSequence;
if (sequence != null) {
registerFaultHandler(synCtx);
sequence.mediate(synCtx);
if (isStatisticsEnabled) {
CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
}
return;
}
String sequenceKey = synCtx.isResponse() ? outSequenceKey : inSequenceKey;
if (sequenceKey != null) {
registerFaultHandler(synCtx);
Mediator referredSequence = synCtx.getSequence(sequenceKey);
if (referredSequence != null) {
referredSequence.mediate(synCtx);
} else {
throw new SynapseException("Specified sequence: " + sequenceKey + " cannot " + "be found");
}
if (isStatisticsEnabled) {
CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
}
return;
}
// response, simply send it back to the client.
if (synCtx.isResponse()) {
if (log.isDebugEnabled()) {
log.debug("No out-sequence configured. Sending the response back.");
}
registerFaultHandler(synCtx);
Axis2Sender.sendBack(synCtx);
} else if (log.isDebugEnabled()) {
log.debug("No in-sequence configured. Dropping the request.");
}
if (isStatisticsEnabled) {
CloseEventCollector.closeEntryEvent(synCtx, getResourceName(synCtx, name), ComponentType.RESOURCE, statisticReportingIndex, true);
}
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class SequenceDeployer method undeploySynapseArtifact.
@Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Sequence Undeployment of the sequence named : " + artifactName + " : Started");
}
try {
SequenceMediator seq = getSynapseConfiguration().getDefinedSequences().get(artifactName);
if (seq != null) {
CustomLogSetter.getInstance().setLogAppender(seq.getArtifactContainerName());
if (SynapseConstants.MAIN_SEQUENCE_KEY.equals(seq.getName()) || SynapseConstants.FAULT_SEQUENCE_KEY.equals(seq.getName())) {
handleSynapseArtifactDeploymentError("Cannot Undeploy the " + seq.getName() + " sequence");
}
getSynapseConfiguration().removeSequence(artifactName);
if (log.isDebugEnabled()) {
log.debug("Destroying the sequence named : " + artifactName);
}
seq.destroy();
if (log.isDebugEnabled()) {
log.debug("Sequence Undeployment of the sequence named : " + artifactName + " : Completed");
}
log.info("Sequence named '" + seq.getName() + "' has been undeployed");
} else if (log.isDebugEnabled()) {
log.debug("Sequence " + artifactName + " has already been undeployed");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Sequence Undeployement of sequence named : " + artifactName + " : Failed", e);
}
}
Aggregations