use of org.apache.synapse.debug.SynapseDebugManager in project wso2-synapse by wso2.
the class Axis2SynapseEnvironment method injectMessage.
public boolean injectMessage(final MessageContext synCtx) {
try {
if (log.isDebugEnabled()) {
log.debug("Injecting MessageContext");
}
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.acquireMediationFlowLock();
debugManager.advertiseMediationFlowStartPoint(synCtx);
}
// setting transport-in name as a message context property
TransportInDescription trpInDesc = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getTransportIn();
if (trpInDesc != null) {
synCtx.setProperty(SynapseConstants.TRANSPORT_IN_NAME, trpInDesc.getName());
}
synCtx.setEnvironment(this);
if (!invokeHandlers(synCtx)) {
return false;
}
Mediator mandatorySeq = synCtx.getConfiguration().getMandatorySequence();
// the mandatory sequence is optional and hence check for the existence before mediation
if (mandatorySeq != null) {
if (log.isDebugEnabled()) {
log.debug("Start mediating the message in the " + "pre-mediate state using the mandatory sequence");
}
if (!mandatorySeq.mediate(synCtx)) {
if (log.isDebugEnabled()) {
log.debug((synCtx.isResponse() ? "Response" : "Request") + " message for the " + (synCtx.getProperty(SynapseConstants.PROXY_SERVICE) != null ? "proxy service " + synCtx.getProperty(SynapseConstants.PROXY_SERVICE) : "message mediation") + " dropped in the " + "pre-mediation state by the mandatory sequence : \n" + synCtx);
}
return false;
}
}
String receivingSequence = (String) synCtx.getProperty(SynapseConstants.RECEIVING_SEQUENCE);
Boolean isContinuationCall = (Boolean) synCtx.getProperty(SynapseConstants.CONTINUATION_CALL);
// clear the message context properties related to endpoint in last service invocation
Set keySet = synCtx.getPropertyKeySet();
if (keySet != null) {
keySet.remove(SynapseConstants.RECEIVING_SEQUENCE);
keySet.remove(SynapseConstants.CONTINUATION_CALL);
}
if (isContinuationCall != null && isContinuationCall && !synCtx.getContinuationStateStack().isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Response received for the Continuation Call service invocation");
}
return mediateFromContinuationStateStack(synCtx);
}
// if this is not a response to a proxy service
String proxyName = (String) synCtx.getProperty(SynapseConstants.PROXY_SERVICE);
if (proxyName == null || "".equals(proxyName)) {
// set default fault handler
synCtx.pushFaultHandler(new MediatorFaultHandler(synCtx.getFaultSequence()));
if (receivingSequence != null) {
if (log.isDebugEnabled()) {
log.debug("Using Sequence with name: " + receivingSequence + " for injected message");
}
Mediator seqMediator = synCtx.getSequence(receivingSequence);
if (seqMediator != null) {
return seqMediator.mediate(synCtx);
} else {
log.warn("Cannot find a Sequence with name: " + receivingSequence + " for injecting the response message");
return false;
}
} else {
boolean processed = restHandler.process(synCtx);
if (processed) {
return true;
}
if (log.isDebugEnabled()) {
log.debug("Using Main Sequence for injected message");
}
return synCtx.getMainSequence().mediate(synCtx);
}
}
ProxyService proxyService = synCtx.getConfiguration().getProxyService(proxyName);
if (proxyService != null) {
proxyService.registerFaultHandler(synCtx);
Mediator outSequence = getProxyOutSequence(synCtx, proxyService);
if (receivingSequence != null) {
if (log.isDebugEnabled()) {
log.debug("Using Sequence with name: " + receivingSequence + " for injected message");
}
Mediator seqMediator = synCtx.getSequence(receivingSequence);
if (seqMediator != null) {
seqMediator.mediate(synCtx);
} else {
log.warn("Cannot find a Sequence with name: " + receivingSequence + " for injecting the message");
return false;
}
} else if (outSequence != null) {
outSequence.mediate(synCtx);
} else {
if (log.isDebugEnabled()) {
log.debug(proxyService + " does not specifies an out-sequence - sending the response back");
}
Axis2Sender.sendBack(synCtx);
}
}
return true;
} finally {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.advertiseMediationFlowTerminatePoint(synCtx);
debugManager.releaseMediationFlowLock();
}
}
}
use of org.apache.synapse.debug.SynapseDebugManager in project wso2-synapse by wso2.
the class Axis2SynapseEnvironment method injectInbound.
/**
* Used by inbound polling endpoints to inject the message to synapse engine
*
* @param synCtx message context
* @param sequential whether message should be injected in sequential manner
* without spawning new threads
* @return Boolean - Indicate if were able to inject the message
* @throws SynapseException
* - in case error occured during the mediation
*/
public boolean injectInbound(final MessageContext synCtx, SequenceMediator seq, boolean sequential) throws SynapseException {
String inboundName = null;
boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
AspectConfiguration inboundAspectConfiguration = null;
Integer statisticReportingIndex = null;
if (log.isDebugEnabled()) {
log.debug("Injecting MessageContext for inbound mediation using the : " + (seq.getName() == null ? "Anonymous" : seq.getName()) + " Sequence");
}
/*
* If the method is invoked by the inbound endpoint
* Then check for the endpoint name and then set the Log Appender Content
*/
if (synCtx.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME) != null) {
InboundEndpoint inboundEndpoint = synCtx.getConfiguration().getInboundEndpoint((String) synCtx.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME));
if (inboundEndpoint != null) {
CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
if (inboundEndpoint.getAspectConfiguration() != null) {
// inboundStatistics = inboundEndpoint.getAspectConfiguration().isStatisticsEnable();
inboundAspectConfiguration = inboundEndpoint.getAspectConfiguration();
}
inboundName = (String) synCtx.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME);
}
}
synCtx.setEnvironment(this);
if (!invokeHandlers(synCtx)) {
return false;
}
if (!sequential) {
try {
if (isStatisticsEnabled) {
statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, inboundName, inboundAspectConfiguration, ComponentType.INBOUNDENDPOINT);
}
executorServiceInbound.execute(new MediatorWorker(seq, synCtx));
return true;
} catch (RejectedExecutionException re) {
// If the pool is full complete the execution with the same thread
log.warn("Inbound worker pool has reached the maximum capacity and will be processing current message sequentially.");
} finally {
if (isStatisticsEnabled) {
CloseEventCollector.tryEndFlow(synCtx, inboundName, ComponentType.INBOUNDENDPOINT, statisticReportingIndex, false);
}
}
}
// reached max level
if (isStatisticsEnabled) {
statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, inboundName, inboundAspectConfiguration, ComponentType.INBOUNDENDPOINT);
}
try {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.acquireMediationFlowLock();
debugManager.advertiseMediationFlowStartPoint(synCtx);
}
seq.mediate(synCtx);
return true;
} catch (SynapseException syne) {
if (!synCtx.getFaultStack().isEmpty()) {
log.warn("Executing fault handler due to exception encountered");
((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
return true;
} else {
log.warn("Exception encountered but no fault handler found - message dropped");
throw syne;
}
} catch (Exception e) {
String msg = "Unexpected error executing task/async inject";
log.error(msg, e);
if (synCtx.getServiceLog() != null) {
synCtx.getServiceLog().error(msg, e);
}
if (!synCtx.getFaultStack().isEmpty()) {
log.warn("Executing fault handler due to exception encountered");
((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, e);
return true;
} else {
log.warn("Exception encountered but no fault handler found - message dropped");
throw new SynapseException("Exception encountered but no fault handler found - message dropped", e);
}
} catch (Throwable e) {
String msg = "Unexpected error executing inbound/async inject, message dropped";
log.error(msg, e);
if (synCtx.getServiceLog() != null) {
synCtx.getServiceLog().error(msg, e);
}
throw new SynapseException(msg, e);
} finally {
if (isStatisticsEnabled) {
CloseEventCollector.tryEndFlow(synCtx, inboundName, ComponentType.INBOUNDENDPOINT, statisticReportingIndex, false);
}
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.advertiseMediationFlowTerminatePoint(synCtx);
debugManager.releaseMediationFlowLock();
}
}
}
use of org.apache.synapse.debug.SynapseDebugManager in project wso2-synapse by wso2.
the class ProxyServiceMessageReceiver method receive.
public void receive(org.apache.axis2.context.MessageContext mc) throws AxisFault {
boolean traceOn = proxy.getAspectConfiguration().isTracingEnabled();
boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
CustomLogSetter.getInstance().setLogAppender(proxy.getArtifactContainerName());
String remoteAddr = (String) mc.getProperty(org.apache.axis2.context.MessageContext.REMOTE_ADDR);
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Proxy Service " + name + " received a new message" + (remoteAddr != null ? " from : " + remoteAddr : "..."));
traceOrDebug(traceOn, ("Message To: " + (mc.getTo() != null ? mc.getTo().getAddress() : "null")));
traceOrDebug(traceOn, ("SOAPAction: " + (mc.getSoapAction() != null ? mc.getSoapAction() : "null")));
traceOrDebug(traceOn, ("WSA-Action: " + (mc.getWSAAction() != null ? mc.getWSAAction() : "null")));
if (traceOn && trace.isTraceEnabled()) {
String[] cids = null;
try {
cids = mc.getAttachmentMap().getAllContentIDs();
} catch (Exception ex) {
// partially read stream could lead to corrupted attachment map and hence this exception
// corrupted attachment map leads to inconsistent runtime exceptions and behavior
// discard the attachment map for the fault handler invocation
// ensure the successful completion for fault handler flow
mc.setAttachmentMap(null);
log.error("Synapse encountered an exception when reading attachments from bytes stream. " + "Hence Attachments map is dropped from the message context.", ex);
}
if (cids != null && cids.length > 0) {
for (String cid : cids) {
trace.trace("With attachment content ID : " + cid);
}
}
trace.trace("Envelope : " + mc.getEnvelope());
}
}
MessageContext synCtx = MessageContextCreatorForAxis2.getSynapseMessageContext(mc);
Integer statisticReportingIndex = null;
// Statistic reporting
boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
if (isStatisticsEnabled) {
statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, this.name, proxy.getAspectConfiguration(), ComponentType.PROXYSERVICE);
}
Object inboundServiceParam = proxy.getParameterMap().get(SynapseConstants.INBOUND_PROXY_SERVICE_PARAM);
Object inboundMsgCtxParam = mc.getProperty(SynapseConstants.IS_INBOUND);
// check whether the message is from Inbound EP
if (inboundMsgCtxParam == null || !(boolean) inboundMsgCtxParam) {
// check whether service parameter is set to true or null, then block this request
if (inboundServiceParam != null && (Boolean.valueOf((String) inboundServiceParam))) {
/*
return because same proxy is exposed via InboundEP and service parameter(inbound.only) is set to
true, which disable normal http transport proxy
*/
if (!synCtx.getFaultStack().isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Executing fault handler - message discarded due to the proxy is allowed only via InboundEP");
}
(synCtx.getFaultStack().pop()).handleFault(synCtx, new Exception("Proxy Service " + name + " message discarded due to the proxy is allowed only via InboundEP"));
} else {
if (log.isDebugEnabled()) {
log.debug("Proxy Service " + name + " message discarded due to the proxy is " + "allowed only via InboundEP");
}
}
return;
}
}
TenantInfoConfigurator configurator = synCtx.getEnvironment().getTenantInfoConfigurator();
if (configurator != null) {
configurator.extractTenantInfo(synCtx);
}
TransportInDescription trpInDesc = mc.getTransportIn();
if (trpInDesc != null) {
synCtx.setProperty(SynapseConstants.TRANSPORT_IN_NAME, trpInDesc.getName());
}
// get service log for this message and attach to the message context also set proxy name
Log serviceLog = LogFactory.getLog(SynapseConstants.SERVICE_LOGGER_PREFIX + name);
((Axis2MessageContext) synCtx).setServiceLog(serviceLog);
synCtx.setProperty(SynapseConstants.PROXY_SERVICE, name);
// synCtx.setTracingState(proxy.getTraceState());
synCtx.setProperty(SynapseConstants.IS_CLIENT_DOING_REST, mc.isDoingREST());
synCtx.setProperty(SynapseConstants.IS_CLIENT_DOING_SOAP11, mc.isSOAP11());
try {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.acquireMediationFlowLock();
debugManager.advertiseMediationFlowStartPoint(synCtx);
if (!synCtx.isResponse()) {
SynapseWireLogHolder wireLogHolder = (SynapseWireLogHolder) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY);
if (wireLogHolder == null) {
wireLogHolder = new SynapseWireLogHolder();
}
if (synCtx.getProperty(SynapseConstants.PROXY_SERVICE) != null && !synCtx.getProperty(SynapseConstants.PROXY_SERVICE).toString().isEmpty()) {
wireLogHolder.setProxyName(synCtx.getProperty(SynapseConstants.PROXY_SERVICE).toString());
}
((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY, wireLogHolder);
}
}
synCtx.setProperty(SynapseConstants.RESPONSE_STATE, new ResponseState());
List handlers = synCtx.getEnvironment().getSynapseHandlers();
Iterator<SynapseHandler> iterator = handlers.iterator();
while (iterator.hasNext()) {
SynapseHandler handler = iterator.next();
if (!handler.handleRequestInFlow(synCtx)) {
return;
}
}
Mediator mandatorySeq = synCtx.getConfiguration().getMandatorySequence();
if (mandatorySeq != null) {
if (log.isDebugEnabled()) {
log.debug("Start mediating the message in the " + "pre-mediate state using the mandatory sequence");
}
if (!mandatorySeq.mediate(synCtx)) {
if (log.isDebugEnabled()) {
log.debug("Request message for the proxy service " + name + " dropped in " + "the pre-mediation state by the mandatory sequence : \n" + synCtx);
}
return;
}
}
// setup fault sequence - i.e. what happens when something goes wrong with this message
proxy.registerFaultHandler(synCtx);
boolean inSequenceResult = true;
// Using inSequence for the incoming message mediation
if (proxy.getTargetInSequence() != null) {
Mediator inSequence = synCtx.getSequence(proxy.getTargetInSequence());
if (inSequence != null) {
traceOrDebug(traceOn, "Using sequence named : " + proxy.getTargetInSequence() + " for incoming message mediation");
inSequenceResult = inSequence.mediate(synCtx);
} else {
handleException("Unable to find in-sequence : " + proxy.getTargetInSequence(), synCtx);
}
} else if (proxy.getTargetInLineInSequence() != null) {
traceOrDebug(traceOn, "Using the anonymous " + "in-sequence of the proxy service for mediation");
inSequenceResult = proxy.getTargetInLineInSequence().mediate(synCtx);
}
// if inSequence returns true, forward message to endpoint
if (inSequenceResult) {
if (proxy.getTargetEndpoint() != null) {
Endpoint endpoint = synCtx.getEndpoint(proxy.getTargetEndpoint());
if (endpoint != null) {
traceOrDebug(traceOn, "Forwarding message to the endpoint : " + proxy.getTargetEndpoint());
endpoint.send(synCtx);
} else {
handleException("Unable to find the endpoint specified : " + proxy.getTargetEndpoint(), synCtx);
}
} else if (proxy.getTargetInLineEndpoint() != null) {
traceOrDebug(traceOn, "Forwarding the message to the anonymous " + "endpoint of the proxy service");
proxy.getTargetInLineEndpoint().send(synCtx);
}
}
} catch (SynapseException syne) {
if (!synCtx.getFaultStack().isEmpty()) {
warn(traceOn, "Executing fault handler due to exception encountered", synCtx);
((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
} else {
warn(traceOn, "Exception encountered but no fault handler found - " + "message dropped", synCtx);
}
} finally {
// Statistic reporting
if (isStatisticsEnabled) {
CloseEventCollector.tryEndFlow(synCtx, this.name, ComponentType.PROXYSERVICE, statisticReportingIndex, true);
}
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.advertiseMediationFlowTerminatePoint(synCtx);
debugManager.releaseMediationFlowLock();
}
doPostInjectUpdates(synCtx);
}
}
use of org.apache.synapse.debug.SynapseDebugManager in project wso2-synapse by wso2.
the class MediatorWorker method run.
/**
* Execution method of the thread. This will just call the mediation of the specified
* Synapse MessageContext using the specified Sequence Mediator
*/
public void run() {
try {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.acquireMediationFlowLock();
debugManager.advertiseMediationFlowStartPoint(synCtx);
}
seq.mediate(synCtx);
// ((Axis2MessageContext)synCtx).getAxis2MessageContext().getEnvelope().discard();
} catch (SynapseException syne) {
if (!synCtx.getFaultStack().isEmpty()) {
warn(false, "Executing fault handler due to exception encountered", synCtx);
((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
} else {
warn(false, "Exception encountered but no fault handler found - " + "message dropped", synCtx);
}
} catch (Exception e) {
String msg = "Unexpected error executing task/async inject";
log.error(msg, e);
if (synCtx.getServiceLog() != null) {
synCtx.getServiceLog().error(msg, e);
}
if (!synCtx.getFaultStack().isEmpty()) {
warn(false, "Executing fault handler due to exception encountered", synCtx);
((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, e);
} else {
warn(false, "Exception encountered but no fault handler found - " + "message dropped", synCtx);
}
} catch (Throwable e) {
String msg = "Unexpected error executing task/async inject, message dropped";
log.error(msg, e);
if (synCtx.getServiceLog() != null) {
synCtx.getServiceLog().error(msg, e);
}
} finally {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.advertiseMediationFlowTerminatePoint(synCtx);
debugManager.releaseMediationFlowLock();
}
if (RuntimeStatisticCollector.isStatisticsEnabled()) {
CloseEventCollector.closeFlowForcefully(synCtx, false);
}
}
synCtx = null;
seq = null;
}
Aggregations