synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ind...@apache.org
Subject svn commit: r555497 - in /webservices/synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/config/xml/ core/src/main/java/org/apache/synapse/mediators/builtin/ core/src/main/java/org/apache/synapse/mediators/transform/ extensions/src/test/...
Date Thu, 12 Jul 2007 05:39:39 GMT
Author: indika
Date: Wed Jul 11 22:39:37 2007
New Revision: 555497

URL: http://svn.apache.org/viewvc?view=rev&rev=555497
Log:
change the validation mediator configuration language  by replacing property with feature.
update theb test cases 
fixed minor thread issue

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
    webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java
    webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorFactory.java?view=diff&rev=555497&r1=555496&r2=555497
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorFactory.java
Wed Jul 11 22:39:37 2007
@@ -25,12 +25,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.config.xml.OMElementUtils;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.mediators.builtin.ValidateMediator;
-import org.apache.synapse.config.xml.AbstractListMediatorFactory;
-import org.apache.synapse.config.xml.Constants;
-import org.apache.synapse.config.xml.MediatorPropertyFactory;
 import org.jaxen.JaxenException;
 
 import javax.xml.namespace.QName;
@@ -58,6 +54,8 @@
     private static final QName SCHEMA_Q   = new QName(Constants.SYNAPSE_NAMESPACE, "schema");
     private static final QName KEY_Q      = new QName(Constants.NULL_NAMESPACE, "key");
     private static final QName SOURCE_Q   = new QName(Constants.NULL_NAMESPACE, "source");
