[jbossws-commits] JBossWS SVN: r13796 - shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Thu Feb 24 10:25:48 EST 2011


Author: alessio.soldano at jboss.com
Date: 2011-02-24 10:25:48 -0500 (Thu, 24 Feb 2011)
New Revision: 13796

Modified:
   shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/Client.java
   shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/EndpointTestCase.java
   shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/TestServlet.java
Log:
[JBWS-3223] Verifying TCCL invariance and that the TCCL for basic servlets does not "see" jbossws impl classes on AS 7


Modified: shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/Client.java
===================================================================
--- shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/Client.java	2011-02-24 15:24:32 UTC (rev 13795)
+++ shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/Client.java	2011-02-24 15:25:48 UTC (rev 13796)
@@ -22,20 +22,127 @@
 package org.jboss.test.ws.jaxws.jbws3223;
 
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import javax.xml.namespace.QName;
-import javax.xml.ws.Endpoint;
 import javax.xml.ws.Service;
+import javax.xml.ws.spi.Provider;
 
 public class Client
 {
+   private boolean checkClassLoader;
+   
+   public Client(boolean checkClassLoader)
+   {
+      this.checkClassLoader = checkClassLoader;
+   }
+   
    public String run(String param, URL wsdlURL)
    {
-      // Create the port
-      QName qname = new QName("http://org.jboss.ws/jaxws/jbws3223", "EndpointService");
-      Service service = Service.create(wsdlURL, qname);
-      EndpointInterface port = (EndpointInterface)service.getPort(EndpointInterface.class);
+      ClassLoader orig = getContextClassLoader();
+      try
+      {
+         // Create the port
+         QName qname = new QName("http://org.jboss.ws/jaxws/jbws3223", "EndpointService");
+         Service service = Service.create(wsdlURL, qname);
+         checkContextClassLoaderInvariance(orig);
+         EndpointInterface port = (EndpointInterface) service.getPort(EndpointInterface.class);
+         checkContextClassLoaderInvariance(orig);
+         String result = port.echo(param);
+         checkContextClassLoaderInvariance(orig);
+         if (checkClassLoader)
+         {
+            checkImplementationClassesAreNotVisible(orig);
+         }
+         return result;
+      }
+      finally
+      {
+         //set back the original TCCL: this is just a sanity fix to ensure a failure in this
+         //test does not influence other tests; the TCCL is not expected to be changed
+         setContextClassLoader(orig);
+      }
+   }
 
-      return port.echo(param);
+   private static void checkContextClassLoaderInvariance(ClassLoader reference)
+   {
+      ClassLoader tccl = getContextClassLoader();
+      if (reference == null && tccl == null)
+      {
+         return;
+      }
+      if (reference == null || tccl == null || !tccl.equals(reference))
+      {
+         throw new RuntimeException("Thread context classloader changed from " + reference + " to " + tccl);
+      }
    }
+   
+   /**
+    * AS7 check on client TCCL
+    * 
+    * @param cl
+    */
+   private void checkImplementationClassesAreNotVisible(ClassLoader cl)
+   {
+      //retrieve the stack specific Provider impl class name through the JAXWS API
+      //classloading mechanism (JBEE-75), which is able to "see" implementation classes
+      String providerImplClassName = Provider.provider().getClass().getName();
+      if (!providerImplClassName.contains("jboss"))
+      {
+         throw new RuntimeException("Expected a JBoss(WS) specific implementation for javax.xml.ws.spi.Provider: "
+               + providerImplClassName);
+      }
+      //then try loading the same class using the provided classloader
+      try
+      {
+         cl.loadClass(providerImplClassName);
+         throw new RuntimeException("ClassLoader " + cl + " should not be able to load " + providerImplClassName);
+      }
+      catch (ClassNotFoundException e)
+      {
+         //this is expected, just check the class that can't be found is our impl
+         if (!(e.getMessage().contains(providerImplClassName)))
+         {
+            throw new RuntimeException("Unexpected Provider implementation being looked up: " + e.getMessage());
+         }
+      }
+   }
+   
+   static ClassLoader getContextClassLoader()
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if (sm == null)
+      {
+         return Thread.currentThread().getContextClassLoader();
+      }
+      else
+      {
+         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+            public ClassLoader run()
+            {
+               return Thread.currentThread().getContextClassLoader();
+            }
+         });
+      }
+   }
+   
+   static void setContextClassLoader(final ClassLoader classLoader)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         Thread.currentThread().setContextClassLoader(classLoader);
+      }
+      else
+      {
+         AccessController.doPrivileged(new PrivilegedAction<Object>()
+         {
+            public Object run()
+            {
+               Thread.currentThread().setContextClassLoader(classLoader);
+               return null;
+            }
+         });
+      }
+   }
 }

Modified: shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/EndpointTestCase.java
===================================================================
--- shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/EndpointTestCase.java	2011-02-24 15:24:32 UTC (rev 13795)
+++ shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/EndpointTestCase.java	2011-02-24 15:25:48 UTC (rev 13796)
@@ -1,6 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2011, 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.
  *
@@ -28,8 +28,6 @@
 import javax.wsdl.Definition;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
-import javax.xml.namespace.QName;
-import javax.xml.ws.Service;
 
 import junit.extensions.TestSetup;
 import junit.framework.Test;
@@ -59,14 +57,15 @@
    public void testClientAccess() throws Exception
    {
       String helloWorld = "Hello world!";
-      Client client = new Client();
+      Client client = new Client(false);
       Object retObj = client.run(helloWorld, getResourceURL("jaxws/jbws3223/WEB-INF/wsdl/TestService.wsdl"));
       assertEquals(helloWorld, retObj);
    }
 
    public void testServletAccess() throws Exception
    {
-      URL url = new URL("http://" + getServerHost() + ":8080/jaxws-jbws3223-servlet?param=hello-world");
+      boolean clCheck = !(isTargetJBoss5() || isTargetJBoss6());
+      URL url = new URL("http://" + getServerHost() + ":8080/jaxws-jbws3223-servlet?param=hello-world&clCheck=" + clCheck);
       BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
       assertEquals("hello-world", br.readLine());
    }

Modified: shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/TestServlet.java
===================================================================
--- shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/TestServlet.java	2011-02-24 15:24:32 UTC (rev 13795)
+++ shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws3223/TestServlet.java	2011-02-24 15:25:48 UTC (rev 13796)
@@ -25,6 +25,8 @@
 import java.io.PrintWriter;
 
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -38,7 +40,8 @@
    {
       // Invoke the endpoint
       String param = req.getParameter("param");
-      Client client = new Client();
+      boolean clCheck = Boolean.parseBoolean(req.getParameter("clCheck"));
+      Client client = new Client(clCheck);
       //URL wsdlURL = getServletContext().getResource("/WEB-INF/wsdl/TestService.wsdl");
       URL wsdlURL = new URL("http://localhost:8080/jaxws-jbws3223?wsdl");
       String retStr = client.run(param, wsdlURL);
@@ -48,4 +51,6 @@
       pw.print(retStr);
       pw.close();
    }
+   
+   
 }



More information about the jbossws-commits mailing list