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/10/13 22:34:01 UTC

svn commit: r463813 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/client/BaseDispatch.java src/org/apache/axis2/jaxws/i18n/resource.properties test/org/apache/axis2/jaxws/dispatch/ParamTests.java

Author: ngallardo
Date: Fri Oct 13 13:34:00 2006
New Revision: 463813

URL: http://svn.apache.org/viewvc?view=rev&rev=463813
Log:
Cleaning up some non-spec behavior related to null params.  We shouldn't ever be throwing an NPE explicitly.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/ParamTests.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java?view=diff&rev=463813&r1=463812&r2=463813
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java Fri Oct 13 13:34:00 2006
@@ -23,6 +23,7 @@
 import javax.xml.ws.Response;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.Service.Mode;
+import javax.xml.ws.http.HTTPBinding;
 import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.axis2.client.ServiceClient;
@@ -105,9 +106,6 @@
             log.debug("Entered synchronous invocation: BaseDispatch.invoke()");
         }
         
-        //Check for valid invocation parameter
-        obj = validateInvocationParam(obj);
-        
         // Create the InvocationContext instance for this request/response flow.
         InvocationContext invocationContext = InvocationContextFactory.createInvocationContext(null);
         invocationContext.setServiceClient(serviceClient);
@@ -117,10 +115,17 @@
         MessageContext requestMsgCtx = new MessageContext();
         invocationContext.setRequestMessageContext(requestMsgCtx);
         
-        Message requestMsg = createMessageFromValue(obj);
-        setupMessageProperties(requestMsg);
-        requestMsgCtx.setMessage(requestMsg);
+        Message requestMsg = null;
+        if (isValidInvocationParam(obj)) {
+            requestMsg = createMessageFromValue(obj);
+        }
+        else {
+            throw ExceptionFactory.makeWebServiceException("dispatchInvalidParam");
+        }
         
+        setupMessageProperties(requestMsg);
+        requestMsgCtx.setMessage(requestMsg);            
+            
         // Copy the properties from the request context into the MessageContext
         requestMsgCtx.getProperties().putAll(requestContext);
         
@@ -145,9 +150,6 @@
             log.debug("Entered one-way invocation: BaseDispatch.invokeOneWay()");
         }
         
-        //Check for valid invocation parameter
-        obj = validateInvocationParam(obj);
-       
         // Create the InvocationContext instance for this request/response flow.
         InvocationContext invocationContext = InvocationContextFactory.createInvocationContext(null);
         invocationContext.setServiceClient(serviceClient);
@@ -157,7 +159,14 @@
         MessageContext requestMsgCtx = new MessageContext();
         invocationContext.setRequestMessageContext(requestMsgCtx);
        
-        Message requestMsg = createMessageFromValue(obj);
+        Message requestMsg = null;
+        if (isValidInvocationParam(obj)) {
+            requestMsg = createMessageFromValue(obj);
+        }
+        else {
+            throw ExceptionFactory.makeWebServiceException("dispatchInvalidParam");
+        }
+        
         setupMessageProperties(requestMsg);
         requestMsgCtx.setMessage(requestMsg);
        
@@ -179,9 +188,6 @@
             log.debug("Entered asynchronous (callback) invocation: BaseDispatch.invokeAsync()");
         }
         
-        //Check for valid invocation parameter
-        obj = validateInvocationParam(obj);
-        
         // Create the InvocationContext instance for this request/response flow.
         InvocationContext invocationContext = InvocationContextFactory.createInvocationContext(null);
         invocationContext.setServiceClient(serviceClient);
@@ -191,7 +197,14 @@
         MessageContext requestMsgCtx = new MessageContext();
         invocationContext.setRequestMessageContext(requestMsgCtx);
         
-        Message requestMsg = createMessageFromValue(obj);
+        Message requestMsg = null;
+        if (isValidInvocationParam(obj)) {
+            requestMsg = createMessageFromValue(obj);
+        }
+        else {
+            throw ExceptionFactory.makeWebServiceException("dispatchInvalidParam");
+        }
+        
         setupMessageProperties(requestMsg);
         requestMsgCtx.setMessage(requestMsg);
         
@@ -283,36 +296,35 @@
         }
     }
     
-    /**
-     * Validate invocation parameter value.
-     * @param object
-     * @return object
+    /*
+     * Validate the invocation param for the Dispatch.  There are 
+     * some cases when nulls are allowed and others where it's 
+     * a violation.
      */
