Author: thomas.diesler(a)jboss.com
Date: 2006-11-02 10:17:07 -0500 (Thu, 02 Nov 2006)
New Revision: 1343
Modified:
trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerJSE.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebAppClassLoaderDeployer.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebMetaDataAdaptor.java
trunk/src/main/resources/jbossws.deployer/META-INF/deployer-beans.xml
Log:
Tmporarily install webapp classloaader
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerJSE.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerJSE.java 2006-11-02
14:25:10 UTC (rev 1342)
+++ trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerJSE.java 2006-11-02
15:17:07 UTC (rev 1343)
@@ -23,12 +23,24 @@
//$Id$
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
import javax.jws.WebService;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.logging.Logger;
import org.jboss.metadata.NameValuePair;
import org.jboss.metadata.WebMetaData;
import org.jboss.metadata.web.Servlet;
@@ -61,6 +73,31 @@
}
@Override
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ boolean removeLoader = false;
+ try
+ {
+ unit.getClassLoader();
+ }
+ catch (Exception ex)
+ {
+ unit.getDeploymentContext().createClassLoader(new WebAppClassLoaderFactory());
+ removeLoader = true;
+ }
+
+ try
+ {
+ super.deploy(unit);
+ }
+ finally
+ {
+ if (removeLoader == true)
+ unit.getDeploymentContext().removeClassLoader();
+ }
+ }
+
+ @Override
public boolean isRelevant(DeploymentUnit unit)
{
boolean isRelevant = false;
@@ -116,4 +153,99 @@
}
return false;
}
+
+ static class WebAppClassLoaderFactory implements ClassLoaderFactory
+ {
+ // provide logging
+ private static Logger log = Logger.getLogger(WebAppClassLoaderFactory.class);
+
+ private ClassLoader classLoader;
+
+ public ClassLoader createClassLoader(DeploymentContext context) throws Exception
+ {
+ log.debug("createClassLoader: " + context.getRoot());
+
+ ArrayList<URL> list = new ArrayList<URL>();
+
+ URL warURL = context.getRoot().toURL();
+ String externalForm = warURL.toExternalForm();
+
+ if (externalForm.endsWith("!/"))
+ {
+ String fileName = warURL.getFile();
+ if (fileName.indexOf("!") > 0)
+ fileName = fileName.substring(0, fileName.indexOf("!"));
+
+ try
+ {
+ URL url = new URL(fileName);
+ fileName = url.getFile();
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ File warFile = new File(fileName);
+ if (warFile.exists())
+ {
+ ZipFile zipFile = new ZipFile(warFile);
+ Enumeration en = zipFile.entries();
+ while (en.hasMoreElements())
+ {
+ ZipEntry entry = (ZipEntry)en.nextElement();
+ String entryName = entry.getName();
+ if (entryName.equals("WEB-INF/classes/"))
+ {
+ URL classesURL = new URL(externalForm + entryName);
+ list.add(classesURL);
+ }
+ if (entryName.startsWith("WEB-INF/lib") &&
entryName.endsWith(".jar"))
+ {
+ URL jarURL = new URL(externalForm + entryName);
+ list.add(jarURL);
+ }
+ }
+ }
+ else
+ {
+ log.warn("WAR file does not exist: " + warFile);
+ }
+ }
+ else
+ {
+ String path = warURL.getFile();
+
+ File classesDir = new File(path, "WEB-INF/classes");
+ if (classesDir.exists())
+ list.add(classesDir.toURL());
+
+ File libDir = new File(path, "WEB-INF/lib");
+ if (libDir.exists())
+ {
+ File[] jars = libDir.listFiles();
+ int length = jars != null ? jars.length : 0;
+ for (int j = 0; j < length; j++)
+ {
+ File jar = jars[j];
+ if (jar.getAbsolutePath().endsWith(".jar"))
+ {
+ list.add(jar.toURL());
+ }
+ }
+ }
+ }
+
+ ClassLoader parent = Thread.currentThread().getContextClassLoader();
+ classLoader = new URLClassLoader(list.toArray(new URL[list.size()]), parent);
+
+ return classLoader;
+ }
+
+ public void removeClassLoader(DeploymentContext context) throws Exception
+ {
+ log.debug("removeClassLoader: " + context.getRoot());
+ this.classLoader = null;
+ }
+ }
}
Modified:
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebAppClassLoaderDeployer.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebAppClassLoaderDeployer.java 2006-11-02
14:25:10 UTC (rev 1342)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebAppClassLoaderDeployer.java 2006-11-02
15:17:07 UTC (rev 1343)
@@ -157,25 +157,7 @@
}
ClassLoader parent = Thread.currentThread().getContextClassLoader();
- classLoader = new URLClassLoader(list.toArray(new URL[list.size()]), parent)
- {
- protected synchronized Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
- {
- try
- {
- Class clazz = findClass(name);
- if (resolve)
- {
- resolveClass(clazz);
- }
- return clazz;
- }
- catch (ClassNotFoundException e)
- {
- return getParent().loadClass(name);
- }
- }
- };
+ classLoader = new URLClassLoader(list.toArray(new URL[list.size()]), parent);
return classLoader;
}
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss50/WebMetaDataAdaptor.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebMetaDataAdaptor.java 2006-11-02
14:25:10 UTC (rev 1342)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebMetaDataAdaptor.java 2006-11-02
15:17:07 UTC (rev 1343)
@@ -28,6 +28,7 @@
import java.util.Map;
import org.jboss.metadata.WebMetaData;
+import org.jboss.metadata.web.Servlet;
import org.jboss.metadata.web.ServletMapping;
import org.jboss.ws.metadata.j2ee.UnifiedWebMetaData;
@@ -44,7 +45,7 @@
UnifiedWebMetaData umd = new UnifiedWebMetaData();
umd.setContextRoot(wmd.getContextRoot());
umd.setServletMappings(getServletMappings(wmd));
- umd.setServletClassMap(wmd.getServletClassMap());
+ umd.setServletClassMap(getServletClassMap(wmd));
umd.setConfigName(wmd.getConfigName());
umd.setConfigFile(wmd.getConfigFile());
umd.setContextLoader(wmd.getContextLoader());
@@ -64,4 +65,16 @@
}
return mappings;
}
+
+ private static Map<String, String> getServletClassMap(WebMetaData wmd)
+ {
+ Map<String, String> mappings = new HashMap<String, String>();
+ Iterator it = wmd.getServlets().iterator();
+ while(it.hasNext())
+ {
+ Servlet servlet = (Servlet)it.next();
+ mappings.put(servlet.getName(), servlet.getServletClass());
+ }
+ return mappings;
+ }
}
Modified: trunk/src/main/resources/jbossws.deployer/META-INF/deployer-beans.xml
===================================================================
--- trunk/src/main/resources/jbossws.deployer/META-INF/deployer-beans.xml 2006-11-02
14:25:10 UTC (rev 1342)
+++ trunk/src/main/resources/jbossws.deployer/META-INF/deployer-beans.xml 2006-11-02
15:17:07 UTC (rev 1343)
@@ -18,6 +18,7 @@
<depends>JBossWebAppParsingDeployer</depends>
</bean>
+ <!--
<bean name="WebAppClassLoaderDeployer"
class="org.jboss.ws.integration.jboss50.WebAppClassLoaderDeployer">
<install bean="MainDeployer" method="addDeployer">
<parameter>
@@ -30,6 +31,7 @@
</parameter>
</uninstall>
</bean>
+ -->
<bean name="JAXWSDeployerJSE"
class="org.jboss.ws.integration.jboss50.JAXWSDeployerJSE">
<install bean="MainDeployer" method="addDeployer">
@@ -43,7 +45,6 @@
</parameter>
</uninstall>
<property name="kernel"><inject
bean="jboss.kernel:service=Kernel"/></property>
- <depends>WebAppClassLoaderDeployer</depends>
<depends>JBossWebAppParsingDeployer</depends>
</bean>
Show replies by date