Search in sources :

Example 46 with SynapseException

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

the class TransactionMediatorSerializationTest method testCreatingMediatorWithInvalidOMElement.

/**
 * Test for creation of transaction mediator with an invalid OMElement
 *
 * @throws Exception
 */
public void testCreatingMediatorWithInvalidOMElement() throws Exception {
    try {
        transactionMediatorFactory.createSpecificMediator(createOMElement("<transaction xmlns=\"http://ws.apache.org/ns/synapse\" />"), new Properties());
        fail("Test for creating transaction mediator with an invalid OMElement fails.");
    } catch (SynapseException e) {
        assertEquals("The 'action' attribute is required for Transaction mediator definition", e.getMessage());
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) Properties(java.util.Properties)

Example 47 with SynapseException

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

the class HeaderMediatorConfigurationTest method testNamespaceUnqualifiedScenarioTwo.

public void testNamespaceUnqualifiedScenarioTwo() {
    try {
        String inputXml = "<header xmlns=\"http://ws.apache.org/ns/synapse\" name=\"m:MyHeader\" value=\"MyValue\"/>";
        HeaderMediatorFactory fac = new HeaderMediatorFactory();
        fac.createMediator(AXIOMUtil.stringToOM(inputXml), new Properties());
        fail("HeaderMediator created with namespace unqualified SOAP header");
    } catch (XMLStreamException e) {
        fail("Error while parsing header mediator configuration");
    } catch (SynapseException ignored) {
    }
    try {
        String inputXml = "<header xmlns=\"http://ws.apache.org/ns/synapse\" name=\"m:MyHeader\" action=\"remove\"/>";
        HeaderMediatorFactory fac = new HeaderMediatorFactory();
        fac.createMediator(AXIOMUtil.stringToOM(inputXml), new Properties());
        fail("HeaderMediator created with namespace unqualified SOAP header");
    } catch (XMLStreamException e) {
        fail("Error while parsing header mediator configuration");
    } catch (SynapseException ignored) {
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) Properties(java.util.Properties)

Example 48 with SynapseException

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

the class HeaderMediatorConfigurationTest method testNamespaceUnqualifiedScenarioOne.

public void testNamespaceUnqualifiedScenarioOne() {
    try {
        String inputXml = "<header xmlns=\"http://ws.apache.org/ns/synapse\" name=\"MyHeader\" value=\"MyValue\"/>";
        HeaderMediatorFactory fac = new HeaderMediatorFactory();
        fac.createMediator(AXIOMUtil.stringToOM(inputXml), new Properties());
        fail("HeaderMediator created with namespace unqualified SOAP header");
    } catch (XMLStreamException e) {
        fail("Error while parsing header mediator configuration");
    } catch (SynapseException ignored) {
    }
    try {
        String inputXml = "<header xmlns=\"http://ws.apache.org/ns/synapse\" name=\"MyHeader\" action=\"remove\"/>";
        HeaderMediatorFactory fac = new HeaderMediatorFactory();
        fac.createMediator(AXIOMUtil.stringToOM(inputXml), new Properties());
        fail("HeaderMediator created with namespace unqualified SOAP header");
    } catch (XMLStreamException e) {
        fail("Error while parsing header mediator configuration");
    } catch (SynapseException ignored) {
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) Properties(java.util.Properties)

Example 49 with SynapseException

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

the class ResourceMap method resolve.

/**
 * Resolve a resource for a given location.
 *
 * @param synCfg the Synapse configuration (used to access the registry)
 * @param location the location of of the resource at is appears in the referencing document
 * @return an <code>InputSource</code> object for the referenced resource
 */
public InputSource resolve(SynapseConfiguration synCfg, String location) {
    String key = resources.get(location);
    if (key == null) {
        if (log.isDebugEnabled()) {
            log.debug("No resource mapping is defined for location '" + location + "'");
        }
        return null;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Resolving location '" + location + "' to registry item '" + key + "'");
        }
        synCfg.getEntryDefinition(key);
        Object keyObject = synCfg.getEntry(key);
        if (keyObject instanceof OMElement) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ((OMElement) keyObject).serialize(baos);
            } catch (XMLStreamException ex) {
                String msg = "Unable to serialize registry item '" + key + "' for location '" + location + "'";
                log.error(msg);
                throw new SynapseException(msg, ex);
            }
            InputSource inputSource = new InputSource(new ByteArrayInputStream(baos.toByteArray()));
            // We must set a system ID because Axis2 relies on this (see SYNAPSE-362). Compose a
            // valid URI with the registry key so that it uniquely identifies the resource.
            inputSource.setSystemId("synapse-reg:///" + key);
            return inputSource;
        } else {
            String msg = "Registry item '" + key + "' for location '" + location + "' is not an OMElement";
            log.error(msg);
            throw new SynapseException(msg);
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 50 with SynapseException

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

the class AbstractListMediatorFactory method addChildren.

protected static void addChildren(OMElement el, ListMediator m, Properties properties) {
    Iterator it = el.getChildren();
    while (it.hasNext()) {
        OMNode child = (OMNode) it.next();
        if (child instanceof OMElement) {
            if (!DESCRIPTION_Q.equals(((OMElement) child).getQName())) {
                // neglect the description tag
                Mediator med = MediatorFactoryFinder.getInstance().getMediator((OMElement) child, properties);
                if (med != null) {
                    m.addChild(med);
                } else {
                    String msg = "Unknown mediator : " + ((OMElement) child).getLocalName();
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            }
        } else if (child instanceof OMComment) {
            CommentMediator commendMediator = new CommentMediator();
            commendMediator.setCommentText(((OMComment) child).getValue());
            m.addChild(commendMediator);
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) SynapseException(org.apache.synapse.SynapseException) OMComment(org.apache.axiom.om.OMComment) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) ListMediator(org.apache.synapse.mediators.ListMediator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator)

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