You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ng...@apache.org on 2008/02/21 17:35:29 UTC

svn commit: r629858 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/client/config/ src/org/apache/axis2/jaxws/client/dispatch/ src/org/apache/axis2/jaxws/client/proxy/ test/org/apache/axis2/jaxws/client/ test/org/apache/axi...

Author: ngallardo
Date: Thu Feb 21 08:35:29 2008
New Revision: 629858

URL: http://svn.apache.org/viewvc?rev=629858&view=rev
Log:
AXIS2-3448

More tests and support for MTOMFeature config.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/InterceptableClientTestCase.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchMTOMFeatureTest.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxyMTOMFeatureTest.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java?rev=629858&r1=629857&r2=629858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java Thu Feb 21 08:35:29 2008
@@ -70,8 +70,7 @@
                 }
                 requestMsg.setMTOMEnabled(true);
             }
-            
-            if (attachmentIDs != null) {
+            else if (attachmentIDs != null) {
             	long size = 0L;
             	
             	for (String attachmentID : attachmentIDs) {

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=629858&r1=629857&r2=629858&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 Thu Feb 21 08:35:29 2008
@@ -78,6 +78,11 @@
 
         InvocationControllerFactory icf = (InvocationControllerFactory) FactoryRegistry.getFactory(InvocationControllerFactory.class);
         ic = icf.getInvocationController();
+        
+        if (ic == null) {
+            // TODO NLS enable.
+            throw new WebServiceException("An InvocationController instance was not found.");
+        }
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java?rev=629858&r1=629857&r2=629858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java Thu Feb 21 08:35:29 2008
@@ -26,13 +26,14 @@
 import org.apache.axis2.jaxws.core.InvocationContextFactory;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.core.controller.InvocationController;
-import org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController;
+import org.apache.axis2.jaxws.core.controller.InvocationControllerFactory;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.description.OperationDescription;
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.marshaller.factory.MethodMarshallerFactory;
 import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.spi.Binding;
 import org.apache.axis2.jaxws.spi.Constants;
 import org.apache.axis2.jaxws.spi.ServiceDelegate;
@@ -42,6 +43,7 @@
 
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Response;
+import javax.xml.ws.WebServiceException;
 import javax.xml.ws.WebServiceFeature;
 import javax.xml.ws.soap.SOAPBinding;
 
@@ -79,13 +81,14 @@
         InvocationHandler {
     private static Log log = LogFactory.getLog(JAXWSProxyHandler.class);
 
-    //Reference to ServiceDelegate instance that was used to create the Proxy
-    protected ServiceDescription serviceDesc = null;
-
     private Class seiClazz = null;
-
     private Method method = null;
+    
+    //Reference to ServiceDelegate instance that was used to create the Proxy
+    protected ServiceDescription serviceDesc = null;
 
+    protected InvocationController controller;
+    
     public JAXWSProxyHandler(ServiceDelegate delegate,
                              Class seiClazz,
                              EndpointDescription epDesc,
@@ -209,9 +212,14 @@
         // Perform the WebServiceFeature configuration requested by the user.
         bnd.configure(request, this);
 
-        // TODO: Change this to some form of factory so that we can change the IC to
-        // a more simple one for marshaller/unmarshaller testing.
-        InvocationController controller = new AxisInvocationController();
+        // We'll need an InvocationController instance to send the request.
+        InvocationControllerFactory icf = (InvocationControllerFactory) FactoryRegistry.getFactory(InvocationControllerFactory.class);
+        controller = icf.getInvocationController();
+        
+        if (controller == null) {
+            // TODO NLS enable.
+            throw new WebServiceException("An InvocationController was not found.");
+        }
         
         // Check if the call is OneWay, Async or Sync
         if (operationDesc.isOneWay()) {

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/InterceptableClientTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/InterceptableClientTestCase.java?rev=629858&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/InterceptableClientTestCase.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/InterceptableClientTestCase.java Thu Feb 21 08:35:29 2008
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.axis2.jaxws.core.controller.InvocationControllerFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+
+import junit.framework.TestCase;
+
+/**
+ * This TestCase can be extended to write JAX-WS client side unit tests without 
+ * having to have an end-to-end test.  The <source>TestClientInvocationController</source>
+ * will be used to capture the request.  
+ */
+public class InterceptableClientTestCase extends TestCase {
+
+    private InvocationControllerFactory oldFactory;
+    private TestClientInvocationControllerFactory newFactory;
+    private TestClientInvocationController testController;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        InvocationControllerFactory icf = (InvocationControllerFactory) FactoryRegistry.getFactory(InvocationControllerFactory.class);
+        oldFactory = icf;
+        
+        testController = new TestClientInvocationController();
+        
+        newFactory = new TestClientInvocationControllerFactory();
+        newFactory.setInvocationController(testController);
+        
+        FactoryRegistry.setFactory(InvocationControllerFactory.class, newFactory);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        FactoryRegistry.setFactory(InvocationControllerFactory.class, oldFactory);
+    }
+    
+    protected TestClientInvocationController getInvocationController() {
+        return testController;
+    }
+    
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchMTOMFeatureTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchMTOMFeatureTest.java?rev=629858&r1=629857&r2=629858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchMTOMFeatureTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DispatchMTOMFeatureTest.java Thu Feb 21 08:35:29 2008
@@ -18,12 +18,10 @@
  */
 package org.apache.axis2.jaxws.client.dispatch;
 
+import org.apache.axis2.jaxws.client.InterceptableClientTestCase;
 import org.apache.axis2.jaxws.client.TestClientInvocationController;
-import org.apache.axis2.jaxws.client.TestClientInvocationControllerFactory;
 import org.apache.axis2.jaxws.core.InvocationContext;
 import org.apache.axis2.jaxws.core.MessageContext;
-import org.apache.axis2.jaxws.core.controller.InvocationControllerFactory;
-import org.apache.axis2.jaxws.registry.FactoryRegistry;
 
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
@@ -32,39 +30,11 @@
 import javax.xml.ws.soap.MTOMFeature;
 import javax.xml.ws.soap.SOAPBinding;
 
-import junit.framework.TestCase;
-
 /**
  * This suite of tests is for the MTOMFeature configuration that can
  * be used on Dispatch clients.
  */
-public class DispatchMTOMFeatureTest extends TestCase {
-
-    private InvocationControllerFactory oldFactory;
-    private TestClientInvocationControllerFactory newFactory;
-    private TestClientInvocationController testController;
-    
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        
-        InvocationControllerFactory icf = (InvocationControllerFactory) FactoryRegistry.getFactory(InvocationControllerFactory.class);
-        oldFactory = icf;
-        
-        testController = new TestClientInvocationController();
-        
-        newFactory = new TestClientInvocationControllerFactory();
-        newFactory.setInvocationController(testController);
-        
-        FactoryRegistry.setFactory(InvocationControllerFactory.class, newFactory);
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-
-        FactoryRegistry.setFactory(InvocationControllerFactory.class, oldFactory);
-    }
+public class DispatchMTOMFeatureTest extends InterceptableClientTestCase {
 
     /*
      * Make sure MTOM is not enabled by default.
@@ -72,14 +42,19 @@
     public void testNoMTOMFeature() {
         Service svc = Service.create(new QName("http://test", "TestService"));
         svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
-        
         Dispatch<Source> d = svc.createDispatch(new QName("http://test", "TestPort"), Source.class, Service.Mode.PAYLOAD);
         
+        SOAPBinding sb = (SOAPBinding) d.getBinding();
+        assertTrue("SOAPBinding should not be null.", sb != null);
+        assertTrue("MTOM should not be enabled on the binding by default.", !sb.isMTOMEnabled());
+        
         d.invoke(null);
         
+        TestClientInvocationController testController = getInvocationController();
         InvocationContext ic = testController.getInvocationContext();
         MessageContext request = ic.getRequestMessageContext();
         
+        assertTrue("Request should not be null.", request != null);
         assertFalse("MTOM should not be enabled by default.", request.getMessage().isMTOMEnabled());
     }
     
@@ -87,17 +62,17 @@
      * Test the default configuration of the MTOMFeature.
      */
     public void testDefaultMTOMFeature() {
-        Service svc = Service.create(new QName("http://test", "TestService"));
-        svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
-        
         // Use the default feature config
         MTOMFeature feature = new MTOMFeature();
         
+        Service svc = Service.create(new QName("http://test", "TestService"));
+        svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
         Dispatch<Source> d = svc.createDispatch(new QName("http://test", "TestPort"), 
             Source.class, Service.Mode.PAYLOAD, feature);
         
         d.invoke(null);
         
+        TestClientInvocationController testController = getInvocationController();
         InvocationContext ic = testController.getInvocationContext();
         MessageContext request = ic.getRequestMessageContext();
         
@@ -119,6 +94,8 @@
         
         d.invoke(null);
         
+        TestClientInvocationController testController = getInvocationController();
+        
         InvocationContext ic = testController.getInvocationContext();
         MessageContext request = ic.getRequestMessageContext();
         
@@ -126,9 +103,11 @@
     }
     
     /*
-     * Test the configuration of the threshold for MTOM.
+     * Test the configuration of the threshold for MTOM when no attachment is 
+     * specified.  In this case, although enabled per the MTOMFeature, MTOM should
+     * not be enabled on the Message, since the attachment size is too small.
      */
-    public void testMTOMFeatureThreshold() {
+    public void testMTOMFeatureThresholdWithNoAttachment() {
         Service svc = Service.create(new QName("http://test", "TestService"));
         svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
         
@@ -141,6 +120,8 @@
         
         d.invoke(null);
         
+        TestClientInvocationController testController = getInvocationController();
+        
         InvocationContext ic = testController.getInvocationContext();
         MessageContext request = ic.getRequestMessageContext();
         
@@ -148,6 +129,15 @@
     }
     
     /*
+     * Test the configuration of the threshold for MTOM when an attachment is specified.
+     * In this case, MTOM should be enabled on the Message if the attachment specified is
+     * larger than the threshold.
+     */
+    public void testMTOMFeatureThresholdWithAttachment() {
+        
+    }
+    
+    /*
      * Test the co-existence of an MTOMFeature and a MTOM binding type for a client.
      */
     public void testMTOMFeatureAndBinding() {
@@ -162,6 +152,8 @@
         
         d.invoke(null);
         
+        TestClientInvocationController testController = getInvocationController();
+        
         InvocationContext ic = testController.getInvocationContext();
         MessageContext request = ic.getRequestMessageContext();
         
@@ -182,6 +174,8 @@
             Source.class, Service.Mode.PAYLOAD, feature);
         
         d.invoke(null);
+        
+        TestClientInvocationController testController = getInvocationController();
         
         InvocationContext ic = testController.getInvocationContext();
         MessageContext request = ic.getRequestMessageContext();

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxyMTOMFeatureTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxyMTOMFeatureTest.java?rev=629858&r1=629857&r2=629858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxyMTOMFeatureTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/proxy/ProxyMTOMFeatureTest.java Thu Feb 21 08:35:29 2008
@@ -18,53 +18,119 @@
  */
 package org.apache.axis2.jaxws.client.proxy;
 
-import junit.framework.TestCase;
+import org.apache.axis2.jaxws.client.InterceptableClientTestCase;
+import org.apache.axis2.jaxws.client.TestClientInvocationController;
+import org.apache.axis2.jaxws.core.InvocationContext;
+import org.apache.axis2.jaxws.core.MessageContext;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.MTOMFeature;
 
 /**
  * This suite of tests is for the MTOMFeature configuration that can
  * be used on Proxy clients.
  */
-public class ProxyMTOMFeatureTest extends TestCase {
+public class ProxyMTOMFeatureTest extends InterceptableClientTestCase {
 
     /*
      * Make sure MTOM is not enabled by default.
      */
     public void testNoMTOMFeature() {
+        Service svc = Service.create(new QName("http://test", "ProxyMTOMService"));
+        ProxyMTOMService proxy = svc.getPort(ProxyMTOMService.class);
+        assertTrue("Proxy instance was null", proxy != null);
+        
+        proxy.sendAttachment("12345");
         
+        TestClientInvocationController testController = getInvocationController();
+        InvocationContext ic = testController.getInvocationContext();
+        MessageContext request = ic.getRequestMessageContext();
+        
+        assertTrue("Request should not be null.", request != null);
+        assertTrue("MTOM should not be abled on the Message by default.", !request.getMessage().isMTOMEnabled());
     }
     
     /*
      * Test the default configuration of the MTOMFeature.
      */
     public void testDefaultMTOMFeature() {
+        // Use the default feature config
+        MTOMFeature feature = new MTOMFeature();
+        
+        Service svc = Service.create(new QName("http://test", "ProxyMTOMService"));
+        ProxyMTOMService proxy = svc.getPort(ProxyMTOMService.class, feature);
+        assertTrue("Proxy instance was null", proxy != null);
         
+        proxy.sendAttachment("12345");
+        
+        TestClientInvocationController testController = getInvocationController();
+        InvocationContext ic = testController.getInvocationContext();
+        MessageContext request = ic.getRequestMessageContext();
+        
+        assertTrue("Request should not be null.", request != null);
+        assertTrue("MTOM should be abled on the Message by default.", request.getMessage().isMTOMEnabled());
     }
     
     /*
      * Test disabling the MTOM feature.
      */
     public void testDisabledMTOMFeature() {
+        // Use the default feature config
+        MTOMFeature feature = new MTOMFeature(false);
+        
+        Service svc = Service.create(new QName("http://test", "ProxyMTOMService"));
+        ProxyMTOMService proxy = svc.getPort(ProxyMTOMService.class, feature);
+        assertTrue("Proxy instance was null", proxy != null);
+        
+        proxy.sendAttachment("12345");
         
+        TestClientInvocationController testController = getInvocationController();
+        InvocationContext ic = testController.getInvocationContext();
+        MessageContext request = ic.getRequestMessageContext();
+        
+        assertTrue("Request should not be null.", request != null);
+        assertTrue("MTOM should NOT be abled on the Message by default.", !request.getMessage().isMTOMEnabled());
     }
     
     /*
-     * Test the configuration of the threshold for MTOM.
+     * Test the configuration of the threshold for MTOM when no attachment is 
+     * specified.  In this case, although enabled per the MTOMFeature, MTOM should
+     * not be enabled on the Message, since the attachment size is too small.
      */
     public void testMTOMFeatureThreshold() {
+        // Set a threshold that we will not meet.
+        int threshold = 20000;
+        MTOMFeature feature = new MTOMFeature(threshold);
+        
+        Service svc = Service.create(new QName("http://test", "ProxyMTOMService"));
+        ProxyMTOMService proxy = svc.getPort(ProxyMTOMService.class, feature);
+        assertTrue("Proxy instance was null", proxy != null);
+        
+        proxy.sendAttachment("12345");
+        
+        TestClientInvocationController testController = getInvocationController();
+        InvocationContext ic = testController.getInvocationContext();
+        MessageContext request = ic.getRequestMessageContext();
         
+        assertTrue("Request should not be null.", request != null);
+        assertTrue("MTOM should NOT be abled on the Message, the threshold was not met.", !request.getMessage().isMTOMEnabled());
     }
     
     /*
-     * Test the co-existence of an MTOMFeature and a MTOM binding type for a client.
+     * Test the configuration of the threshold for MTOM when an attachment is specified.
+     * In this case, MTOM should be enabled on the Message if the attachment specified is
+     * larger than the threshold.
      */
-    public void testMTOMFeatureAndBinding() {
+    public void testMTOMFeatureThresholdWithAttachment() {
         
     }
     
-    /*
-     * Test the override of an MTOM binding by disabling MTOM via the MTOMFeature.
-     */
-    public void testMTOMFeatureAndBindingOverride() {
+    @WebService()
+    public interface ProxyMTOMService {
+    
+        public String sendAttachment(String id);
         
     }
 }



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