You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ng...@apache.org on 2006/12/07 18:37:57 UTC

svn commit: r483562 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/ src/org/apache/axis2/jaxws/client/ test/org/apache/axis2/jaxws/client/ test/org/apache/axis2/jaxws/framework/

Author: ngallardo
Date: Thu Dec  7 09:37:56 2006
New Revision: 483562

URL: http://svn.apache.org/viewvc?view=rev&rev=483562
Log:
Adding validation to client side request context properties.

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/PropertyValidator.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PropertyValueTests.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java?view=diff&rev=483562&r1=483561&r2=483562
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java Thu Dec  7 09:37:56 2006
@@ -24,6 +24,7 @@
 import javax.xml.ws.Binding;
 
 import org.apache.axis2.jaxws.binding.SOAPBinding;
+import org.apache.axis2.jaxws.client.PropertyValidator;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.spi.ServiceDelegate;
@@ -49,8 +50,8 @@
      * Initialize any objects needed by the BindingProvider
      */
     private void initialize() {
-        requestContext = new Hashtable<String,Object>();
-        responseContext = new Hashtable<String,Object>();
+        requestContext = new ValidatingClientContext();
+        responseContext = new ValidatingClientContext();
         
         // Setting standard property defaults for the request context
         requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, new Boolean(false));
@@ -155,6 +156,22 @@
         else {
             // If the value is not set, then just default to sending a SOAPAction
             return true;
+        }
+    }
+    
+    /*
+     * An inner class used to validate properties as they are set by the client.
+     */
+    class ValidatingClientContext extends Hashtable<String, Object> {
+
+        @Override
+        public synchronized Object put(String key, Object value) {
+            if (PropertyValidator.validate(key, value)) {
+                return super.put(key, value);
+            }
+            else {
+                throw ExceptionFactory.makeWebServiceException("Bad Property");
+            }
         }
     }
 }

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/PropertyValidator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/PropertyValidator.java?view=auto&rev=483562
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/PropertyValidator.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/PropertyValidator.java Thu Dec  7 09:37:56 2006
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.axis2.jaxws.client;
+
+import java.util.HashMap;
+
+import javax.xml.ws.BindingProvider;
+
+public class PropertyValidator {
+
+    private static HashMap<String, Class> map = new HashMap<String, Class>();
+    
+    static {
+        map.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, String.class);
+        map.put(BindingProvider.USERNAME_PROPERTY, String.class);
+        map.put(BindingProvider.PASSWORD_PROPERTY, String.class);
+        map.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.class);
+        map.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.class);
+        map.put(BindingProvider.SOAPACTION_URI_PROPERTY, String.class);
+    }
+    
+    /**
+     * Checks to see if the property value is valid given the name of the
+     * property and the type that is expected by JAX-WS.
+     * @param propName
+     * @param value
+     * @return
+     */
+    public static boolean validate(String propName, Object value) {
+        Class expectedType = map.get(propName);
+        if (expectedType != null) {
+            if (expectedType.equals(value.getClass())) {
+                return true;
+            }
+            else {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PropertyValueTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PropertyValueTests.java?view=auto&rev=483562
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PropertyValueTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PropertyValueTests.java Thu Dec  7 09:37:56 2006
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.axis2.jaxws.client;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.Service.Mode;
+
+import junit.framework.TestCase;
+
+/**
+ * A suite to test the validation of the client request/response context properties
+ */
+public class PropertyValueTests extends TestCase {
+    
+    public PropertyValueTests(String name) {
+        super(name);
+    }
+    
+    public void testSetInvalidClientProperties() throws Exception {
+        Service svc = Service.create(new QName("http://test", "TestService"));
+        Dispatch dispatch = svc.createDispatch(new QName("http://test", "TestPort"), String.class, Mode.PAYLOAD);
+        
+        Map<String, Object> map = dispatch.getRequestContext();
+        
+        try {
+            map.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, new Integer(4));
+            fail();
+        }
+        catch (WebServiceException wse) {
+            System.out.println("[pass] - exception thrown as expected");
+        }
+
+        try {
+            map.put(BindingProvider.USERNAME_PROPERTY, new Integer(4));
+            fail();
+        }
+        catch (WebServiceException wse) {
+            System.out.println("[pass] - exception thrown as expected");
+        }
+        
+        try {
+            map.put(BindingProvider.PASSWORD_PROPERTY, new Integer(4));
+            fail();
+        }
+        catch (WebServiceException wse) {
+            System.out.println("[pass] - exception thrown as expected");
+        }
+
+        try {
+            map.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, "true");
+            fail();
+        }
+        catch (WebServiceException wse) {
+            System.out.println("[pass] - exception thrown as expected");
+        }
+        
+        try {
+            map.put(BindingProvider.SOAPACTION_USE_PROPERTY, "true");
+            fail();
+        }
+        catch (WebServiceException wse) {
+            System.out.println("[pass] - exception thrown as expected");
+        }
+
+        try {
+            map.put(BindingProvider.SOAPACTION_URI_PROPERTY, new Integer(4));
+            fail();
+        }
+        catch (WebServiceException wse) {
+            System.out.println("[pass] - exception thrown as expected");
+        }
+    }
+
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=483562&r1=483561&r2=483562
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Thu Dec  7 09:37:56 2006
@@ -24,6 +24,7 @@
 import org.apache.axis2.jaxws.anytype.tests.AnyTypeTests;
 import org.apache.axis2.jaxws.attachments.MTOMSerializationTests;
 import org.apache.axis2.jaxws.client.DispatchSoapActionTests;
+import org.apache.axis2.jaxws.client.PropertyValueTests;
 import org.apache.axis2.jaxws.client.ProxySoapActionTests;
 import org.apache.axis2.jaxws.databinding.BindingToProtocolTests;
 import org.apache.axis2.jaxws.description.AnnotationDescriptionTests;
@@ -98,6 +99,7 @@
         suite.addTestSuite(SOAP12Dispatch.class);
         suite.addTestSuite(DispatchSoapActionTests.class);
         suite.addTestSuite(ProxySoapActionTests.class);
+        suite.addTestSuite(PropertyValueTests.class);
         
         suite.addTestSuite(BlockTests.class);
         suite.addTestSuite(MessageTests.class);



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