use of org.apache.synapse.FaultHandler in project wso2-synapse by wso2.
the class AsyncCallback method onError.
public void onError(Exception e) {
axis2OutMsgCtx.setFailureReason(e);
log.error(e.getMessage(), e);
if (!synapseOutMsgCtx.getFaultStack().isEmpty()) {
if (log.isWarnEnabled()) {
log.warn("Executing fault handler due to exception encountered");
}
((FaultHandler) synapseOutMsgCtx.getFaultStack().pop()).handleFault(synapseOutMsgCtx, new SynapseException(e.getMessage(), e));
} else {
if (log.isWarnEnabled()) {
log.warn("Exception encountered but no fault handler found - " + "message dropped");
}
}
}
use of org.apache.synapse.FaultHandler in project wso2-synapse by wso2.
the class Target method mediate.
/**
* process the message through this target (may be to mediate
* using the target sequence, send message to the target endpoint or both)
*
* @param synCtx - MessageContext to be mediated
* @return <code>false</code> if the target is mediated as synchronous and the sequence
* mediation returns <code>false</code>, <code>true</code> otherwise
*/
public boolean mediate(MessageContext synCtx) {
boolean returnValue = true;
if (log.isDebugEnabled()) {
log.debug("Target mediation : START");
}
if (soapAction != null) {
if (log.isDebugEnabled()) {
log.debug("Setting the SOAPAction as : " + soapAction);
}
synCtx.setSoapAction(soapAction);
}
if (toAddress != null) {
if (log.isDebugEnabled()) {
log.debug("Setting the To header as : " + toAddress);
}
if (synCtx.getTo() != null) {
synCtx.getTo().setAddress(toAddress);
} else {
synCtx.setTo(new EndpointReference(toAddress));
}
}
// through a sequence and then again with an endpoint
if (sequence != null) {
if (asynchronous) {
if (log.isDebugEnabled()) {
log.debug("Asynchronously mediating using the in-lined anonymous sequence");
}
synCtx.getEnvironment().injectAsync(synCtx, sequence);
} else {
if (log.isDebugEnabled()) {
log.debug("Synchronously mediating using the in-lined anonymous sequence");
}
returnValue = sequence.mediate(synCtx);
}
} else if (sequenceRef != null) {
SequenceMediator refSequence = (SequenceMediator) synCtx.getSequence(sequenceRef);
// if target directs the message to a defined sequence, ReliantContState added by
// Clone/Iterate mediator is no longer needed as defined sequence can be directly
// referred from a SeqContinuationState
ContinuationStackManager.removeReliantContinuationState(synCtx);
if (refSequence != null) {
if (asynchronous) {
if (log.isDebugEnabled()) {
log.debug("Asynchronously mediating using the sequence " + "named : " + sequenceRef);
}
synCtx.getEnvironment().injectAsync(synCtx, refSequence);
} else {
if (log.isDebugEnabled()) {
log.debug("Synchronously mediating using the sequence " + "named : " + sequenceRef);
}
try {
returnValue = refSequence.mediate(synCtx);
} catch (SynapseException syne) {
if (!synCtx.getFaultStack().isEmpty()) {
log.warn("Executing fault handler due to exception encountered");
((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
} else {
log.warn("Exception encountered but no fault handler found - message dropped");
}
} catch (Exception e) {
String msg = "Unexpected error occurred executing the Target";
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);
} else {
log.warn("Exception encountered but no fault handler found - message dropped");
}
}
}
} else {
handleException("Couldn't find the sequence named : " + sequenceRef);
}
} else if (endpoint != null) {
if (log.isDebugEnabled()) {
log.debug("Sending using the in-lined anonymous endpoint");
}
ContinuationStackManager.removeReliantContinuationState(synCtx);
endpoint.send(synCtx);
} else if (endpointRef != null) {
ContinuationStackManager.removeReliantContinuationState(synCtx);
Endpoint epr = synCtx.getConfiguration().getEndpoint(endpointRef);
if (epr != null) {
if (log.isDebugEnabled()) {
log.debug("Sending using the endpoint named : " + endpointRef);
}
if (!epr.isInitialized()) {
// initializing registry
epr.init(synCtx.getEnvironment());
// base endpoint configuration
}
epr.send(synCtx);
// epr.destroy();
} else {
handleException("Couldn't find the endpoint named : " + endpointRef);
}
}
if (log.isDebugEnabled()) {
log.debug("Target mediation : END");
}
return returnValue;
}
Aggregations