Search in sources :

Example 6 with FaultHandler

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");
        }
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) FaultHandler(org.apache.synapse.FaultHandler)

Example 7 with FaultHandler

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;
}
Also used : SynapseException(org.apache.synapse.SynapseException) Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) FaultHandler(org.apache.synapse.FaultHandler) SynapseException(org.apache.synapse.SynapseException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

FaultHandler (org.apache.synapse.FaultHandler)7 ArrayList (java.util.ArrayList)4 Stack (java.util.Stack)3 ContinuationState (org.apache.synapse.ContinuationState)3 MessageContext (org.apache.synapse.MessageContext)3 EndpointReference (org.apache.axis2.addressing.EndpointReference)2 SynapseException (org.apache.synapse.SynapseException)2 SeqContinuationState (org.apache.synapse.continuation.SeqContinuationState)2 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 TemplateContext (org.apache.synapse.mediators.template.TemplateContext)2 List (java.util.List)1 OMElement (org.apache.axiom.om.OMElement)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 RelatesTo (org.apache.axis2.addressing.RelatesTo)1 MessageContext (org.apache.axis2.context.MessageContext)1 NHttpServerConnection (org.apache.http.nio.NHttpServerConnection)1 TenantInfoConfigurator (org.apache.synapse.carbonext.TenantInfoConfigurator)1 ConcurrentAccessController (org.apache.synapse.commons.throttle.core.ConcurrentAccessController)1 ConcurrentAccessReplicator (org.apache.synapse.commons.throttle.core.ConcurrentAccessReplicator)1