+    public static final QName ATT_NAME_Q  = new QName(Constants.NULL_NAMESPACE, "name");
+    public static final QName ATT_VALUE_Q = new QName(Constants.NULL_NAMESPACE, "value");
 
     public Mediator createMediator(OMElement elem) {
 
@@ -103,9 +101,9 @@
 
         // process on-fail
         OMElement onFail = null;
-        Iterator iter = elem.getChildrenWithName(ON_FAIL_Q);
-        if (iter.hasNext()) {
-            onFail = (OMElement)iter.next();
+        Iterator iterator = elem.getChildrenWithName(ON_FAIL_Q);
+        if (iterator.hasNext()) {
+            onFail = (OMElement)iterator.next();
         }
 
         if (onFail != null && onFail.getChildElements().hasNext()) {
@@ -118,11 +116,32 @@
         // after successfully creating the mediator
         // set its common attributes such as tracing etc
         initMediator(validateMediator,elem);
-
-        // process properties
-        validateMediator.addAllProperties(
-            MediatorPropertyFactory.getMediatorProperties(elem));
-
+        // set the features
+        Iterator iter = elem.getChildrenWithName(new QName(Constants.SYNAPSE_NAMESPACE, "feature"));
+        while (iter.hasNext()) {
+            OMElement featureElem = (OMElement) iter.next();
+            OMAttribute attName = featureElem.getAttribute(ATT_NAME_Q);
+            OMAttribute attValue = featureElem.getAttribute(ATT_VALUE_Q);
+            if (attName != null && attValue != null) {
+                String name = attName.getAttributeValue();
+                String value = attValue.getAttributeValue();
+                if (name != null && value != null) {
+                    if ("true".equals(value.trim())) {
+                        validateMediator.addFeature(name.trim(),
+                                true);
+                    } else if ("false".equals(value.trim())) {
+                        validateMediator.addFeature(name.trim(),
+                                false);
+                    } else {
+                        handleException("The feature must have value true or false");
+                    }
+                } else {
+                    handleException("The valid values for both of the name and value are
need");
+                }
+            } else {
+                handleException("Both of the name and value attribute are required for a
feature");
+            }
+        }
         return validateMediator;
     }
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorSerializer.java?view=diff&rev=555497&r1=555496&r2=555497
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorSerializer.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValidateMediatorSerializer.java
Wed Jul 11 22:39:37 2007
@@ -25,10 +25,10 @@
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.mediators.builtin.ValidateMediator;
-import org.apache.synapse.config.xml.MediatorSerializer;
-import org.apache.synapse.config.xml.AbstractListMediatorSerializer;
+import org.apache.synapse.mediators.MediatorProperty;
 
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * <validate [source="xpath"]>
@@ -52,25 +52,40 @@
 
         ValidateMediator mediator = (ValidateMediator) m;
         OMElement validate = fac.createOMElement("validate", synNS);
-        finalizeSerialization(validate,mediator);
+        finalizeSerialization(validate, mediator);
 
         if (mediator.getSource() != null) {
             validate.addAttribute(fac.createOMAttribute(
-                "source", nullNS, mediator.getSource().toString()));
+                    "source", nullNS, mediator.getSource().toString()));
             serializeNamespaces(validate, mediator.getSource());
         }
 
-        Iterator iter = mediator.getSchemaKeys().iterator();
-        while (iter.hasNext()) {
-            String key = (String) iter.next();
+        Iterator iterator = mediator.getSchemaKeys().iterator();
+        while (iterator.hasNext()) {
+            String key = (String) iterator.next();
             OMElement schema = fac.createOMElement("schema", synNS, validate);
             schema.addAttribute(fac.createOMAttribute("key", nullNS, key));
         }
 
-        serializeProperties(validate, mediator.getProperties());
-
+        List features = mediator.getFeatures();
+        if (!features.isEmpty()) {
+            for (Iterator iter = features.iterator(); iter.hasNext();) {
+                MediatorProperty mp = (MediatorProperty) iter.next();
+                OMElement feature = fac.createOMElement("feature", synNS, validate);
+                if (mp.getName() != null) {
+                    feature.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
+                } else {
+                    handleException("The Feature name is missing");
+                }
+                if (mp.getValue() != null) {
+                    feature.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));
+                } else {
+                    handleException("The Feature value is missing");
+                }
+            }
+        }
         OMElement onFail = fac.createOMElement("on-fail", synNS, validate);
-        serializeChildren(onFail, mediator.getList());        
+        serializeChildren(onFail, mediator.getList());
 
         if (parent != null) {
             parent.addChild(validate);

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java?view=diff&rev=555497&r1=555496&r2=555497
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
Wed Jul 11 22:39:37 2007
@@ -50,7 +50,7 @@
     private static final Log log = LogFactory.getLog(XSLTMediatorFactory.class);
     private static final QName TAG_NAME    = new QName(Constants.SYNAPSE_NAMESPACE, "xslt");
     public static final QName ATT_NAME_Q  = new QName(Constants.NULL_NAMESPACE, "name");
-       public static final QName ATT_VALUE_Q = new QName(Constants.NULL_NAMESPACE, "value");
+    public static final QName ATT_VALUE_Q = new QName(Constants.NULL_NAMESPACE, "value");
 
 
     public QName getTagQName() {

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java?view=diff&rev=555497&r1=555496&r2=555497
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java
Wed Jul 11 22:39:37 2007
@@ -77,10 +77,9 @@
     private AXIOMXPath source = null;
 
     /**
-     * A Map containing properties for the validate mediator - such as
-     * features to be passed to the actual validator (Xerces)
+     * A Map containing features to be passed to the actual validator (Xerces)
      */
-    private List properties = new ArrayList();
+    private List explicityFeatures = new ArrayList();
 
     /**
      * This is the actual schema instance used to create a new schema
@@ -93,6 +92,11 @@
      */
     private final Object validatorLock = new Object();
 
+    /**
+     * The SchemaFactory for whcih used to create new schema instance
+     */
+    private  SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+
     private static final String DEFAULT_XPATH = "//s11:Envelope/s11:Body/child::*[position()=1]
| " +
         "//s12:Envelope/s12:Body/child::*[position()=1]";
 
@@ -107,31 +111,6 @@
         }
     }
 
-    /**
-     * Return the OMNode to be validated. If a source XPath is not specified, this will
-     * default to the first child of the SOAP body i.e. - //*:Envelope/*:Body/child::*
-     *
-     * @param synCtx the message context
-     * @return the OMNode against which validation should be performed
-     */
-    private OMNode getValidateSource(MessageContext synCtx) {
-
-        try {
-            Object o = source.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 {
-                handleException("The evaluation of the XPath expression "
-                        + source + " must result in an OMNode");
-            }
-        } catch (JaxenException e) {
-            handleException("Error evaluating XPath " + source + " on message");
-        }
-        return null;
-    }
-
     public boolean mediate(MessageContext synCtx) {
 
         log.debug("ValidateMediator - Validate mediator mediate()");
@@ -181,16 +160,7 @@
         synchronized (validatorLock) {
             if (reCreate || cachedSchema == null) {
                 try {
-                    SchemaFactory factory = SchemaFactory.newInstance(
-                            XMLConstants.W3C_XML_SCHEMA_NS_URI);
                     factory.setErrorHandler(errorHandler);
-                    // set any features on/off as requested
-                    for (Iterator iter = properties.iterator(); iter.hasNext();) {
-                        MediatorProperty prop = (MediatorProperty) iter.next();
-                        factory.setFeature(
-                                prop.getName(), prop.getValue() != null &&
-                                "true".equals(prop.getValue()));
-                    }
                     StreamSource[] sources = new StreamSource[schemaKeys.size()];
                     int i = 0;
                     for (Iterator iterator = schemaKeys.iterator(); iterator.hasNext();)
{
@@ -295,17 +265,42 @@
         throw new SynapseException(msg, e);
     }
 
+    /**
+     * Return the OMNode to be validated. If a source XPath is not specified, this will
+     * default to the first child of the SOAP body i.e. - //*:Envelope/*:Body/child::*
+     *
+     * @param synCtx the message context
+     * @return the OMNode against which validation should be performed
+     */
+    private OMNode getValidateSource(MessageContext synCtx) {
+
+        try {
+            Object o = source.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 {
+                handleException("The evaluation of the XPath expression "
+                        + source + " must result in an OMNode");
+            }
+        } catch (JaxenException e) {
+            handleException("Error evaluating XPath " + source + " on message");
+        }
+        return null;
+    }
+
     // setters and getters
 
     /**
-     * Get a mediator property. The common use case is a feature for the
+     * Get a mediator feature. The common use case is a feature for the
      * underlying Xerces validator
      *
      * @param key property key / feature name
      * @return property string value (usually true|false)
      */
-    public Object getProperty(String key) {
-        Iterator iter = properties.iterator();
+    public Object getFeature(String key) {
+        Iterator iter = explicityFeatures.iterator();
         while (iter.hasNext()) {
             MediatorProperty prop = (MediatorProperty) iter.next();
             if (key.equals(prop.getName())) {
@@ -316,35 +311,27 @@
     }
 
     /**
-     * Set a property for this mediator
+     * add a feature which need to set for the Schema Factory
      *
-     * @param key   the property key / feature name
-     * @param value property string value (usually true|false)
-     * @see #getProperty(String)
+     * @param  featureName The name of the feature
+     * @param isFeatureEnable should this feature enable?(true|false)
+    * @see #getFeature(String)
      */
-    public void setProperty(String key, Object value) {
-        MediatorProperty prop = new MediatorProperty();
-        prop.setName(key);
-        prop.setValue(value.toString());
-        properties.add(prop);
-    }
-
-    /**
-     * Add a list of 'MediatorProperty'ies to this mediator
-     *
-     * @param list a List of MediatorProperty objects
-     */
-    public void addAllProperties(List list) {
-        Iterator iter = list.iterator();
-        while (iter.hasNext()) {
-            Object o = iter.next();
-            if (o instanceof MediatorProperty) {
-                MediatorProperty prop = (MediatorProperty) o;
-                setProperty(prop.getName(), prop.getValue());
+   public void addFeature(String featureName, boolean isFeatureEnable) {
+        try {
+            MediatorProperty mp = new MediatorProperty();
+            mp.setName(featureName);
+            if (isFeatureEnable) {
+                mp.setValue("true");
             } else {
-                handleException("Attempt to set invalid property type. " +
-                        "Expected MediatorProperty type got " + o.getClass().getName());
+                mp.setValue("false");
             }
+            explicityFeatures.add(mp);
+            factory.setFeature(featureName, isFeatureEnable);             
+        } catch (SAXNotSupportedException e) {
+           handleException("Error setting a feature to Schema Factory " + e.getMessage(),e);
+        } catch (SAXNotRecognizedException e) {
+           handleException("Error setting a feature to Schema Factory " + e.getMessage(),e);
         }
     }
 
@@ -383,10 +370,10 @@
     }
 
     /**
-     * Properties for the actual Xerces validator
-     * @return properties to be passed to the Xerces validator
+     * Features for the actual Xerces validator
+     * @return explicityFeatures to be passed to the Xerces validator
      */
-    public List getProperties() {
-        return properties;
+    public List getFeatures() {
+        return explicityFeatures;
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?view=diff&rev=555497&r1=555496&r2=555497
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
Wed Jul 11 22:39:37 2007
@@ -218,8 +218,8 @@
                 reCreate = true;
             }
         }
-        if (reCreate || cachedTemplates == null) {
-            synchronized (transformerLock) {
+        synchronized (transformerLock) {
+            if (reCreate || cachedTemplates == null) {
                 try {
                     cachedTemplates = transFact.newTemplates(
                             Util.getStreamSource(

Modified: webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java?view=diff&rev=555497&r1=555496&r2=555497
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java
(original)
+++ webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java
Wed Jul 11 22:39:37 2007
@@ -37,6 +37,7 @@
 
         String validateConfiguration = "<syn:validate xmlns:syn=\"http://ws.apache.org/ns/synapse\"
source=\"//regRequest\">" +
                 "<syn:schema key=\"file:synapse_repository/conf/sample/validate.xsd\"/>"
+
+                "<syn:feature name=\"http://javax.xml.XMLConstants/feature/secure-processing\"
value=\"true\"/>" +
                 "<syn:on-fail>" +
                 "<syn:drop/>" +
                 "</syn:on-fail>" +

Modified: webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java?view=diff&rev=555497&r1=555496&r2=555497
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java
(original)
+++ webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java
Wed Jul 11 22:39:37 2007
@@ -47,6 +47,9 @@
     private static final String HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID = 
         "http://apache.org/xml/features/honour-all-schemaLocations";
 
+    public static final String FEATURE_SECURE_PROCESSING =
+         "http://javax.xml.XMLConstants/feature/secure-processing";
+
     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"
+
@@ -101,8 +104,8 @@
     private static final String CUSTOM_FEATURES_MEDIATOR_CONFIG = 
             "<validate xmlns=\"http://ws.apache.org/ns/synapse\">" +
             "   <schema key=\"file:synapse_repository/conf/sample/validate.xsd\"/>"
+
-            "   <property name=\"" + SCHEMA_FULL_CHECKING_FEATURE_ID + "\" value=\"false\"/>"
+
-            "   <property name=\"" + HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID + "\" value=\"true\"/>"
+
+            "   <feature name=\"" + SCHEMA_FULL_CHECKING_FEATURE_ID + "\" value=\"false\"/>"
+
+            "   <feature name=\"" + HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID + "\" value=\"true\"/>"
+
             "   <on-fail>" +
             "       <makefault>" +
             "           <code value=\"tns:Receiver\" xmlns:tns=\"http://www.w3.org/2003/05/soap-envelope\"/>"
+
@@ -329,8 +332,8 @@
         ValidateMediator validate = (ValidateMediator)mf.createMediator(
             createOMElement(DEFAULT_FEATURES_MEDIATOR_CONFIG));
 
-        assertNull(validate.getProperty(SCHEMA_FULL_CHECKING_FEATURE_ID));
-        assertNull(validate.getProperty(HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID));
+        assertNull(validate.getFeature(SCHEMA_FULL_CHECKING_FEATURE_ID));
+        assertNull(validate.getFeature(HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID));
 
         makeValidInvocation(validate);
     }
@@ -341,10 +344,10 @@
         ValidateMediator validate = (ValidateMediator)mf.createMediator(
             createOMElement(CUSTOM_FEATURES_MEDIATOR_CONFIG));
 
-        assertNotNull(validate.getProperty(SCHEMA_FULL_CHECKING_FEATURE_ID));
-        assertFalse("true".equals((String)validate.getProperty(SCHEMA_FULL_CHECKING_FEATURE_ID)));
-        assertNotNull(validate.getProperty(HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID));
-        assertTrue("true".equals((String)validate.getProperty(HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID)));
+        assertNotNull(validate.getFeature(SCHEMA_FULL_CHECKING_FEATURE_ID));
+        assertFalse("true".equals((String)validate.getFeature(SCHEMA_FULL_CHECKING_FEATURE_ID)));
+        assertNotNull(validate.getFeature(HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID));
+        assertTrue("true".equals((String)validate.getFeature(HONOUR_ALL_SCHEMA_LOCATIONS_FEATURE_ID)));
 
         makeValidInvocation(validate);
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message