Author: asoldano
Date: 2013-08-28 10:38:25 -0400 (Wed, 28 Aug 2013)
New Revision: 17895
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseNewBusFeature.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/BusReuseTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/WSDLServlet.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/bus/InvalidAddressEndpoint.wsdl
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/bus/ValidAddressEndpoint.wsdl
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java
Log:
[JBWS-3699] Adding UseNewBusFeature feature and a testcase for it
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2013-08-28
12:17:12 UTC (rev 17894)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2013-08-28
14:38:25 UTC (rev 17895)
@@ -37,7 +37,6 @@
import javax.xml.ws.Endpoint;
import javax.xml.ws.EndpointContext;
import javax.xml.ws.EndpointReference;
-import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.Service.Mode;
import javax.xml.ws.spi.Invoker;
@@ -51,7 +50,6 @@
import org.apache.cxf.jaxws.ServiceImpl;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.jboss.ws.api.configuration.AbstractClientFeature;
-import org.jboss.ws.common.configuration.ConfigHelper;
import org.jboss.ws.common.utils.DelegateClassLoader;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
@@ -185,13 +183,31 @@
try
{
restoreTCCL = checkAndFixContextClassLoader(origClassLoader);
- Bus bus = setValidThreadDefaultBus();
+ boolean createNewBus = false;
for (WebServiceFeature f : features) {
- if (!f.getClass().getName().startsWith("javax.xml.ws")) {
+ final String fName = f.getClass().getName();
+ if (!fName.startsWith("javax.xml.ws") &&
!fName.startsWith("org.jboss.ws")) {
throw Messages.MESSAGES.unknownFeature(f.getClass().getName());
}
+ if (fName.equals(UseNewBusFeature.class.getName())) {
+ createNewBus = f.isEnabled();
+ }
}
- return new JBossWSServiceImpl(bus, wsdlDocumentLocation, serviceName,
serviceClass, features);
+ if (!createNewBus) {
+ Bus bus = setValidThreadDefaultBus();
+ return new JBossWSServiceImpl(bus, wsdlDocumentLocation, serviceName,
serviceClass, features);
+ } else { //honor the UseNewBusFeature
+ Bus orig = null;
+ try {
+ orig = BusFactory.getThreadDefaultBus(false);
+ Bus bus = BusFactory.newInstance().createBus();
+ return new JBossWSServiceImpl(bus, wsdlDocumentLocation, serviceName,
serviceClass, features);
+ } finally {
+ if (orig != null) {
+ BusFactory.setThreadDefaultBus(orig);
+ }
+ }
+ }
}
finally
{
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseNewBusFeature.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseNewBusFeature.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseNewBusFeature.java 2013-08-28
14:38:25 UTC (rev 17895)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.client;
+
+import javax.xml.ws.WebServiceFeature;
+
+/**
+ * A JBossWS-CXF custom WebServiceFeature to be used for requesting a new Bus
+ * to be created for building the JAXWS Service.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 28-Aug-2013
+ *
+ */
+public class UseNewBusFeature extends WebServiceFeature
+{
+ public UseNewBusFeature() {
+ this.enabled = true;
+ }
+
+ public UseNewBusFeature(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public String getID()
+ {
+ return this.getClass().getName();
+ }
+
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/BusReuseTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/BusReuseTestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/BusReuseTestCase.java 2013-08-28
14:38:25 UTC (rev 17895)
@@ -0,0 +1,144 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.bus;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServiceFeature;
+
+import junit.framework.Test;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.jboss.wsf.stack.cxf.client.UseNewBusFeature;
+import org.jboss.wsf.test.JBossWSCXFTestSetup;
+import org.jboss.wsf.test.JBossWSTest;
+
+/**
+ * A testcase for verifying proper behaviour of the UseNewBusFeature on
+ * JAXWS Service creation.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 28-Aug-2013
+ *
+ */
+public class BusReuseTestCase extends JBossWSTest
+{
+ public final String WSDL_ADDRESS = "http://" + getServerHost() +
":8080/jaxws-cxf-bus-wsdl";
+
+ public static Test suite()
+ {
+ return new JBossWSCXFTestSetup(BusReuseTestCase.class, "jaxws-cxf-bus.war,
jaxws-cxf-bus-wsdl.war");
+ }
+
+ public void testReuse() throws Exception
+ {
+ //odd wsdl GETs return WSDL doc with invalid soap:address
+ //even wsdl GETs return WSDL doc with valid soap:address
+ final String wsdl1 = readWsdl(WSDL_ADDRESS); //invalid
+ final String wsdl2 = readWsdl(WSDL_ADDRESS); //valid
+ final String wsdl3 = readWsdl(WSDL_ADDRESS); //invalid
+ final String wsdl4 = readWsdl(WSDL_ADDRESS); //valid
+ assertEquals(wsdl1, wsdl3);
+ assertEquals(wsdl2, wsdl4);
+ assertFalse(wsdl1.equals(wsdl2));
+
+ Bus bus = BusFactory.newInstance().createBus();
+ try {
+ BusFactory.setThreadDefaultBus(bus);
+ Endpoint port = getPort(WSDL_ADDRESS, bus); //invalid
+ try {
+ performInvocation(port);
+ fail("Failure expected, as the wsdl soap:address is not valid!");
+ } catch (WebServiceException wse) {
+
assertTrue(wse.getCause().getMessage().contains("InvalidEndpoint"));
+ }
+
+ port = getPort(WSDL_ADDRESS, bus); //valid
+ try {
+ performInvocation(port);
+ fail("Failure expected, as the WSDLManager for the bus will return the
invalid wsdl");
+ } catch (WebServiceException wse) {
+
assertTrue(wse.getCause().getMessage().contains("InvalidEndpoint"));
+ }
+
+ port = getPort(WSDL_ADDRESS, bus); //invalid
+
+ port = getPort(WSDL_ADDRESS, bus, new UseNewBusFeature()); //valid
+ //the port should now actually be built against the valid wsdl
+ //as a new bus should have been started (with a new WSDLManager)
+ //so the invocation is expected to succeed
+ performInvocation(port);
+
+ port = getPort(WSDL_ADDRESS, bus); //invalid
+
+ port = getPort(WSDL_ADDRESS, bus, new UseNewBusFeature(false)); //valid
+ try {
+ performInvocation(port);
+ fail("Failure expected, as the WSDLManager for the bus will return the
invalid wsdl (disabled feature used)");
+ } catch (WebServiceException wse) {
+
assertTrue(wse.getCause().getMessage().contains("InvalidEndpoint"));
+ }
+ } finally {
+ bus.shutdown(true);
+ }
+ }
+
+ private String readWsdl(String addr) throws Exception {
+ BufferedReader in = null;
+ try {
+ in = new BufferedReader(new InputStreamReader(new URL(addr).openStream()));
+ StringBuffer sb = new StringBuffer();
+ String line;
+ while ((line = in.readLine()) != null) {
+ sb.append(line);
+ }
+ return sb.toString();
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ protected static void performInvocation(Endpoint endpoint)
+ {
+ String result = endpoint.echo("Alessio");
+ assert ("Alessio".equals(result));
+ }
+
+ protected static Endpoint getPort(String wsdlAddr, Bus currentThreadBus,
WebServiceFeature... features) throws MalformedURLException
+ {
+ QName serviceName = new QName("http://org.jboss.ws/bus",
"EndpointService");
+ Service service = Service.create(new URL(wsdlAddr), serviceName, features);
+ //check the current thread bus has not changed (even if we used the
UseNewBusFeature)
+ assertEquals(currentThreadBus, BusFactory.getThreadDefaultBus(false));
+ QName portQName = new QName("http://org.jboss.ws/bus",
"EndpointPort");
+ return (Endpoint) service.getPort(portQName, Endpoint.class);
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/WSDLServlet.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/WSDLServlet.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/bus/WSDLServlet.java 2013-08-28
14:38:25 UTC (rev 17895)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.bus;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * A servlet serving two WSDL documents alternatively
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 28-Aug-2013
+ *
+ */
+@WebServlet(name = "WSDLServlet", urlPatterns = "/*")
+public class WSDLServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ private static boolean serveValidWsdl = false;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
+ {
+ final OutputStream out = res.getOutputStream();
+ final InputStream in =
Thread.currentThread().getContextClassLoader().getResource(getWsdlName()).openStream();
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = in.read(buffer)) > 0)
+ {
+ out.write(buffer, 0, length);
+ }
+ in.close();
+ out.flush();
+ }
+
+ private static synchronized String getWsdlName() {
+ String result = "ValidAddressEndpoint.wsdl";
+ if (!serveValidWsdl) {
+ result = "InvalidAddressEndpoint.wsdl";
+ }
+ serveValidWsdl = !serveValidWsdl;
+ return result;
+ }
+
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/bus/InvalidAddressEndpoint.wsdl
===================================================================
(Binary files differ)
Property changes on:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/bus/InvalidAddressEndpoint.wsdl
___________________________________________________________________
Added: svn:mime-type
+ application/xml
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/bus/ValidAddressEndpoint.wsdl
===================================================================
(Binary files differ)
Property changes on:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/bus/ValidAddressEndpoint.wsdl
___________________________________________________________________
Added: svn:mime-type
+ application/xml