[jbossws-commits] JBossWS SVN: r18435 - in stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws: cxf/httpauth and 1 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Feb 25 12:54:28 EST 2014


Author: asoldano
Date: 2014-02-25 12:54:28 -0500 (Tue, 25 Feb 2014)
New Revision: 18435

Modified:
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpauth/HelloDigestTestCase.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java
Log:
[JBWS-3768] Use new bus instances (and shutdown them) for tests modifying client conduits


Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java	2014-02-25 15:12:58 UTC (rev 18434)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java	2014-02-25 17:54:28 UTC (rev 18435)
@@ -74,25 +74,45 @@
    
    public boolean testGZIPUsingFeatureOnClient() throws Exception
    {
-      HelloWorld port = getPort();
-      Client client = ClientProxy.getClient(port);
-      GZIPFeature gzipFeature = new GZIPFeature();
-      gzipFeature.setThreshold(0);
-      gzipFeature.initialize(client, null); //bus parameter not actually used
-      return ("foo".equals(port.echo("foo")));
+      Bus bus = BusFactory.newInstance().createBus();
+      try
+      {
+         BusFactory.setThreadDefaultBus(bus);
+         
+         HelloWorld port = getPort();
+         Client client = ClientProxy.getClient(port);
+         GZIPFeature gzipFeature = new GZIPFeature();
+         gzipFeature.setThreshold(0);
+         gzipFeature.initialize(client, null); //bus parameter not actually used
+         return ("foo".equals(port.echo("foo")));
+      }
+      finally
+      {
+         bus.shutdown(true);
+      }
    }
    
    public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception
    {
-      HelloWorld port = getPort();
-      Client client = ClientProxy.getClient(port);
-      HTTPConduit conduit = (HTTPConduit)client.getConduit();
-      HTTPClientPolicy policy = conduit.getClient();
-      //enable Accept gzip, otherwise the server will not try to reply using gzip
-      policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
-      //add interceptor for decoding gzip message
-      client.getInInterceptors().add(new GZIPEnforcingInInterceptor());
-      return ("foo".equals(port.echo("foo")));
+      Bus bus = BusFactory.newInstance().createBus();
+      try
+      {
+         BusFactory.setThreadDefaultBus(bus);
+         
+         HelloWorld port = getPort();
+         Client client = ClientProxy.getClient(port);
+         HTTPConduit conduit = (HTTPConduit)client.getConduit();
+         HTTPClientPolicy policy = conduit.getClient();
+         //enable Accept gzip, otherwise the server will not try to reply using gzip
+         policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
+         //add interceptor for decoding gzip message
+         client.getInInterceptors().add(new GZIPEnforcingInInterceptor());
+         return ("foo".equals(port.echo("foo")));
+      }
+      finally
+      {
+         bus.shutdown(true);
+      }
    }
    
    public boolean testFailureGZIPServerSideOnlyInterceptorOnClient() throws Exception

Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpauth/HelloDigestTestCase.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpauth/HelloDigestTestCase.java	2014-02-25 15:12:58 UTC (rev 18434)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpauth/HelloDigestTestCase.java	2014-02-25 17:54:28 UTC (rev 18435)
@@ -31,9 +31,12 @@
 
 import junit.framework.Test;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transport.http.auth.DigestAuthSupplier;
+import org.jboss.wsf.stack.cxf.client.UseThreadBusFeature;
 import org.jboss.wsf.test.JBossWSCXFTestSetup;
 import org.jboss.wsf.test.JBossWSTest;
 
