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());
}
}
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) {
}
}
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) {
}
}
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);
}
}
}
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);
}
}
}
Aggregations