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/01/28 17:46:05 UTC
svn commit: r615942 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/client/config/ test/org/apache/axis2/jaxws/client/
test/org/apache/axis2/jaxws/client/dispatch/
test/org/apache/axis2/jaxws/client/proxy/
Author: ngallardo
Date: Mon Jan 28 08:46:03 2008
New Revision: 615942
URL: http://svn.apache.org/viewvc?rev=615942&view=rev
Log:
AXIS2-3448
Tests and minor tweaks for client side MTOMFeature enablement.
Added:
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationController.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationControllerFactory.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.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=615942&r1=615941&r2=615942&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 Mon Jan 28 08:46:03 2008
@@ -31,14 +31,18 @@
import org.apache.axis2.jaxws.message.Message;
import org.apache.axis2.jaxws.spi.Binding;
import org.apache.axis2.jaxws.spi.BindingProvider;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
*
*/
public class MTOMConfigurator implements ClientConfigurator {
+ private static Log log = LogFactory.getLog(MTOMConfigurator.class);
+
/*
- * (non-Javadoc)
+ * (non-Javadoc)
* @see org.apache.axis2.jaxws.feature.util.WebServiceFeatureConfigurator#performConfiguration(org.apache.axis2.jaxws.core.MessageContext, org.apache.axis2.jaxws.spi.BindingProvider)
*/
public void configure(MessageContext messageContext, BindingProvider provider) {
@@ -49,7 +53,7 @@
//Disable MTOM.
requestMsg.setMTOMEnabled(false);
-// TODO NLS enable.
+ //TODO NLS enable.
if (mtomFeature == null)
throw ExceptionFactory.makeWebServiceException("The MTOM features was unspecified.");
@@ -58,42 +62,52 @@
int threshold = mtomFeature.getThreshold();
List<String> attachmentIDs = requestMsg.getAttachmentIDs();
+ // If a threshold wasn't configured, enable MTOM for all cases.
+ if (threshold <= 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("Enabling MTOM with no threshold.");
+ }
+ requestMsg.setMTOMEnabled(true);
+ }
+
if (attachmentIDs != null) {
long size = 0L;
- for (String attachmentID : attachmentIDs) {
- DataHandler dh = requestMsg.getDataHandler(attachmentID);
+ for (String attachmentID : attachmentIDs) {
+ DataHandler dh = requestMsg.getDataHandler(attachmentID);
- if (dh != null) {
- DataSource ds = dh.getDataSource();
- InputStream is = null;
+ if (dh != null) {
+ DataSource ds = dh.getDataSource();
+ InputStream is = null;
- try {
- is = ds.getInputStream();
- size += is.available();
- }
- catch (Exception e) {
-// TODO NLS enable.
- throw ExceptionFactory.makeWebServiceException("Unable to determine the size of the attachment(s).", e);
+ try {
+ is = ds.getInputStream();
+ size += is.available();
+ }
+ catch (Exception e) {
+ // TODO NLS enable.
+ throw ExceptionFactory.makeWebServiceException("Unable to determine the size of the attachment(s).", e);
}
finally {
- try {
- if (is != null)
- is.close();
- }
- catch (Exception e) {
- //Nothing to do.
- }
+ try {
+ if (is != null)
+ is.close();
+ }
+ catch (Exception e) {
+ //Nothing to do.
+ }
}
- }
- }
+ }
+ }
if (size > threshold)
- requestMsg.setMTOMEnabled(true);
+ requestMsg.setMTOMEnabled(true);
}
}
else {
-
+ if (log.isDebugEnabled()) {
+ log.debug("The MTOMFeature was found, but not enabled.");
+ }
}
}
}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationController.java?rev=615942&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationController.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationController.java Mon Jan 28 08:46:03 2008
@@ -0,0 +1,66 @@
+/*
+ * 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.InvocationContext;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.core.controller.InvocationController;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import java.util.concurrent.Future;
+
+public class TestClientInvocationController implements InvocationController {
+
+ private InvocationContext cachedCtx;
+
+ public InvocationContext invoke(InvocationContext ic) {
+ cachedCtx = ic;
+
+ MessageContext request = ic.getRequestMessageContext();
+ MessageContext response = new MessageContext();
+
+ response.setEndpointDescription(request.getEndpointDescription());
+ response.setMessage(request.getMessage());
+
+ ic.setResponseMessageContext(response);
+ return ic;
+ }
+
+ public Future<?> invokeAsync(InvocationContext ic, AsyncHandler asyncHandler) {
+ cachedCtx = ic;
+ return null;
+ }
+
+ public Response invokeAsync(InvocationContext ic) {
+ cachedCtx = ic;
+ return null;
+ }
+
+ public void invokeOneWay(InvocationContext ic) throws Exception {
+ cachedCtx = ic;
+
+ }
+
+ public InvocationContext getInvocationContext() {
+ return cachedCtx;
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationControllerFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationControllerFactory.java?rev=615942&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationControllerFactory.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/TestClientInvocationControllerFactory.java Mon Jan 28 08:46:03 2008
@@ -0,0 +1,39 @@
+/*
+ * 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.InvocationController;
+import org.apache.axis2.jaxws.core.controller.InvocationControllerFactory;
+
+public class TestClientInvocationControllerFactory implements InvocationControllerFactory {
+
+ private InvocationController ic;
+
+ public InvocationController getInvocationController() {
+ if (ic != null)
+ return ic;
+ else
+ return new TestClientInvocationController();
+ }
+
+ public void setInvocationController(InvocationController inst) {
+ ic = inst;
+ }
+
+}
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=615942&r1=615941&r2=615942&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 Mon Jan 28 08:46:03 2008
@@ -1,5 +1,37 @@
+/*
+ * 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.dispatch;
+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;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.MTOMFeature;
+import javax.xml.ws.soap.SOAPBinding;
+
import junit.framework.TestCase;
/**
@@ -8,45 +40,152 @@
*/
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);
+ }
+
/*
* Make sure MTOM is not enabled by default.
*/
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);
+
+ d.invoke(null);
+
+ InvocationContext ic = testController.getInvocationContext();
+ MessageContext request = ic.getRequestMessageContext();
+
+ assertFalse("MTOM should not be enabled by default.", request.getMessage().isMTOMEnabled());
}
/*
* 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();
+ Dispatch<Source> d = svc.createDispatch(new QName("http://test", "TestPort"),
+ Source.class, Service.Mode.PAYLOAD, feature);
+
+ d.invoke(null);
+
+ InvocationContext ic = testController.getInvocationContext();
+ MessageContext request = ic.getRequestMessageContext();
+
+ assertTrue("MTOM should be enabled via the MTOMFeature.", request.getMessage().isMTOMEnabled());
}
/*
* Test disabling the MTOM feature.
*/
public void testDisabledMTOMFeature() {
+ Service svc = Service.create(new QName("http://test", "TestService"));
+ svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
+
+ // Set the feature to be disabled.
+ MTOMFeature feature = new MTOMFeature(false);
+
+ Dispatch<Source> d = svc.createDispatch(new QName("http://test", "TestPort"),
+ Source.class, Service.Mode.PAYLOAD, feature);
+
+ d.invoke(null);
+ InvocationContext ic = testController.getInvocationContext();
+ MessageContext request = ic.getRequestMessageContext();
+
+ assertFalse("MTOM should be disabled via the MTOMFeature.", request.getMessage().isMTOMEnabled());
}
/*
* Test the configuration of the threshold for MTOM.
*/
public void testMTOMFeatureThreshold() {
+ Service svc = Service.create(new QName("http://test", "TestService"));
+ svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost");
+
+ // Set the feature to be disabled.
+ int threshold = 20000;
+ MTOMFeature feature = new MTOMFeature(threshold);
+
+ Dispatch<Source> d = svc.createDispatch(new QName("http://test", "TestPort"),
+ Source.class, Service.Mode.PAYLOAD, feature);
+
+ d.invoke(null);
+
+ InvocationContext ic = testController.getInvocationContext();
+ MessageContext request = ic.getRequestMessageContext();
+ assertFalse("MTOM should not be enabled. The threshold was not exceeded.", request.getMessage().isMTOMEnabled());
}
/*
* Test the co-existence of an MTOMFeature and a MTOM binding type for a client.
*/
public void testMTOMFeatureAndBinding() {
+ Service svc = Service.create(new QName("http://test", "TestService"));
+ svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_MTOM_BINDING, "http://localhost");
+ // Use the default feature config
+ MTOMFeature feature = new MTOMFeature();
+
+ Dispatch<Source> d = svc.createDispatch(new QName("http://test", "TestPort"),
+ Source.class, Service.Mode.PAYLOAD, feature);
+
+ d.invoke(null);
+
+ InvocationContext ic = testController.getInvocationContext();
+ MessageContext request = ic.getRequestMessageContext();
+
+ assertTrue("MTOM should be enabled via the MTOMFeature.", request.getMessage().isMTOMEnabled());
}
/*
* Test the override of an MTOM binding by disabling MTOM via the MTOMFeature.
*/
public void testMTOMFeatureAndBindingOverride() {
+ Service svc = Service.create(new QName("http://test", "TestService"));
+ svc.addPort(new QName("http://test", "TestPort"), SOAPBinding.SOAP11HTTP_MTOM_BINDING, "http://localhost");
+
+ // Use the default feature config
+ MTOMFeature feature = new MTOMFeature(false);
+
+ Dispatch<Source> d = svc.createDispatch(new QName("http://test", "TestPort"),
+ Source.class, Service.Mode.PAYLOAD, feature);
+
+ d.invoke(null);
+
+ InvocationContext ic = testController.getInvocationContext();
+ MessageContext request = ic.getRequestMessageContext();
+ assertFalse("MTOM should be disabled via the MTOMFeature.", request.getMessage().isMTOMEnabled());
}
}
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=615942&r1=615941&r2=615942&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 Mon Jan 28 08:46:03 2008
@@ -1,3 +1,21 @@
+/*
+ * 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.proxy;
import junit.framework.TestCase;
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org