@@ -65,36 +68,47 @@
 
    public void testDigest() throws Exception
    {
-      QName serviceName = new QName("http://jboss.org/http/security", "HelloService");
-      URL wsdlURL = getResourceURL("jaxws/cxf/httpauth/WEB-INF/wsdl/hello.wsdl");
-      Service service = Service.create(wsdlURL, serviceName);
-      Hello proxy = (Hello)service.getPort(Hello.class);
-      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
-      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jbossws");
-      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "jbossws");
-      HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
-      cond.setAuthSupplier(new DigestAuthSupplier());
-      int result = proxy.helloRequest("number");
-      assertEquals(100, result);
-      
+      final Bus bus = BusFactory.newInstance().createBus();
+      BusFactory.setThreadDefaultBus(bus);
+      try {
+         QName serviceName = new QName("http://jboss.org/http/security", "HelloService");
+         URL wsdlURL = getResourceURL("jaxws/cxf/httpauth/WEB-INF/wsdl/hello.wsdl");
+         Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
+         Hello proxy = (Hello)service.getPort(Hello.class);
+         ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
+         ((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jbossws");
+         ((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "jbossws");
+         HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
+         cond.setAuthSupplier(new DigestAuthSupplier());
+         int result = proxy.helloRequest("number");
+         assertEquals(100, result);
+      } finally {
+         bus.shutdown(true);
+      }
    }
    
    public void testDigestAuthFail() throws Exception
    {
-      QName serviceName = new QName("http://jboss.org/http/security", "HelloService");
-      URL wsdlURL = getResourceURL("jaxws/cxf/httpauth/WEB-INF/wsdl/hello.wsdl");
-      Service service = Service.create(wsdlURL, serviceName);
-      Hello proxy = (Hello)service.getPort(Hello.class);
-      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
-      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jbossws");
-      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "wrongPwd");
-      HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
-      cond.setAuthSupplier(new DigestAuthSupplier());
+      final Bus bus = BusFactory.newInstance().createBus();
+      BusFactory.setThreadDefaultBus(bus);
       try {
-         proxy.helloRequest("number");
-         fail("Authorization exception expected!");
-      } catch (Exception e) {
-         assertTrue(e.getCause().getMessage().contains("Authorization"));
+         QName serviceName = new QName("http://jboss.org/http/security", "HelloService");
+         URL wsdlURL = getResourceURL("jaxws/cxf/httpauth/WEB-INF/wsdl/hello.wsdl");
+         Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
+         Hello proxy = (Hello)service.getPort(Hello.class);
+         ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
+         ((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jbossws");
+         ((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "wrongPwd");
+         HTTPConduit cond = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
+         cond.setAuthSupplier(new DigestAuthSupplier());
+         try {
+            proxy.helloRequest("number");
+            fail("Authorization exception expected!");
+         } catch (Exception e) {
+            assertTrue(e.getCause().getMessage().contains("Authorization"));
+         }
+      } finally {
+         bus.shutdown(true);
       }
    }
    

Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java	2014-02-25 15:12:58 UTC (rev 18434)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java	2014-02-25 17:54:28 UTC (rev 18435)
@@ -32,10 +32,13 @@
 
 import junit.framework.Test;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.jboss.wsf.stack.cxf.client.UseThreadBusFeature;
 import org.jboss.wsf.test.JBossWSCXFTestSetup;
 import org.jboss.wsf.test.JBossWSTest;
 
@@ -99,31 +102,37 @@
     */
    public void testDecoupledEndpointForLongLastingProcessingOfInvocations() throws Exception
    {
-      // construct proxy
-      QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing", "AddressingService");
-      URL wsdlURL = new URL(serviceURL + "?wsdl");
-      Service service = Service.create(wsdlURL, serviceName);
-      ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
-      
-      Client client = ClientProxy.getClient(proxy);
-      HTTPConduit conduit = (HTTPConduit)client.getConduit();
-      HTTPClientPolicy policy = conduit.getClient();
-      //set low connection and receive timeouts to ensure the http client can't keep the connection open till the response is received
-      policy.setConnectionTimeout(5000); //5 secs
-      policy.setReceiveTimeout(10000); //10 secs
-      //please note you might want to set the synchronous timeout for long waits, as CXF ClientImpl would simply drop waiting for the response after that (default 60 secs)
-//      ((ClientImpl)client).setSynchronousTimeout(value);
-      
+      final Bus bus = BusFactory.newInstance().createBus();
+      BusFactory.setThreadDefaultBus(bus);
       try {
-         proxy.sayHello("Sleepy"); //this takes at least 30 secs
-         fail("Timeout exception expected");
-      } catch (WebServiceException e) {
-         assertTrue(e.getCause() instanceof SocketTimeoutException);
+         // construct proxy
+         QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing", "AddressingService");
+         URL wsdlURL = new URL(serviceURL + "?wsdl");
+         Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
+         ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
+         
+         Client client = ClientProxy.getClient(proxy);
+         HTTPConduit conduit = (HTTPConduit)client.getConduit();
+         HTTPClientPolicy policy = conduit.getClient();
+         //set low connection and receive timeouts to ensure the http client can't keep the connection open till the response is received
+         policy.setConnectionTimeout(5000); //5 secs
+         policy.setReceiveTimeout(10000); //10 secs
+         //please note you might want to set the synchronous timeout for long waits, as CXF ClientImpl would simply drop waiting for the response after that (default 60 secs)
+//          ((ClientImpl)client).setSynchronousTimeout(value);
+         
+         try {
+            proxy.sayHello("Sleepy"); //this takes at least 30 secs
+            fail("Timeout exception expected");
+         } catch (WebServiceException e) {
+            assertTrue(e.getCause() instanceof SocketTimeoutException);
+         }
+         
+         policy.setDecoupledEndpoint("http://" + getServerHost() + ":18181/jaxws-samples-wsa/decoupled-endpoint");
+         String response = proxy.sayHello("Sleepy"); //this takes at least 30 secs... but now the client doesn't time out
+         assertEquals("Hello Sleepy!", response);
+      } finally {
+         bus.shutdown(true);
       }
-      
-      policy.setDecoupledEndpoint("http://" + getServerHost() + ":18181/jaxws-samples-wsa/decoupled-endpoint");
-      String response = proxy.sayHello("Sleepy"); //this takes at least 30 secs... but now the client doesn't time out
-      assertEquals("Hello Sleepy!", response);
    }
    
    



More information about the jbossws-commits mailing list