axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r722635 - in /webservices/axis2/trunk/java/modules: jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/source/ jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/source/ jaxws/src/org/apache/axis2...
Date Tue, 02 Dec 2008 22:20:51 GMT
Author: gawor
Date: Tue Dec  2 14:20:51 2008
New Revision: 722635

URL: http://svn.apache.org/viewvc?rev=722635&view=rev
Log:
allow for null value for XML/HTTP Dispatch invocation when using HTTP GET (AXIS2-4145)

Modified:
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/source/DispatchXMessageSourceTests.java
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/source/XMessageSourceProvider.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/source/DispatchXMessageSourceTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/source/DispatchXMessageSourceTests.java?rev=722635&r1=722634&r2=722635&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/source/DispatchXMessageSourceTests.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/source/DispatchXMessageSourceTests.java
Tue Dec  2 14:20:51 2008
@@ -31,6 +31,8 @@
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.http.HTTPBinding;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -48,6 +50,8 @@
     private static String XML_TEXT = "<p:echo xmlns:p=\"http://sample\">hello world</p:echo>";
     private static String XML_TEXT_NPE = "<p:echo xmlns:p=\"http://sample\">NPE</p:echo>";
     
+    private static String GET_RESPONSE = "<response>GET</response>";
+    
     public static Test suite() {
         return getTestSetup(new TestSuite(DispatchXMessageSourceTests.class));
     }
@@ -94,6 +98,35 @@
         assertTrue(request.equals(response));
     }
     
+    public void testGetRequest() throws Exception {
+        Dispatch<Source> dispatch = getDispatch();
+
+        // this should fail
+        try {
+            dispatch.invoke(null);
+            fail("Did not throw WebServiceException");
+        } catch (WebServiceException e) {
+            // that's what we expect
+        }
+        
+        // this should work ok
+        dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, "GET"); 
+        Source outSource = dispatch.invoke(null);
+        
+        XMLStreamReader reader = inputFactory.createXMLStreamReader(outSource);
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String response = r2w.getAsString();        
+        assertEquals(GET_RESPONSE, response);     
+        
+        // this should fail again
+        dispatch.getRequestContext().remove(MessageContext.HTTP_REQUEST_METHOD);
+        try {
+            dispatch.invoke(null);
+            fail("Did not throw WebServiceException");
+        } catch (WebServiceException e) {
+            // that's what we expect
+        }
+    }
    
 }
 

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/source/XMessageSourceProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/source/XMessageSourceProvider.java?rev=722635&r1=722634&r2=722635&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/source/XMessageSourceProvider.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/source/XMessageSourceProvider.java
Tue Dec  2 14:20:51 2008
@@ -19,14 +19,22 @@
 
 package org.apache.axis2.jaxws.xmlhttp.provider.message.source;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.annotation.Resource;
 import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.BindingType;
 import javax.xml.ws.Provider;
 import javax.xml.ws.Service;
 import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceContext;
 import javax.xml.ws.WebServiceProvider;
 import javax.xml.ws.http.HTTPBinding;
 
+import org.apache.axis2.transport.http.HTTPConstants;
+
 /**
  * Sample XML/HTTP String Provider 
  */
@@ -35,7 +43,16 @@
 @ServiceMode(value=Service.Mode.MESSAGE)
 public class XMessageSourceProvider implements Provider<Source> {
 
+    @Resource
+    public WebServiceContext ctx;
+    
     public Source invoke(Source input) {
+        String method = (String)ctx.getMessageContext().get(HTTPConstants.HTTP_METHOD);
+        if (input == null) {
+            String request = "<response>" + method + "</response>";
+            ByteArrayInputStream stream = new ByteArrayInputStream(request.getBytes());
+            input = new StreamSource((InputStream) stream);
+        }
         return input;
     }
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java?rev=722635&r1=722634&r2=722635&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
Tue Dec  2 14:20:51 2008
@@ -162,7 +162,7 @@
                     }
                 }
             }
-            
+                        
             // Migrate the properties from the client request context bag to
             // the request MessageContext.
             ApplicationContextMigratorUtil.performMigrationToMessageContext(
@@ -225,6 +225,11 @@
         Message requestMsg = createRequestMessage(obj);
         setupMessageProperties(requestMsg);
         requestMsgCtx.setMessage(requestMsg);
+        // handle HTTP_REQUEST_METHOD property
+        String method = (String)requestContext.get(javax.xml.ws.handler.MessageContext.HTTP_REQUEST_METHOD);
+        if (method != null) {
+            requestMsgCtx.setProperty(org.apache.axis2.Constants.Configuration.HTTP_METHOD,
method);
+        }
     }
 
     public void invokeOneWay(Object obj) throws WebServiceException {
@@ -536,8 +541,8 @@
             }
         } else {
             // In all cases (PAYLOAD and MESSAGE) we must throw a WebServiceException
-            // if the parameter is null.
-            if (object == null) {
+            // if the parameter is null and request method is POST or PUT.
+            if (object == null && isPOSTorPUTRequest()) {
                 throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNullParamHttpBinding"));
             }
         }
@@ -553,6 +558,14 @@
         return true;
     }
     
+    private boolean isPOSTorPUTRequest() {
+        String method = (String)this.requestContext.get(javax.xml.ws.handler.MessageContext.HTTP_REQUEST_METHOD);
+        // if HTTP_REQUEST_METHOD is not specified, assume it is a POST method
+        return (method == null || 
+                HTTPConstants.HEADER_POST.equalsIgnoreCase(method) || 
+                HTTPConstants.HEADER_PUT.equalsIgnoreCase(method));
+    }
+    
     private Message createRequestMessage(Object obj) throws WebServiceException {
         
         // Check to see if the object is a valid invocation parameter.  



Mime
View raw message