Search in sources :

Example 11 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class EIPUtils method enrichEnvelope.

/**
 * Merge two SOAP envelopes using the given XPath expression that specifies the
 * element that enriches the first envelope from the second
 *
 * @param envelope   SOAPEnvelope to be enriched with the content
 * @param enricher   SOAPEnvelope from which the enriching element will be extracted
 * @param expression SynapseXPath describing the enriching element
 * @throws JaxenException on failing of processing the xpath
 */
public static void enrichEnvelope(SOAPEnvelope envelope, SOAPEnvelope enricher, MessageContext synCtxt, SynapseXPath expression) throws JaxenException {
    OMElement enrichingElement;
    enricher.toString();
    List elementList = getMatchingElements(envelope, synCtxt, expression);
    List list = getMatchingElements(enricher, synCtxt, expression);
    if ((checkNotEmpty(elementList) && checkNotEmpty(list)) || (!checkNotEmpty(elementList) && checkNotEmpty(list))) {
        if (checkNotEmpty(elementList)) {
            // attach at parent of the first result from the XPath, or to the SOAPBody
            Object o = elementList.get(0);
            if (o instanceof OMElement && ((OMElement) o).getParent() != null && ((OMElement) o).getParent() instanceof OMElement) {
                enrichingElement = (OMElement) ((OMElement) o).getParent();
                OMElement body = envelope.getBody();
                if (!isBody(body, enrichingElement)) {
                    OMElement nonBodyElem = enrichingElement;
                    enrichingElement = envelope.getBody();
                    addChildren(elementList, enrichingElement);
                    while (!isBody(body, (OMElement) nonBodyElem.getParent())) {
                        nonBodyElem = (OMElement) nonBodyElem.getParent();
                    }
                    nonBodyElem.detach();
                }
            }
        }
        enrichingElement = envelope.getBody();
        // validate child element is a SOAPEnvelop
        for (Object child : list) {
            if (child instanceof SOAPEnvelope) {
                throw new SynapseException("Could not add SOAPEnvelope as child element.");
            }
        }
        addChildren(list, enrichingElement);
    } else {
        throw new SynapseException("Could not find matching elements to aggregate.");
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) OMElement(org.apache.axiom.om.OMElement) List(java.util.List) ArrayList(java.util.ArrayList) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 12 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class CallMediator method handleFault.

private void handleFault(MessageContext synCtx, Exception ex) {
    synCtx.setProperty(SynapseConstants.SENDING_FAULT, Boolean.TRUE);
    if (ex != null && ex instanceof AxisFault) {
        AxisFault axisFault = (AxisFault) ex;
        int errorCode = SynapseConstants.BLOCKING_CALL_OPERATION_FAILED;
        if (axisFault.getFaultCodeElement() != null && !"".equals(axisFault.getFaultCodeElement().getText())) {
            try {
                errorCode = Integer.parseInt(axisFault.getFaultCodeElement().getText());
            } catch (NumberFormatException e) {
                errorCode = SynapseConstants.BLOCKING_CALL_OPERATION_FAILED;
            }
        }
        synCtx.setProperty(SynapseConstants.ERROR_CODE, errorCode);
        if (axisFault.getMessage() != null) {
            synCtx.setProperty(SynapseConstants.ERROR_MESSAGE, axisFault.getMessage());
        } else {
            synCtx.setProperty(SynapseConstants.ERROR_MESSAGE, "Error while performing " + "the call operation");
        }
        if (axisFault.getFaultDetailElement() != null) {
            if (axisFault.getFaultDetailElement().getFirstElement() != null) {
                synCtx.setProperty(SynapseConstants.ERROR_DETAIL, axisFault.getFaultDetailElement().getFirstElement());
            } else {
                synCtx.setProperty(SynapseConstants.ERROR_DETAIL, axisFault.getFaultDetailElement().getText());
            }
        }
    }
    synCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, ex);
    throw new SynapseException("Error while performing the call operation", ex);
}
Also used : AxisFault(org.apache.axis2.AxisFault) SynapseException(org.apache.synapse.SynapseException) DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint)

Example 13 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class MediatorProperty method evaluate.

/**
 * @param synCtx
 */
public void evaluate(MessageContext synCtx) {
    String result;
    if (value != null) {
        result = value;
    } else if (expression != null) {
        result = expression.stringValueOf(synCtx);
    } else {
        throw new SynapseException("A value or expression must be specified");
    }
    if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
        synCtx.setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) {
        // Setting property into the  Axis2 Message Context
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        axis2MessageCtx.setProperty(name, result);
        MediatorPropertyUtils.handleSpecialProperties(name, result, axis2MessageCtx);
    } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope)) {
        // Setting property into the  Axis2 Message Context client options
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        axis2MessageCtx.getOptions().setProperty(name, result);
    } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) {
        // Setting Transport Headers
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
        if (headers != null && headers instanceof Map) {
            Map headersMap = (Map) headers;
            headersMap.put(name, result);
        }
        if (headers == null) {
            Map headersMap = new HashMap();
            headersMap.put(name, result);
            axis2MessageCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
        }
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) HashMap(java.util.HashMap) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Map(java.util.Map) HashMap(java.util.HashMap) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 14 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class PayloadHelper method setMapPayload.

public static void setMapPayload(SOAPEnvelope envelope, SimpleMap map) {
    if (map instanceof SimpleMapImpl) {
        SimpleMapImpl impl = (SimpleMapImpl) map;
        OMElement mapElt = impl.getOMElement(envelope.getOMFactory());
        if (mapElt == null) {
            log.debug("null map element returned");
            return;
        }
        setXMLPayload(envelope, mapElt);
    } else {
        throw new SynapseException("cannot handle any other instance of SimpleMap at this point TODO");
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) OMElement(org.apache.axiom.om.OMElement)

Example 15 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class JmsConsumer method cleanup.

public boolean cleanup() throws SynapseException {
    if (logger.isDebugEnabled()) {
        logger.debug(getId() + " cleaning up...");
    }
    try {
        store.cleanup(connection, session);
        return true;
    } catch (JMSException e) {
        throw new SynapseException("Error while connecting to store to close created connections. JMS provider " + "might not be accessible" + store.getName(), e);
    } finally {
        connection = null;
        session = null;
        consumer = null;
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) JMSException(javax.jms.JMSException)

Aggregations

SynapseException (org.apache.synapse.SynapseException)136 OMElement (org.apache.axiom.om.OMElement)31 OMAttribute (org.apache.axiom.om.OMAttribute)23 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)16 QName (javax.xml.namespace.QName)15 Iterator (java.util.Iterator)14 JaxenException (org.jaxen.JaxenException)14 XMLStreamException (javax.xml.stream.XMLStreamException)13 AxisFault (org.apache.axis2.AxisFault)13 Map (java.util.Map)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)8 OMNode (org.apache.axiom.om.OMNode)7 Mediator (org.apache.synapse.Mediator)7 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)7