This patch moves the validate mediator into extensions. This will allow
Synapse core to be independent of Xerces, and to avoid bundling it.
asankha
Index: etc/project.xml
===================================================================
--- etc/project.xml (revision 406952)
+++ etc/project.xml (working copy)
@@ -2,11 +2,8 @@
<project>
<pomVersion>3</pomVersion>
-
<id>Synapse-Incubating</id>
-
<name>Apache Synpase</name>
-
<currentVersion>M2-SNAPSHOT</currentVersion>
<organization>
@@ -23,15 +20,13 @@
framework based on Web services specifications.</description>
<url>http://ws.apache.org/synapse/</url>
- <issueTrackingUrl>
- http://issues.apache.org/jira/browse/Synapse</issueTrackingUrl>
+
<issueTrackingUrl>http://issues.apache.org/jira/browse/Synapse</issueTrackingUrl>
<siteAddress>ws.apache.org</siteAddress>
<siteDirectory>/synapse/</siteDirectory>
<distributionDirectory>/www/ws.apache.org/builds/</distributionDirectory>
<!--any mailing lists for the project -->
-
<mailingLists>
<mailingList>
<name>Synpase Developer List</name>
@@ -61,6 +56,15 @@
<artifactId>axis2</artifactId>
<version>${axis2.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>ws-commons</groupId>
+ <artifactId>axiom</artifactId>
+ <version>${axiom.version}</version>
+ <properties>
+ <module>false</module>
+ </properties>
+ </dependency>
<dependency>
<groupId>org.apache.ws.commons</groupId>
@@ -79,17 +83,7 @@
<module>false</module>
</properties>
</dependency>
- <dependency>
- <groupId>ws-commons</groupId>
- <artifactId>axiom</artifactId>
- <version>${axiom.version}</version>
- <properties>
- <module>false</module>
- </properties>
- </dependency>
-
-
<!-- external JARs -->
<dependency>
<groupId>commons-logging</groupId>
@@ -99,7 +93,6 @@
<module>true</module>
</properties>
</dependency>
-
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
@@ -149,6 +142,23 @@
</properties>
</dependency>
<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <properties>
+ <classloader>root</classloader>
+ </properties>
+ </dependency>
+ <dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ <version>${jaxen.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<version>${axis.wsdl4j.version}</version>
@@ -181,22 +191,6 @@
</properties>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <properties>
- <classloader>root</classloader>
- </properties>
- </dependency>
- <dependency>
- <groupId>jaxen</groupId>
- <artifactId>jaxen</artifactId>
- <version>${jaxen.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
- <dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.6.0</version>
@@ -204,25 +198,7 @@
<module>true</module>
</properties>
</dependency>
-
<dependency>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- <version>${xerces.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
- <dependency>
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- <version>${xml_apis.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
-
- <dependency>
<groupId>annogen</groupId>
<artifactId>annogen</artifactId>
<version>${annogen.version}</version>
@@ -230,7 +206,6 @@
<module>true</module>
</properties>
</dependency>
-
<dependency>
<groupId>backport-util-concurrent</groupId>
<artifactId>backport-util-concurrent</artifactId>
@@ -239,6 +214,7 @@
<module>true</module>
</properties>
</dependency>
+
</dependencies>
<!-- ================================= -->
@@ -253,9 +229,6 @@
<includes>
<include>**/*Test.java</include>
</includes>
- <!--<excludes>-->
- <!--<exclude>**/AddressingInProcessorTest.java</exclude>-->
- <!--</excludes>-->
<resources>
<resource>
<directory>conf</directory>
Index: modules/core/project.xml
===================================================================
--- modules/core/project.xml (revision 406952)
+++ modules/core/project.xml (working copy)
@@ -23,10 +23,6 @@
<includes>
<include>**/*Test.java</include>
</includes>
- <!--<excludes>
- <exclude>**/*ValidateMediatorTest.java</exclude>
- <exclude>**/*TransformMediatorTest.java</exclude>
- </excludes>-->
<resources>
<resource>
<directory>test-resources</directory>
@@ -42,7 +38,6 @@
</includes>
</resource>
</resources>
-
</build>
</project>
Index: modules/core/src/org/apache/synapse/config/xml/Constants.java
===================================================================
--- modules/core/src/org/apache/synapse/config/xml/Constants.java
(revision 407499)
+++ modules/core/src/org/apache/synapse/config/xml/Constants.java
(working copy)
@@ -18,19 +18,15 @@
import javax.xml.namespace.QName;
/**
- * <p/>
* Constants used in the XML processing
*/
public interface Constants {
- public static final QName DEFINITIONS_ELT = new QName("definitions");
- public static final QName SEQUENCE_ELT = new QName("sequence");
- public static final QName ENDPOINT_ELT = new QName("endpoint");
- public static final QName CONFIG_ELT = new QName("configuration");
- public static final QName PROPERTY_ELT = new QName("set-property");
+ public static final QName DEFINITIONS_ELT = new
QName(Constants.SYNAPSE_NAMESPACE, "definitions");
+ public static final QName SEQUENCE_ELT = new
QName(Constants.SYNAPSE_NAMESPACE, "sequence");
+ public static final QName ENDPOINT_ELT = new
QName(Constants.SYNAPSE_NAMESPACE, "endpoint");
+ public static final QName PROPERTY_ELT = new
QName(Constants.SYNAPSE_NAMESPACE, "set-property");
+ public static final QName RULES_ELT = new
QName(Constants.SYNAPSE_NAMESPACE, "rules");
- public static final QName RULES_ELT = new QName("rules");
-
public static final String SYNAPSE_NAMESPACE =
org.apache.synapse.Constants.SYNAPSE_NAMESPACE;
- public static final String SYNAPSE = "synapse";
- public static final String NULL_NAMESPACE = "";
+ public static final String NULL_NAMESPACE = "";
}
Index: modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
===================================================================
--- modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
(revision 407550)
+++ modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
(working copy)
@@ -56,7 +56,6 @@
HeaderMediatorFactory.class,
FaultMediatorFactory.class,
TransformMediatorFactory.class,
- ValidateMediatorFactory.class,
PropertyMediatorFactory.class,
SwitchMediatorFactory.class,
SwitchCaseMediatorFactory.class,
Index:
modules/core/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java
===================================================================
--- modules/core/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java
(revision 406952)
+++ modules/core/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java
(working copy)
@@ -1,89 +0,0 @@
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.synapse.config.xml;
-
-import org.apache.synapse.api.Mediator;
-import org.apache.synapse.mediators.builtin.ValidateMediator;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.Util;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jaxen.JaxenException;
-
-import javax.xml.namespace.QName;
-
-/**
- * Creates a validation mediator from the XML configuration
- *
- * <validate schema="url" [source="xpath"]>
- * <on-fail>
- * mediator+
- * </on-fail>
- * </validate>
- */
-public class ValidateMediatorFactory extends AbstractListMediatorFactory {
-
- private static final Log log =
LogFactory.getLog(TransformMediatorFactory.class);
- private static final QName VALIDATE_Q = new
QName(Constants.SYNAPSE_NAMESPACE, "validate");
-
- public Mediator createMediator(OMElement elem) {
-
- ValidateMediator validateMediator = new ValidateMediator();
- OMAttribute attSchema = elem.getAttribute(new
QName(Constants.NULL_NAMESPACE, "schema"));
- OMAttribute attSource = elem.getAttribute(new
QName(Constants.NULL_NAMESPACE, "source"));
-
- if (attSchema != null) {
- validateMediator.setSchemaUrl(attSchema.getAttributeValue());
- } else {
- String msg = "The 'schema' attribute is required for the validate
mediator configuration";
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- if (attSource != null) {
- try {
- AXIOMXPath xp = new AXIOMXPath(attSource.getAttributeValue());
- validateMediator.setSource(xp);
- Util.addNameSpaces(xp, elem, log);
-
- } catch (JaxenException e) {
- String msg = "Invalid XPath expression specified for attribute
'source'";
- log.error(msg);
- throw new SynapseException(msg, e);
- }
- }
-
- OMElement onFail = elem.getFirstElement();
- if (new QName(Constants.SYNAPSE_NAMESPACE,
"on-fail").equals(onFail.getQName()) &&
- onFail.getChildElements().hasNext()) {
- super.addChildren(onFail, validateMediator);
-
- } else {
- String msg = "A non-empty on-fail element is required for the
validate mediator";
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- return validateMediator;
- }
-
- public QName getTagQName() {
- return VALIDATE_Q;
- }
-}
Index:
modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java
===================================================================
--- modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java
(revision 407499)
+++ modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java
(working copy)
@@ -1,248 +0,0 @@
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.synapse.mediators.builtin;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.mediators.AbstractListMediator;
-import org.jaxen.JaxenException;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-import javax.xml.XMLConstants;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.List;
-import java.util.StringTokenizer;
-
-/**
- * Validate a message or an element against a schema
- */
-public class ValidateMediator extends AbstractListMediator {
-
- private static final Log log = LogFactory.getLog(ValidateMediator.class);
-
- /** A space or comma delimitered list of schemas to validate the source
element against */
- private String schemaUrl = null;
- /**
- * An XPath expression to be evaluated against the message to find the
element to be validated.
- * If this is not specified, the validation will occur against the first
child element of the SOAP body
- */
- private AXIOMXPath source = null;
-
- /**
- * Schema full checking feature id
(http://apache.org/xml/features/validation/schema-full-checking).
- */
- private static final String SCHEMA_FULL_CHECKING_FEATURE_ID =
"http://apache.org/xml/features/validation/schema-full-checking";
-
- /**
- * Honour all schema locations feature id
(http://apache.org/xml/features/honour-all-schemaLocations).
- */
- private static final String HONOUR_ALL_SCHEMA_LOCATIONS_ID =
"http://apache.org/xml/features/honour-all-schemaLocations";
-
- /**
- * Default schema language (http://www.w3.org/2001/XMLSchema).
- */
- private static final String DEFAULT_SCHEMA_LANGUAGE =
"http://www.w3.org/2001/XMLSchema";
-
-
- public String getSchemaUrl() {
- return schemaUrl;
- }
-
- public void setSchemaUrl(String schemaUrl) {
- this.schemaUrl = schemaUrl;
- }
-
- public AXIOMXPath getSource() {
- return source;
- }
-
- public void setSource(AXIOMXPath source) {
- this.source = source;
- }
-
- /**
- * Return the node to be validated. If a source XPath is not specified,
this will
- * default to the first child of the SOAP body
- * @param synCtx the message context
- * @return the OMNode against which validation should be performed
- */
- private OMNode getValidateSource(MessageContext synCtx) {
-
- AXIOMXPath sourceXPath = source;
- // do not change the source XPath if not specified, as it is shared..
- // and will cause confusion to concurrent messages and erroneous
results
-
- if (sourceXPath == null) {
- log.debug("validation source was not specified.. defaulting to
SOAP Body");
- try {
- sourceXPath = new AXIOMXPath("//SOAP-ENV:Body/child::*");
- sourceXPath.addNamespace("SOAP-ENV", synCtx.isSOAP11() ?
- SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI :
SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
- } catch (JaxenException e) {
- // this should not cause a runtime exception!
- }
- }
-
- try {
- Object o = sourceXPath.evaluate(synCtx.getEnvelope());
- if (o instanceof OMNode) {
- return (OMNode) o;
- } else if (o instanceof List && !((List) o).isEmpty()) {
- return (OMNode) ((List) o).get(0); // Always fetches *only*
the first
- } else {
- String msg = "The evaluation of the XPath expression " +
source + " must result in an OMNode";
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- } catch (JaxenException e) {
- String msg = "Error evaluating XPath " + source + " on message";
- log.error(msg);
- throw new SynapseException(msg, e);
- }
- }
-
- public boolean mediate(MessageContext synCtx) {
-
- ByteArrayInputStream baisFromSource = null;
-
- try {
- // create a byte array output stream and serialize the source node
into it
- ByteArrayOutputStream baosForSource = new ByteArrayOutputStream();
- XMLStreamWriter xsWriterForSource =
XMLOutputFactory.newInstance().createXMLStreamWriter(baosForSource);
-
- // serialize the validation target and get an input stream into it
- OMNode sourceNode = getValidateSource(synCtx);
- sourceNode.serialize(xsWriterForSource);
- baisFromSource = new
ByteArrayInputStream(baosForSource.toByteArray());
-
- } catch (Exception e) {
- String msg = "Error accessing source element for validation : " +
source;
- log.error(msg);
- throw new SynapseException(msg, e);
- }
-
- try {
- // this is our custom validation handler
- SynapseValidator handler = new SynapseValidator();
-
- // Create SchemaFactory and configure
- SchemaFactory factory =
SchemaFactory.newInstance(DEFAULT_SCHEMA_LANGUAGE);
- factory.setErrorHandler(handler);
- factory.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
- factory.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, true);
-
- // Build Schema from schemaUrl
- Schema schema = null;
- if (schemaUrl != null) {
- StringTokenizer st = new StringTokenizer(schemaUrl, " ,");
- int sourceCount = st.countTokens();
-
- if (sourceCount == 0) {
- log.debug("Schemas have not been specified..");
- schema = factory.newSchema();
- } else {
- StreamSource[] sources = new StreamSource[sourceCount];
- for (int j = 0; j < sourceCount; ++j) {
- sources[j] = new StreamSource(st.nextToken());
- }
- schema = factory.newSchema(sources);
- }
- } else {
- log.debug("Schemas have not been specified..");
- schema = factory.newSchema();
- }
-
- // Setup validator and input source.
- Validator validator = schema.newValidator();
- validator.setErrorHandler(handler);
- validator.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
- validator.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, true);
-
- XMLReader reader = XMLReaderFactory.createXMLReader();
- SAXSource source = new SAXSource(reader, new
InputSource(baisFromSource));
- validator.validate(source);
-
- if (handler.isValidationError()) {
- log.debug("Validation of element : " + source + " failed
against : " + schemaUrl +
- " Message : " +
handler.getSaxParseException().getMessage() + " Executing 'on-fail' sequence");
- log.debug("Failed message envelope : " + synCtx.getEnvelope());
- // super.mediate() invokes the "on-fail" sequence of mediators
- return super.mediate(synCtx);
- }
-
- }
- catch (Exception e) {
- String msg = "Error validating " + source + " against schema : " +
schemaUrl + " : " + e.getMessage();
- log.error(msg);
- throw new SynapseException(msg, e);
- }
-
- return true;
- }
-
- /**
- * This class handles validation errors to be used for error reporting
- */
- private class SynapseValidator extends DefaultHandler {
-
- private boolean validationError = false;
- private SAXParseException saxParseException = null;
-
- public void error(SAXParseException exception) throws SAXException {
- validationError = true;
- saxParseException = exception;
- }
-
- public void fatalError(SAXParseException exception) throws
SAXException {
- validationError = true;
- saxParseException = exception;
- }
-
- public void warning(SAXParseException exception) throws SAXException {
- }
-
- public boolean isValidationError() {
- return validationError;
- }
-
- public SAXParseException getSaxParseException() {
- return saxParseException;
- }
- }
-
-}
Index:
modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
===================================================================
---
modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
(revision 406952)
+++
modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
(working copy)
@@ -1,209 +0,0 @@
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.synapse.mediators.builtin;
-
-import junit.framework.TestCase;
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.mediators.TestMediateHandler;
-import org.apache.synapse.mediators.TestMediator;
-import org.apache.synapse.mediators.TestUtils;
-
-public class ValidateMediatorTest extends TestCase {
-
- private static final String VALID_ENVELOPE_TWO_SCHEMAS =
- "<Outer xmlns=\"http://www.apache-synapse.org/test2\">" +
- "<m0:CheckPriceRequest
xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
- "<m0:Code>String</m0:Code>\n" +
- "</m0:CheckPriceRequest>\n" +
- "<m1:CheckPriceRequest2
xmlns:m1=\"http://www.apache-synapse.org/test2\">\n" +
- "<m1:Code2>String</m1:Code2>\n" +
- "</m1:CheckPriceRequest2>\n" +
- "</Outer>";
-
- private static final String INVALID_ENVELOPE_TWO_SCHEMAS =
- "<Outer xmlns=\"http://www.apache-synapse.org/test2\">" +
- "<m1:CheckPriceRequest2
xmlns:m1=\"http://www.apache-synapse.org/test2\">\n" +
- "<m1:Code2>String</m1:Code2>\n" +
- "</m1:CheckPriceRequest2>\n" +
- "<m0:CheckPriceRequest
xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
- "<m0:Code>String</m0:Code>\n" +
- "</m0:CheckPriceRequest>\n" +
- "</Outer>";
-
- private static final String VALID_ENVELOPE =
- "<m0:CheckPriceRequest
xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
- "\t<m0:Code>String</m0:Code>\n" +
- "</m0:CheckPriceRequest>\n";
-
- private static final String IN_VALID_ENVELOPE =
- "<m0:CheckPriceRequest
xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
- "\t<m0:Codes>String</m0:Codes>\n" +
- "</m0:CheckPriceRequest>\n";
-
- private static final String VALID_ENVELOPE_NO_NS =
- "<CheckPriceRequest
xmlns=\"http://www.apache-synapse.org/test\">\n" +
- "\t<Code>String</Code>\n" +
- "</CheckPriceRequest>\n";
-
- private static final String IN_VALID_ENVELOPE_NO_NS =
- "<CheckPriceRequest
xmlns=\"http://www.apache-synapse.org/test\">\n" +
- "\t<Code>String</Code>\n" +
- "</CheckPriceRequest>\n";
-
- private boolean onFailInvoked = false;
- private TestMediator testMediator = null;
-
- public void setUp() {
- testMediator = new TestMediator();
- testMediator.setHandler(
- new TestMediateHandler() {
- public void handle(MessageContext synCtx) {
- setOnFailInvoked(true);
- }
- });
- }
-
- public void setOnFailInvoked(boolean onFailInvoked) {
- this.onFailInvoked = onFailInvoked;
- }
-
- public void testValidateMedaitorValidCase() throws Exception {
- setOnFailInvoked(false);
-
- // create a validate mediator
- ValidateMediator validate = new ValidateMediator();
-
- // set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd");
- AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
- source.addNamespace("m0", "http://www.apache-synapse.org/test");
- validate.setSource(source);
-
- // set dummy mediator to be called on fail
- validate.addChild(testMediator);
-
- // test validate mediator, with static enveope
- validate.mediate(TestUtils.getTestContext(VALID_ENVELOPE));
-
- assertTrue(!onFailInvoked);
- }
-
- public void testValidateMedaitorValidCaseTwoSchemas() throws Exception {
- setOnFailInvoked(false);
-
- // create a validate mediator
- ValidateMediator validate = new ValidateMediator();
-
- // set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd
test-resources/misc/validate2.xsd");
- AXIOMXPath source = new AXIOMXPath("//m0:Outer");
- source.addNamespace("m0", "http://www.apache-synapse.org/test2");
- validate.setSource(source);
-
- // set dummy mediator to be called on fail
- validate.addChild(testMediator);
-
- // test validate mediator, with static enveope
- validate.mediate(TestUtils.getTestContext(VALID_ENVELOPE_TWO_SCHEMAS));
-
- assertTrue(!onFailInvoked);
- }
-
- public void testValidateMedaitorInvalidCaseTwoSchemas() throws Exception {
- setOnFailInvoked(false);
-
- // create a validate mediator
- ValidateMediator validate = new ValidateMediator();
-
- // set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd
test-resources/misc/validate2.xsd");
- AXIOMXPath source = new AXIOMXPath("//m0:Outer");
- source.addNamespace("m0", "http://www.apache-synapse.org/test2");
- validate.setSource(source);
-
- // set dummy mediator to be called on fail
- validate.addChild(testMediator);
-
- // test validate mediator, with static enveope
-
validate.mediate(TestUtils.getTestContext(INVALID_ENVELOPE_TWO_SCHEMAS));
-
- assertTrue(onFailInvoked);
- }
-
- public void testValidateMedaitorInvalidCase() throws Exception {
- setOnFailInvoked(false);
-
- // create a validate mediator
- ValidateMediator validate = new ValidateMediator();
-
- // set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("modules/core/test-resources/misc/validate.xsd");
- AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
- source.addNamespace("m0", "http://www.apache-synapse.org/test");
- validate.setSource(source);
-
- // set dummy mediator to be called on fail
- validate.addChild(testMediator);
-
- // test validate mediator, with static enveope
- validate.mediate(TestUtils.getTestContext(IN_VALID_ENVELOPE));
-
- assertTrue(onFailInvoked);
- }
-
- public void testValidateMedaitorValidCaseNoNS() throws Exception {
- setOnFailInvoked(false);
-
- // create a validate mediator
- ValidateMediator validate = new ValidateMediator();
-
- // set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd");
- AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
- source.addNamespace("m0", "http://www.apache-synapse.org/test");
- validate.setSource(source);
-
- // set dummy mediator to be called on fail
- validate.addChild(testMediator);
-
- // test validate mediator, with static enveope
- validate.mediate(TestUtils.getTestContext(VALID_ENVELOPE_NO_NS));
-
- assertTrue(!onFailInvoked);
- }
-
- public void testValidateMedaitorInvalidCaseNoNS() throws Exception {
- setOnFailInvoked(false);
-
- // create a validate mediator
- ValidateMediator validate = new ValidateMediator();
-
- // set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("modules/core/test-resources/misc/validate.xsd");
- AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
- source.addNamespace("m0", "http://www.apache-synapse.org/test");
- validate.setSource(source);
-
- // set dummy mediator to be called on fail
- validate.addChild(testMediator);
-
- // test validate mediator, with static enveope
- validate.mediate(TestUtils.getTestContext(IN_VALID_ENVELOPE_NO_NS));
-
- assertTrue(onFailInvoked);
- }
-}
Index: modules/extensions/project.xml
===================================================================
--- modules/extensions/project.xml (revision 407550)
+++ modules/extensions/project.xml (working copy)
@@ -27,6 +27,25 @@
<module>true</module>
</properties>
</dependency>
+
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>${xerces.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>${xml_apis.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
</dependencies>
<build>
@@ -37,9 +56,7 @@
<includes>
<include>**/*Test.java</include>
</includes>
- <!--<excludes>-->
- <!--<exclude>**/*Test.java</exclude>-->
- <!--</excludes>-->
+
<resources>
<resource>
<directory>src</directory>
Index:
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
===================================================================
---
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
(revision 407499)
+++
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
(working copy)
@@ -1 +1,2 @@
-org.apache.synapse.config.xml.SpringMediatorFactory
\ No newline at end of file
+org.apache.synapse.config.xml.SpringMediatorFactory
+org.apache.synapse.config.xml.ValidateMediatorFactory
\ No newline at end of file
Index:
modules/extensions/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java
===================================================================
---
modules/extensions/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java
(revision 407499)
+++
modules/extensions/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java
(working copy)
@@ -15,32 +15,32 @@
*/
package org.apache.synapse.config.xml;
-import org.apache.synapse.api.Mediator;
-import org.apache.synapse.mediators.builtin.ValidateMediator;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.Util;
+import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.ValidateMediator;
import org.jaxen.JaxenException;
import javax.xml.namespace.QName;
/**
* Creates a validation mediator from the XML configuration
- *
+ * <p/>
* <validate schema="url" [source="xpath"]>
- * <on-fail>
- * mediator+
- * </on-fail>
+ * <on-fail>
+ * mediator+
+ * </on-fail>
* </validate>
*/
public class ValidateMediatorFactory extends AbstractListMediatorFactory {
private static final Log log =
LogFactory.getLog(TransformMediatorFactory.class);
- private static final QName VALIDATE_Q = new
QName(Constants.SYNAPSE_NAMESPACE, "validate");
+ private static final QName VALIDATE_Q = new
QName(Constants.SYNAPSE_NAMESPACE, "validate");
public Mediator createMediator(OMElement elem) {
Index: modules/extensions/src/org/apache/synapse/mediators/ValidateMediator.java
===================================================================
--- modules/extensions/src/org/apache/synapse/mediators/ValidateMediator.java
(revision 405612)
+++ modules/extensions/src/org/apache/synapse/mediators/ValidateMediator.java
(working copy)
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.synapse.mediators.builtin;
+package org.apache.synapse.mediators;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
@@ -139,6 +139,7 @@
public boolean mediate(MessageContext synCtx) {
ByteArrayInputStream baisFromSource = null;
+ OMNode sourceNode = null;
try {
// create a byte array output stream and serialize the source node
into it
@@ -146,7 +147,7 @@
XMLStreamWriter xsWriterForSource =
XMLOutputFactory.newInstance().createXMLStreamWriter(baosForSource);
// serialize the validation target and get an input stream into it
- OMNode sourceNode = getValidateSource(synCtx);
+ sourceNode = getValidateSource(synCtx);
sourceNode.serialize(xsWriterForSource);
baisFromSource = new
ByteArrayInputStream(baosForSource.toByteArray());
@@ -198,7 +199,7 @@
validator.validate(source);
if (handler.isValidationError()) {
- log.debug("Validation of element : " + source + " failed
against : " + schemaUrl +
+ log.debug("Validation of element : " + sourceNode + " failed
against : " + schemaUrl +
" Message : " +
handler.getSaxParseException().getMessage() + " Executing 'on-fail' sequence");
log.debug("Failed message envelope : " + synCtx.getEnvelope());
// super.mediate() invokes the "on-fail" sequence of mediators
Index: modules/extensions/test/org/apache/synapse/spring/SpringTestBean.java
===================================================================
--- modules/extensions/test/org/apache/synapse/spring/SpringTestBean.java
(revision 407550)
+++ modules/extensions/test/org/apache/synapse/spring/SpringTestBean.java
(working copy)
@@ -17,6 +17,7 @@
import org.apache.synapse.api.Mediator;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.TestMediateHandler;
/**
* This is a very simple Spring bean, that has one int property, and a
Index: modules/extensions/test/org/apache/synapse/spring/TestMediateHandler.java
===================================================================
--- modules/extensions/test/org/apache/synapse/spring/TestMediateHandler.java
(revision 407499)
+++ modules/extensions/test/org/apache/synapse/spring/TestMediateHandler.java
(working copy)
@@ -1,23 +0,0 @@
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.synapse.spring;
-
-import org.apache.synapse.MessageContext;
-
-public interface TestMediateHandler {
-
- public void handle(MessageContext synCtx);
-}
Index:
modules/extensions/test/org/apache/synapse/spring/TestMediateHandlerImpl.java
===================================================================
---
modules/extensions/test/org/apache/synapse/spring/TestMediateHandlerImpl.java
(revision 407499)
+++
modules/extensions/test/org/apache/synapse/spring/TestMediateHandlerImpl.java
(working copy)
@@ -16,6 +16,7 @@
package org.apache.synapse.spring;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.TestMediateHandler;
public class TestMediateHandlerImpl implements TestMediateHandler {
Index: modules/extensions/test/org/apache/synapse/TestMediateHandler.java
===================================================================
--- modules/extensions/test/org/apache/synapse/TestMediateHandler.java
(revision 405612)
+++ modules/extensions/test/org/apache/synapse/TestMediateHandler.java
(working copy)
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.synapse.spring;
+package org.apache.synapse;
import org.apache.synapse.MessageContext;
Index: modules/extensions/test/org/apache/synapse/TestMediator.java
===================================================================
--- modules/extensions/test/org/apache/synapse/TestMediator.java
(revision 0)
+++ modules/extensions/test/org/apache/synapse/TestMediator.java
(revision 0)
@@ -0,0 +1,49 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.TestMediateHandler;
+
+/**
+ * Test mediator class.
+ */
+public class TestMediator implements Mediator {
+
+ private org.apache.synapse.TestMediateHandler handlerTest = null;
+
+ public TestMediator() {
+ }
+
+ public boolean mediate(MessageContext synCtx) {
+ if (handlerTest != null) {
+ handlerTest.handle(synCtx);
+ }
+ return true;
+ }
+
+ public String getType() {
+ return null;
+ }
+
+ public TestMediateHandler getHandler() {
+ return handlerTest;
+ }
+
+ public void setHandler(TestMediateHandler handlerTest) {
+ this.handlerTest = handlerTest;
+ }
+}
Index: modules/extensions/test/org/apache/synapse/ValidateMediatorTest.java
===================================================================
--- modules/extensions/test/org/apache/synapse/ValidateMediatorTest.java
(revision 405612)
+++ modules/extensions/test/org/apache/synapse/ValidateMediatorTest.java
(working copy)
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.synapse.mediators.builtin;
+package org.apache.synapse;
import junit.framework.TestCase;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.synapse.MessageContext;
-import org.apache.synapse.mediators.TestMediateHandler;
-import org.apache.synapse.mediators.TestMediator;
-import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.TestMediateHandler;
+import org.apache.synapse.TestMediator;
+import org.apache.synapse.TestUtils;
+import org.apache.synapse.mediators.ValidateMediator;
public class ValidateMediatorTest extends TestCase {
@@ -56,12 +57,12 @@
private static final String VALID_ENVELOPE_NO_NS =
"<CheckPriceRequest
xmlns=\"http://www.apache-synapse.org/test\">\n" +
- "\t<Code>String</Code>\n" +
+ "<Code>String</Code>\n" +
"</CheckPriceRequest>\n";
private static final String IN_VALID_ENVELOPE_NO_NS =
"<CheckPriceRequest
xmlns=\"http://www.apache-synapse.org/test\">\n" +
- "\t<Code>String</Code>\n" +
+ "<Codes>String</Codes>\n" +
"</CheckPriceRequest>\n";
private boolean onFailInvoked = false;
@@ -88,7 +89,7 @@
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd");
+ validate.setSchemaUrl("../core/test-resources/misc/validate.xsd");
AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
source.addNamespace("m0", "http://www.apache-synapse.org/test");
validate.setSource(source);
@@ -109,7 +110,7 @@
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd
test-resources/misc/validate2.xsd");
+ validate.setSchemaUrl("../core/test-resources/misc/validate.xsd
../core/test-resources/misc/validate2.xsd");
AXIOMXPath source = new AXIOMXPath("//m0:Outer");
source.addNamespace("m0", "http://www.apache-synapse.org/test2");
validate.setSource(source);
@@ -130,7 +131,7 @@
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd
test-resources/misc/validate2.xsd");
+ validate.setSchemaUrl("../core/test-resources/misc/validate.xsd
../core/test-resources/misc/validate2.xsd");
AXIOMXPath source = new AXIOMXPath("//m0:Outer");
source.addNamespace("m0", "http://www.apache-synapse.org/test2");
validate.setSource(source);
@@ -151,7 +152,7 @@
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("modules/core/test-resources/misc/validate.xsd");
+ validate.setSchemaUrl("../core/test-resources/misc/validate.xsd");
AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
source.addNamespace("m0", "http://www.apache-synapse.org/test");
validate.setSource(source);
@@ -172,7 +173,7 @@
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("test-resources/misc/validate.xsd");
+ validate.setSchemaUrl("../core/test-resources/misc/validate.xsd");
AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
source.addNamespace("m0", "http://www.apache-synapse.org/test");
validate.setSource(source);
@@ -193,7 +194,7 @@
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
- validate.setSchemaUrl("modules/core/test-resources/misc/validate.xsd");
+ validate.setSchemaUrl("../core/test-resources/misc/validate.xsd");
AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
source.addNamespace("m0", "http://www.apache-synapse.org/test");
validate.setSource(source);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]