-    private Object validateInvocationParam(Object object){
-    	Object obj = object;
+    private boolean isValidInvocationParam(Object object){
     	String bindingId = port.getBindingID();
-    	
-    	try {
-    		if(bindingId.equalsIgnoreCase(SOAPBinding.SOAP11HTTP_BINDING) ||
-    		   bindingId.equalsIgnoreCase(SOAPBinding.SOAP11HTTP_MTOM_BINDING)){
-    			if(mode.toString().equalsIgnoreCase(Mode.PAYLOAD.toString()) && object == null){
-    				//TODO Per JAXWS 2.0 Specification in Section 4.3.2, may need to send a soap
-    				//     message with empty body. For now, implementation will through a
-    				//     NullPointerException wrapped in WebServiceException
-    				throw new NullPointerException("Error: Dispatch invocation value is NULL");
-    			}
-    		}
-    		else if(object == null){
-    			throw new NullPointerException("Error: Dispatch invocation value is NULL");
-    		}
-    	}
-    	catch(NullPointerException npe){
-    		throw ExceptionFactory.makeWebServiceException(npe);
-    	}
-    	catch(Exception e){
-    		throw ExceptionFactory.makeWebServiceException(e);
-    	}
-    	
-    	return obj;
+        
+        // If no bindingId was found, use the default.
+        if (bindingId == null) {
+            bindingId = SOAPBinding.SOAP11HTTP_BINDING;
+        }
+        
+        // If it's not an HTTP_BINDING, then we can allow for null params,  
+        // but only in PAYLOAD mode per JAX-WS Section 4.3.2.
+        if (!bindingId.equals(HTTPBinding.HTTP_BINDING)) { 
+            if (mode.equals(Mode.MESSAGE) && object == null) {
+                throw ExceptionFactory.makeWebServiceException("dispatchNullParamMessageMode");
+            }
+        }
+        else {
+            // In all cases (PAYLOAD and MESSAGE) we must throw a WebServiceException
+            // if the parameter is null.
+            if (object == null) {
+                throw ExceptionFactory.makeWebServiceException("dispatchNullParamHttpBinding");
+            }
+        }
+        
+        // If we've gotten this far, then all is good.
+        return true;
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties?view=diff&rev=463813&r1=463812&r2=463813
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties Fri Oct 13 13:34:00 2006
@@ -108,3 +108,6 @@
 JavaBeanDispatcherErr1=No Java method was found for the operation, if WSDL Operation Name is different from java Method name, make sure you have @WebMethod annotation name present.DocLitProxyHandlerErr2 = Method Input parameter for NON Wrapped Request cannot be null.
 SOAP12WithSAAJ12Err=A SOAP 1.2 Message cannot be rendered in an SAAJ 1.2 Object Model.
 SOAP12WithSAAJ12Err=A SOAP 1.2 Message cannot be rendered in an SAAJ 1.2 Object Model.
+dispatchNullParamMessageMode=The parameter cannot be null for a Dispatch invocation using MESSAGE mode.
+dispatchNullParamHttpBinding=The parameter cannot be null for a Dispatch invocation using the XML/HTTP Binding.
+dispatchInvalidParam=The parameter for the Dispatch invocation was invalid.

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/ParamTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/ParamTests.java?view=auto&rev=463813
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/ParamTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/dispatch/ParamTests.java Fri Oct 13 13:34:00 2006
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.dispatch;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.TestCase;
+
+/**
+ * A suite for some tests for specific behavior in the Dispatch with 
+ * null and invalid params.
+ */
+public class ParamTests extends TestCase {
+    
+    public ParamTests(String name) {
+        super(name);
+    }
+    
+    public void testNullSoapParamWithMessageMode() {
+        QName serviceName = new QName("http://test", "MyService");
+        QName portName = new QName("http://test", "MyPort");
+        
+        Service svc = Service.create(serviceName);
+        svc.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
+        
+        Dispatch<Source> dispatch = svc.createDispatch(portName, 
+                Source.class, Mode.PAYLOAD);
+        
+        boolean handled = false;
+        try {
+            dispatch.invoke(null);    
+        }
+        catch (WebServiceException wse) {
+            handled = true;
+        }        
+        
+        assertTrue("A WebServiceException should be thrown for this null param", handled);
+    }
+    
+    public void testNullHttpParamWithPayloadMode() {
+        // fill in this test when we add XML/HTTP Binding support
+    }
+    
+    public void testNullHttpParamWithMessageMode() {
+        // fill in this test when we add XML/HTTP Binding support        
+    }
+}



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