Author: thomas.diesler(a)jboss.com
Date: 2006-11-02 09:25:10 -0500 (Thu, 02 Nov 2006)
New Revision: 1342
Added:
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebAppClassLoaderDeployer.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebMetaDataAdaptor.java
Modified:
trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractDeployer.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractEJBDeployer.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/DeploymentInfoAdaptor.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerEJB3.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerJSE.java
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointGeneratorEJB.java
trunk/src/main/resources/jbossws.deployer/META-INF/deployer-beans.xml
Log:
JAXWS JSE deployer, more to come
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractDeployer.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractDeployer.java 2006-11-02
10:08:07 UTC (rev 1341)
+++ trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractDeployer.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -26,8 +26,10 @@
import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.registry.KernelRegistry;
import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+import org.jboss.ws.deployment.AbstractServiceEndpointPublisher;
import org.jboss.ws.deployment.ServiceEndpointDeployer;
import org.jboss.ws.deployment.UnifiedDeploymentInfo;
import org.jboss.ws.server.KernelLocator;
@@ -40,10 +42,22 @@
*/
public abstract class AbstractDeployer extends AbstractSimpleDeployer
{
+ private Kernel kernel;
+
+ public Kernel getKernel()
+ {
+ return kernel;
+ }
+
+ public void setKernel(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+
@Override
public void deploy(DeploymentUnit unit) throws DeploymentException
{
- if (isWebserviceDeployment(unit))
+ if (isRelevant(unit))
{
UnifiedDeploymentInfo udi = createUnifiedDeploymentInfo(unit);
String attachmentKey = getClass().getName() + ":" + unit.getName();
@@ -88,6 +102,8 @@
}
}
+ protected abstract UnifiedDeploymentInfo createUnifiedDeploymentInfo(DeploymentUnit
unit);
+
protected void createServiceEndpoint(UnifiedDeploymentInfo udi, DeploymentUnit unit)
throws Exception
{
log.debug("createServiceEndpoint: " + udi.getCanonicalName());
@@ -119,10 +135,13 @@
return (ServiceEndpointDeployer)entry.getTarget();
}
- protected abstract boolean isWebserviceDeployment(DeploymentUnit unit);
-
- protected abstract UnifiedDeploymentInfo createUnifiedDeploymentInfo(DeploymentUnit
unit);
-
+ protected ServiceEndpointPublisher getServiceEndpointPublisher()
+ {
+ KernelRegistry registry = KernelLocator.getKernel().getRegistry();
+ KernelRegistryEntry entry =
registry.getEntry(AbstractServiceEndpointPublisher.BEAN_NAME);
+ return (ServiceEndpointPublisher)entry.getTarget();
+ }
+
protected UnifiedDeploymentInfo getUnifiedDeploymentInfo(DeploymentUnit unit)
{
String attachmentKey = getClass().getName() + ":" + unit.getName();
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractEJBDeployer.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractEJBDeployer.java 2006-11-02
10:08:07 UTC (rev 1341)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/AbstractEJBDeployer.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -60,12 +60,5 @@
super.destroyServiceEndpoint(udi, unit);
}
- protected ServiceEndpointPublisher getServiceEndpointPublisher()
- {
- KernelRegistry registry = KernelLocator.getKernel().getRegistry();
- KernelRegistryEntry entry =
registry.getEntry(AbstractServiceEndpointPublisher.BEAN_NAME);
- return (ServiceEndpointPublisher)entry.getTarget();
- }
-
protected abstract URL generateWebDeployment(UnifiedMetaData wsMetaData,
DeploymentUnit unit);
}
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss50/DeploymentInfoAdaptor.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/integration/jboss50/DeploymentInfoAdaptor.java 2006-11-02
10:08:07 UTC (rev 1341)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/DeploymentInfoAdaptor.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -22,10 +22,12 @@
package org.jboss.ws.integration.jboss50;
import java.net.URL;
+import java.util.Set;
import org.jboss.deployers.spi.deployer.DeploymentUnit;
import org.jboss.ejb3.Ejb3Deployment;
import org.jboss.logging.Logger;
+import org.jboss.metadata.WebMetaData;
import org.jboss.ws.deployment.UnifiedDeploymentInfo;
// $Id$
@@ -92,12 +94,15 @@
{
metaData = ApplicationMetaDataAdaptor.buildUnifiedApplicationMetaData(unit);
}
- /*
- if (metaData instanceof WebMetaData)
+ else
{
- retMetaData =
WebMetaDataAdaptor.buildUnifiedWebMetaData((WebMetaData)metaData);
+ Set<? extends WebMetaData> allMetaData =
unit.getAllMetaData(WebMetaData.class);
+ if (allMetaData.size() > 0)
+ {
+ metaData = allMetaData.iterator().next();
+ metaData =
WebMetaDataAdaptor.buildUnifiedWebMetaData((WebMetaData)metaData);
+ }
}
- */
return metaData;
}
}
Modified: trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerEJB3.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerEJB3.java 2006-11-02
10:08:07 UTC (rev 1341)
+++ trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerEJB3.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -53,9 +53,9 @@
}
@Override
- protected boolean isWebserviceDeployment(DeploymentUnit unit)
+ public boolean isRelevant(DeploymentUnit unit)
{
- boolean isWebserviceDeployment = false;
+ boolean isRelevant = false;
Ejb3Deployment ejb3Deployment = unit.getAttachment(Ejb3Deployment.class);
if (ejb3Deployment != null)
@@ -66,13 +66,13 @@
EJBContainer container = (EJBContainer)it.next();
if (container instanceof StatelessContainer &&
container.resolveAnnotation(WebService.class) != null)
{
- isWebserviceDeployment = true;
+ isRelevant = true;
break;
}
}
}
- return isWebserviceDeployment;
+ return isRelevant;
}
protected URL generateWebDeployment(UnifiedMetaData wsMetaData, DeploymentUnit unit)
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
10:08:07 UTC (rev 1341)
+++ trunk/src/main/java/org/jboss/ws/integration/jboss50/JAXWSDeployerJSE.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -23,29 +23,35 @@
//$Id$
-import java.net.URL;
import java.util.Iterator;
import java.util.Set;
import javax.jws.WebService;
import org.jboss.deployers.spi.deployer.DeploymentUnit;
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.stateless.StatelessContainer;
+import org.jboss.metadata.NameValuePair;
import org.jboss.metadata.WebMetaData;
+import org.jboss.metadata.web.Servlet;
import org.jboss.ws.deployment.JSR181Deployment;
import org.jboss.ws.deployment.UnifiedDeploymentInfo;
-import org.jboss.ws.metadata.UnifiedMetaData;
/**
- * A deployer JAXWS EJB3 Endpoints
+ * A deployer JAXWS JSE Endpoints
*
* @author Thomas.Diesler(a)jboss.org
* @since 31-Oct-2005
*/
public class JAXWSDeployerJSE extends AbstractJSEDeployer
{
+ // The servlet init param in web.xml that is the service endpoint class
+ public static final String INIT_PARAM_SERVICE_ENDPOINT_IMPL =
"ServiceEndpointImpl";
+
+ // The default relative order after the JBossWebAppParsingDeployer
+ public int getRelativeOrder()
+ {
+ return PARSER_DEPLOYER + 3;
+ }
+
@Override
protected UnifiedDeploymentInfo createUnifiedDeploymentInfo(DeploymentUnit unit)
{
@@ -55,16 +61,59 @@
}
@Override
- protected boolean isWebserviceDeployment(DeploymentUnit unit)
+ public boolean isRelevant(DeploymentUnit unit)
{
- boolean isWebserviceDeployment = false;
+ boolean isRelevant = false;
Set<? extends WebMetaData> allMetaData =
unit.getAllMetaData(WebMetaData.class);
if (allMetaData.size() > 0)
{
- log.debug("unit: " + unit.getName());
+ WebMetaData webMetaData = allMetaData.iterator().next();
+ if (allMetaData.size() > 1)
+ log.warn("More than one WebMetaData not supported");
+
+ try
+ {
+ ClassLoader anLoader = unit.getClassLoader();
+ String serviceEndpointServlet =
getServiceEndpointPublisher().getServiceEndpointServlet();
+
+ Iterator it = webMetaData.getServlets().iterator();
+ while (it.hasNext())
+ {
+ Servlet servlet = (Servlet)it.next();
+ String beanName = servlet.getServletClass();
+ Class<?> servletClass = anLoader.loadClass(beanName);
+ if (servletClass.isAnnotationPresent(WebService.class))
+ {
+ // Nothing to do if we have an <init-param>
+ if (isAlreadyModified(servlet) == false)
+ {
+ servlet.setServletClass(serviceEndpointServlet);
+ NameValuePair initParam = new
NameValuePair(INIT_PARAM_SERVICE_ENDPOINT_IMPL, beanName);
+ servlet.addInitParam(initParam);
+ }
+ isRelevant = true;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ log.error("Cannot process web deployment", ex);
+ }
}
- return isWebserviceDeployment;
+ return isRelevant;
}
+
+ private boolean isAlreadyModified(Servlet servlet)
+ {
+ Iterator itParams = servlet.getInitParams().iterator();
+ while (itParams.hasNext())
+ {
+ NameValuePair pair = (NameValuePair)itParams.next();
+ if (INIT_PARAM_SERVICE_ENDPOINT_IMPL.equals(pair.getName()))
+ return true;
+ }
+ return false;
+ }
}
Modified:
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointGeneratorEJB.java
===================================================================
---
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointGeneratorEJB.java 2006-11-02
10:08:07 UTC (rev 1341)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/ServiceEndpointGeneratorEJB.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -56,7 +56,7 @@
public URL generatWebDeployment(UnifiedMetaData wsMetaData, DeploymentUnit unit)
{
- // Collect the list of PortComponentMetaData
+ // Collect the list of EndpointMetaData
List<EndpointMetaData> epMetaDataList = new
ArrayList<EndpointMetaData>();
for (ServiceMetaData serviceMetaData : wsMetaData.getServices())
{
Added:
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
10:08:07 UTC (rev 1341)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebAppClassLoaderDeployer.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -0,0 +1,189 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ws.integration.jboss50;
+
+//$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.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+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;
+
+/**
+ * A deployer that adds a webapp class loader to the depployment unit
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 31-Oct-2005
+ */
+public class WebAppClassLoaderDeployer extends AbstractSimpleDeployer
+{
+ // The default relative order after the JBossWebAppParsingDeployer
+ public int getRelativeOrder()
+ {
+ return PARSER_DEPLOYER + 2;
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ ClassLoader classLoader = null;
+ try
+ {
+ // This throws a RTE if the loader was not set
+ classLoader = unit.getClassLoader();
+ }
+ catch (Exception ex)
+ {
+ // ignore
+ }
+
+
+ if (classLoader == null)
+ {
+ unit.getDeploymentContext().createClassLoader(new WebAppClassLoaderFactory());
+ }
+ }
+
+ 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)
+ {
+ 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);
+ }
+ }
+ };
+
+ return classLoader;
+ }
+
+ public void removeClassLoader(DeploymentContext context) throws Exception
+ {
+ log.debug("removeClassLoader: " + context.getRoot());
+ this.classLoader = null;
+ }
+ }
+}
Property changes on:
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebAppClassLoaderDeployer.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: 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
10:08:07 UTC (rev 1341)
+++
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebMetaDataAdaptor.java 2006-11-02
14:25:10 UTC (rev 1342)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ws.integration.jboss50;
+
+// $Id$
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.jboss.metadata.WebMetaData;
+import org.jboss.metadata.web.ServletMapping;
+import org.jboss.ws.metadata.j2ee.UnifiedWebMetaData;
+
+/**
+ * Build container independent web meta data
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 05-May-2006
+ */
+public class WebMetaDataAdaptor
+{
+ public static UnifiedWebMetaData buildUnifiedWebMetaData(WebMetaData wmd)
+ {
+ UnifiedWebMetaData umd = new UnifiedWebMetaData();
+ umd.setContextRoot(wmd.getContextRoot());
+ umd.setServletMappings(getServletMappings(wmd));
+ umd.setServletClassMap(wmd.getServletClassMap());
+ umd.setConfigName(wmd.getConfigName());
+ umd.setConfigFile(wmd.getConfigFile());
+ umd.setContextLoader(wmd.getContextLoader());
+ umd.setSecurityDomain(wmd.getSecurityDomain());
+ //umd.setWsdlPublishLocationMap(wmd.getWsdlPublishLocationMap());
+ return umd;
+ }
+
+ private static Map<String, String> getServletMappings(WebMetaData wmd)
+ {
+ Map<String, String> mappings = new HashMap<String, String>();
+ Iterator it = wmd.getServletMappings().iterator();
+ while(it.hasNext())
+ {
+ ServletMapping sm = (ServletMapping)it.next();
+ mappings.put(sm.getName(), sm.getUrlPattern());
+ }
+ return mappings;
+ }
+}
Property changes on:
trunk/src/main/java/org/jboss/ws/integration/jboss50/WebMetaDataAdaptor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
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
10:08:07 UTC (rev 1341)
+++ trunk/src/main/resources/jbossws.deployer/META-INF/deployer-beans.xml 2006-11-02
14:25:10 UTC (rev 1342)
@@ -13,10 +13,24 @@
<this/>
</parameter>
</uninstall>
+ <property name="kernel"><inject
bean="jboss.kernel:service=Kernel"/></property>
<depends>EJBRegistrationDeployer</depends>
- <depends>WarDeployer</depends>
+ <depends>JBossWebAppParsingDeployer</depends>
</bean>
+ <bean name="WebAppClassLoaderDeployer"
class="org.jboss.ws.integration.jboss50.WebAppClassLoaderDeployer">
+ <install bean="MainDeployer" method="addDeployer">
+ <parameter>
+ <this/>
+ </parameter>
+ </install>
+ <uninstall bean="MainDeployer" method="removeDeployer">
+ <parameter>
+ <this/>
+ </parameter>
+ </uninstall>
+ </bean>
+
<bean name="JAXWSDeployerJSE"
class="org.jboss.ws.integration.jboss50.JAXWSDeployerJSE">
<install bean="MainDeployer" method="addDeployer">
<parameter>
@@ -28,7 +42,9 @@
<this/>
</parameter>
</uninstall>
- <depends>WarDeployer</depends>
+ <property name="kernel"><inject
bean="jboss.kernel:service=Kernel"/></property>
+ <depends>WebAppClassLoaderDeployer</depends>
+ <depends>JBossWebAppParsingDeployer</depends>
</bean>
</deployment>
\ No newline at end of file