use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class AbstractEndpoint method send.
public void send(MessageContext synCtx) {
logSetter();
Integer statisticReportingIndex = null;
boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
if (isStatisticsEnabled) {
statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, getReportingName(), definition.getAspectConfiguration(), ComponentType.ENDPOINT);
}
boolean traceOn = isTraceOn(synCtx);
boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
if (!initialized) {
// can't send to a non-initialized endpoint. This is a program fault
throw new IllegalStateException("not initialized, " + "endpoint must be in initialized state");
}
prepareForEndpointStatistics(synCtx);
if (traceOrDebugOn) {
String address = definition.getAddress();
if (address == null && synCtx.getTo() != null && synCtx.getTo().getAddress() != null) {
// compute address for the default endpoint only for logging purposes
address = synCtx.getTo().getAddress();
}
traceOrDebug(traceOn, "Sending message through endpoint : " + getName() + " resolving to address = " + address);
traceOrDebug(traceOn, "SOAPAction: " + (synCtx.getSoapAction() != null ? synCtx.getSoapAction() : "null"));
traceOrDebug(traceOn, "WSA-Action: " + (synCtx.getWSAAction() != null ? synCtx.getWSAAction() : "null"));
if (traceOn && trace.isTraceEnabled()) {
trace.trace("Envelope : \n" + synCtx.getEnvelope());
}
}
// push the errorHandler sequence into the current message as the fault handler
if (errorHandler != null) {
Mediator errorHandlerMediator = synCtx.getSequence(errorHandler);
if (errorHandlerMediator != null) {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Setting the onError handler : " + errorHandler + " for the endpoint : " + endpointName);
}
synCtx.pushFaultHandler(new MediatorFaultHandler(errorHandlerMediator));
} else {
log.warn("onError handler sequence : " + errorHandler + " for : " + endpointName + " cannot be found");
}
}
// register this as the immediate fault handler for this message.
synCtx.pushFaultHandler(this);
// add this as the last endpoint to process this message - used by statistics counting code
synCtx.setProperty(SynapseConstants.LAST_ENDPOINT, this);
// set message level metrics collector
org.apache.axis2.context.MessageContext axis2Ctx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
axis2Ctx.setProperty(BaseConstants.METRICS_COLLECTOR, metricsMBean);
if (contentAware) {
try {
RelayUtils.buildMessage(((Axis2MessageContext) synCtx).getAxis2MessageContext(), false);
axis2Ctx.setProperty(RelayConstants.FORCE_RESPONSE_EARLY_BUILD, Boolean.TRUE);
if (forceBuildMC) {
((Axis2MessageContext) synCtx).getAxis2MessageContext().getEnvelope().build();
}
} catch (Exception e) {
handleException("Error while building message", e);
}
}
evaluateProperties(synCtx);
// if the envelope preserving set build the envelope
MediatorProperty preserveEnv = getProperty(SynapseConstants.PRESERVE_ENVELOPE);
if (preserveEnv != null && JavaUtils.isTrueExplicitly(preserveEnv.getValue() != null ? preserveEnv.getValue() : preserveEnv.getEvaluatedExpression(synCtx))) {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Preserving the envelope by building it before " + "sending, since it is explicitly set");
}
synCtx.getEnvelope().build();
}
// Send the message through this endpoint
synCtx.getEnvironment().send(definition, synCtx);
if (isStatisticsEnabled) {
CloseEventCollector.closeEntryEvent(synCtx, getReportingName(), ComponentType.ENDPOINT, statisticReportingIndex, false);
}
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class APIDebugUtil method registerAPISequenceMediationFlowSkip.
/**
* Registers/Un-registers a skip, point where mediator disables from the mediation flow
*
* @param synCfg Synapse configuration
* @param mapping either resource url-mapping or uri-template
* @param method resource http method
* @param seqType Synapse sequence type
* @param apiKey name of the API
* @param position array of integers that uniquely specifies a point in mediation route
* @param registerMode specify whether register or un register
*/
public static void registerAPISequenceMediationFlowSkip(SynapseConfiguration synCfg, String mapping, String method, String seqType, String apiKey, int[] position, boolean registerMode) {
SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(seqType.toUpperCase());
APIMediationFlowPoint skipPoint = new APIMediationFlowPoint();
skipPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
skipPoint.setKey(apiKey);
skipPoint.setMediatorPosition(position);
skipPoint.setSynapseSequenceType(synapseSequenceType);
skipPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API);
skipPoint.setResourceMapping(mapping);
skipPoint.setResourceHTTPMethod(method);
Mediator seqMediator = null;
Resource api_resource = null;
API api = synCfg.getAPI(apiKey);
if (api == null) {
if (log.isDebugEnabled()) {
log.debug("Non existing API for the key " + skipPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_NOT_FOUND).toString());
return;
}
Resource[] resource_array = api.getResources();
for (int counter = 0; counter < resource_array.length; counter++) {
if (resource_array[counter].getDispatcherHelper() != null && mapping != null) {
if (mapping.equals(resource_array[counter].getDispatcherHelper().getString())) {
for (String m1 : resource_array[counter].getMethods()) {
if (m1.equals(method)) {
api_resource = resource_array[counter];
break;
}
}
if (api_resource != null) {
break;
}
}
} else if (resource_array[counter].getDispatcherHelper() == null && mapping == null) {
for (String m1 : resource_array[counter].getMethods()) {
if (m1.equals(method)) {
api_resource = resource_array[counter];
break;
}
}
if (api_resource != null) {
break;
}
}
}
if (api_resource != null) {
if (synapseSequenceType.equals(SynapseSequenceType.API_INSEQ)) {
seqMediator = api_resource.getInSequence();
} else if (synapseSequenceType.equals(SynapseSequenceType.API_OUTSEQ)) {
seqMediator = api_resource.getOutSequence();
} else if (synapseSequenceType.equals(SynapseSequenceType.API_FAULTSEQ)) {
seqMediator = api_resource.getFaultSequence();
}
} else {
if (log.isDebugEnabled()) {
log.debug("Resource not found for the API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_RESOURCE_NOT_FOUND).toString());
return;
}
if (seqMediator != null) {
Mediator current_mediator = null;
current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, position);
if (current_mediator != null) {
skipPoint.setMediatorReference(current_mediator);
if (registerMode) {
if (!((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).setSkipEnabled(true);
((AbstractMediator) current_mediator).registerMediationFlowPoint(skipPoint);
if (log.isDebugEnabled()) {
log.debug("Registered skip at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Already skip enabled at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_ENABLED).toString());
}
} else {
if (((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
((AbstractMediator) current_mediator).setSkipEnabled(false);
if (log.isDebugEnabled()) {
log.debug("Unregistered skip at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Already skip disabled at mediator position " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_DISABLED).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod() + " sequence type " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for API key " + skipPoint.getKey() + " resource mapping " + skipPoint.getResourceMapping() + " resource HTTP method " + skipPoint.getResourceHTTPMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
}
}
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class InboundEndpointDebugUtil method registerInboundSequenceMediationFlowSkip.
/**
* Registers/Un-registers a skip, point where mediator disables from mediation flow
*
* @param synCfg Synapse configuration
* @param seqType Synapse sequence type
* @param inboundKey name of the Inbound Endpoint
* @param position array of integers that uniquely specifies a point in mediation route
* @param registerMode specify whether register or un register
*/
public static void registerInboundSequenceMediationFlowSkip(SynapseConfiguration synCfg, String seqType, String inboundKey, int[] position, boolean registerMode) {
SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(seqType.toUpperCase());
SequenceMediationFlowPoint skipPoint = new SequenceMediationFlowPoint();
skipPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
skipPoint.setKey(inboundKey);
skipPoint.setMediatorPosition(position);
skipPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND);
skipPoint.setSynapseSequenceType(synapseSequenceType);
Mediator seqMediator = null;
InboundEndpoint inbound = null;
inbound = synCfg.getInboundEndpoint(inboundKey);
if (inbound != null) {
if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_SEQ)) {
seqMediator = synCfg.getSequence(inbound.getInjectingSeq());
} else if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_FAULTSEQ)) {
seqMediator = synCfg.getSequence(inbound.getOnErrorSeq());
}
} else {
if (log.isDebugEnabled()) {
log.debug("Non existing Inbound Endpoint for key " + skipPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_INBOUND_NOT_FOUND).toString());
return;
}
if (seqMediator != null) {
Mediator current_mediator = null;
current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, position);
if (current_mediator != null) {
skipPoint.setMediatorReference(current_mediator);
if (registerMode) {
if (!((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).setSkipEnabled(true);
((AbstractMediator) current_mediator).registerMediationFlowPoint(skipPoint);
if (log.isDebugEnabled()) {
log.debug("Registered skip at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Already skip enabled at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_ENABLED).toString());
}
} else {
if (((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
((AbstractMediator) current_mediator).setSkipEnabled(false);
if (log.isDebugEnabled()) {
log.debug("Unregistered skip at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Already skip disabled at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_DISABLED).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for Inbound Endpoint key " + skipPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for Inbound Endpoint key " + skipPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
}
}
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class MediatorTreeTraverseUtil method getCorrectedPossition.
/**
* Developer Studio will send mediator positions without considering "Comment Mediators".
* Due to that reason, if there are comments in the source view, mediator positions become incorrect.
* This method will return the corrected mediator position considering "Comment Mediators" as well.
*
* @param seqMediator
* @param position
* @return correctedPossition considering comment mediators
*/
private static int getCorrectedPossition(AbstractListMediator seqMediator, int position) {
int positionWithComments = 0;
int positionWithoutComments = 0;
for (Mediator mediator : seqMediator.getList()) {
if (!(mediator instanceof CommentMediator)) {
if (positionWithoutComments == position) {
return positionWithComments;
}
++positionWithoutComments;
}
++positionWithComments;
}
return position;
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class HandlerUtil method mediateOutMessage.
public static boolean mediateOutMessage(Log log, MessageContext messageContext, org.apache.synapse.MessageContext synCtx) throws AxisFault {
AxisService service = messageContext.getAxisService();
if (service != null) {
Parameter inMediationParam = service.getParameter(HandlerConstants.OUT_SEQUENCE_PARAM_NAME);
if (inMediationParam != null && inMediationParam.getValue() != null) {
if (inMediationParam.getValue() instanceof Mediator) {
Mediator inMessageSequence = (Mediator) inMediationParam.getValue();
return inMessageSequence.mediate(synCtx);
} else if (inMediationParam.getValue() instanceof String) {
Mediator inMessageSequence = synCtx.getConfiguration().getSequence((String) inMediationParam.getValue());
return inMessageSequence.mediate(synCtx);
} else {
if (log.isDebugEnabled()) {
log.debug("The provided out message mediation " + "sequence is not a proper mediator");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Couldn't find the outgoing mediation for the service " + service.getName());
}
}
} else {
String message = "Couldn't find the Service for the associated message with id " + messageContext.getMessageID();
log.error(message);
throw new AxisFault(message);
}
return true;
}
Aggregations