[jboss-cvs] JBossAS SVN: r69975 - in trunk/webservices: src/main/org/jboss/wsf/container/jboss50 and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 20 09:45:56 EST 2008


Author: thomas.diesler at jboss.com
Date: 2008-02-20 09:45:56 -0500 (Wed, 20 Feb 2008)
New Revision: 69975

Added:
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/FileBasedWebMetaDataModifier.java
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/InMemoryWebMetaDataModifier.java
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebMetaDataModifier.java
Removed:
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/DefaultWebAppDesciptorModifierImpl.java
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDesciptorModifier.java
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebXMLRewriterImpl.java
Modified:
   trunk/webservices/build.xml
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/AbstractDeployerHookJSE.java
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ContainerMetaDataAdapter.java
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ModifyWebMetaDataDeploymentAspect.java
   trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDeploymentAspect.java
   trunk/webservices/src/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-beans.xml
Log:
Add InMemoryWebMetaDataModifier

Modified: trunk/webservices/build.xml
===================================================================
--- trunk/webservices/build.xml	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/build.xml	2008-02-20 14:45:56 UTC (rev 69975)
@@ -139,7 +139,7 @@
   <!-- 
      |  Build all jar files.
   -->
-  <target name="module-jars" >
+  <target name="module-jars" depends="compile">
 
     <!-- Build jbossws-jboss50.jar -->
     <jar jarfile="${build.lib}/jbossws-jboss50.jar" manifest="${build.etc}/default.mf">
@@ -171,4 +171,19 @@
 	  
   </target>
 
+  <!-- ================================================================== -->
+  <!-- Deployment                                                         -->
+  <!-- ================================================================== -->
+
+  <!-- 
+     |  Build all jar files.
+  -->
+  <target name="deploy" depends="module-jars">
+
+
+    <!-- Build jbossws-native50.deployer -->
+    <unzip dest="../build/output/jboss-${specification.version}/server/default/deployers/jbossws.deployer" src="${build.lib}/jbossws-jboss50-deployer.zip">
+    </unzip>
+    
+  </target>
 </project>

Modified: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/AbstractDeployerHookJSE.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/AbstractDeployerHookJSE.java	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/AbstractDeployerHookJSE.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -42,7 +42,7 @@
    public boolean isWebServiceDeployment(DeploymentUnit unit)
    {
       JBossWebMetaData webMetaData = unit.getAttachment(JBossWebMetaData.class);
-      boolean isGenerated = Boolean.TRUE.equals(unit.getAttachment(WebAppDesciptorModifier.PROPERTY_GENERATED_WEBAPP));
+      boolean isGenerated = Boolean.TRUE.equals(unit.getAttachment(WebMetaDataModifier.PROPERTY_GENERATED_WEBAPP));
       return webMetaData != null && isGenerated == false;
    }
 

Modified: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ContainerMetaDataAdapter.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ContainerMetaDataAdapter.java	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ContainerMetaDataAdapter.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -81,7 +81,7 @@
             if (dep instanceof ArchiveDeployment)
             {
                URL webURL = ((ArchiveDeployment)dep).getRootFile().toURL();
-               dep.setProperty(WebAppDesciptorModifier.PROPERTY_WEBAPP_URL, webURL);
+               dep.setProperty(WebMetaDataModifier.PROPERTY_WEBAPP_URL, webURL);
             }
          }
          

Deleted: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/DefaultWebAppDesciptorModifierImpl.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/DefaultWebAppDesciptorModifierImpl.java	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/DefaultWebAppDesciptorModifierImpl.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -1,168 +0,0 @@
-/*
- * 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.wsf.container.jboss50;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.jboss.logging.Logger;
-import org.jboss.wsf.spi.deployment.Deployment;
-import org.jboss.wsf.spi.deployment.Endpoint;
-
-/**
- * Modifies web.xml for jbossws
- *
- * @author Thomas.Diesler at jboss.org
- * @since 19-May-2006
- */
-public class DefaultWebAppDesciptorModifierImpl implements WebAppDesciptorModifier
-{
-   // logging support
-   private static Logger log = Logger.getLogger(DefaultWebAppDesciptorModifierImpl.class);
-
-   public RewriteResults modifyDescriptor(Deployment dep, Document webXml) throws ClassNotFoundException
-   {
-      RewriteResults results = new RewriteResults();
-      Element root = webXml.getRootElement();
-
-      String servletClass = (String)dep.getProperty(PROPERTY_WEBAPP_SERVLET_CLASS);
-      if (servletClass == null)
-         throw new IllegalStateException("Cannot obtain context property: " + PROPERTY_WEBAPP_SERVLET_CLASS);
-
-      Map<String, String> contextParams = (Map<String, String>)dep.getProperty(PROPERTY_WEBAPP_CONTEXT_PARAMETERS);
-      if (contextParams != null)
-      {
-         for (Map.Entry<String, String> entry : contextParams.entrySet())
-         {
-            // Ugly way to insert at position 0
-            Element contextParamTmp = root.addElement("context-param-tmp");
-
-            Element contextParam = (Element)contextParamTmp.clone();
-            contextParam.setName("context-param");
-            contextParam.addElement("param-name").addText(entry.getKey());
-            contextParam.addElement("param-value").addText(entry.getValue());
-            root.content().add(0, contextParam);
-
-            root.remove(contextParamTmp);
-         }
-      }
-
-      String listenerClass = (String)dep.getProperty(PROPERTY_WEBAPP_SERVLET_CONTEXT_LISTENER);
-      if (listenerClass != null)
-      {
-         Element listener = root.addElement("listener");
-         listener.addElement("listener-class").setText(listenerClass);
-      }
-
-      for (Iterator it = root.elementIterator("servlet"); it.hasNext();)
-      {
-         Element servlet = (Element)it.next();
-         String linkName = servlet.element("servlet-name").getTextTrim();
-
-         // find the servlet-class
-         Element classElement = servlet.element("servlet-class");
-
-         // JSP
-         if (classElement == null)
-            continue;
-
-         String orgServletClassName = classElement.getTextTrim();
-
-         // Get the servlet class
-         Class orgServletClass = null;
-         try
-         {
-            ClassLoader loader = dep.getInitialClassLoader();
-            orgServletClass = loader.loadClass(orgServletClassName);
-         }
-         catch (ClassNotFoundException ex)
-         {
-            log.warn("Cannot load servlet class: " + orgServletClassName);
-         }
-
-         String targetBeanName = null;
-
-         // Nothing to do if we have an <init-param>
-         if (isAlreadyModified(servlet))
-         {
-            for (Iterator itParam = servlet.elementIterator("init-param"); itParam.hasNext();)
-            {
-               Element elParam = (Element)itParam.next();
-               String paramName = elParam.element("param-name").getTextTrim();
-               String paramValue = elParam.element("param-value").getTextTrim();
-               if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
-               {
-                  targetBeanName = paramValue;
-               }
-            }
-         }
-         else
-         {
-            // Check if it is a real servlet that we can ignore
-            if (orgServletClass != null && javax.servlet.Servlet.class.isAssignableFrom(orgServletClass))
-            {
-               log.info("Ignore servlet: " + orgServletClassName);
-               continue;
-            }
-            else if (orgServletClassName.endsWith("Servlet"))
-            {
-               log.info("Ignore <servlet-class> that ends with 'Servlet': " + orgServletClassName);
-               continue;
-            }
-
-            classElement.setText(servletClass);
-
-            // add additional init params
-            if (orgServletClassName.equals(servletClass) == false)
-            {
-               targetBeanName = orgServletClassName;
-               Element paramElement = servlet.addElement("init-param");
-               paramElement.addElement("param-name").addText(Endpoint.SEPID_DOMAIN_ENDPOINT);
-               paramElement.addElement("param-value").addText(targetBeanName);
-            }
-         }
-
-         if (targetBeanName == null)
-            throw new IllegalStateException("Cannot obtain service endpoint bean for: " + linkName);
-
-         // remember the target bean name
-         results.sepTargetMap.put(linkName, targetBeanName);
-      }
-
-      return results;
-   }
-
-   // Return true if the web.xml is already modified
-   private boolean isAlreadyModified(Element servlet)
-   {
-      for (Iterator it = servlet.elementIterator("init-param"); it.hasNext();)
-      {
-         Element elParam = (Element)it.next();
-         String paramName = elParam.element("param-name").getTextTrim();
-         if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
-            return true;
-      }
-      return false;
-   }
-}

Copied: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/FileBasedWebMetaDataModifier.java (from rev 69969, trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebXMLRewriterImpl.java)
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/FileBasedWebMetaDataModifier.java	                        (rev 0)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/FileBasedWebMetaDataModifier.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -0,0 +1,253 @@
+/*
+ * 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.wsf.container.jboss50;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.ws.WebServiceException;
+
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+import org.jboss.logging.Logger;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.wsf.common.IOUtils;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Endpoint;
+
+/**
+ * The rewriter for web.xml
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 19-May-2007
+ */
+public class FileBasedWebMetaDataModifier implements WebMetaDataModifier
+{
+   // logging support
+   private static Logger log = Logger.getLogger(FileBasedWebMetaDataModifier.class);
+
+   public RewriteResults modifyMetaData(Deployment dep)
+   {
+      URL warURL = (URL)dep.getProperty(WebMetaDataModifier.PROPERTY_WEBAPP_URL);
+      File warFile = new File(warURL.getFile());
+      if (warFile.isDirectory() == false)
+         throw new WebServiceException("Expected a war directory: " + warURL);
+
+      File webXML = new File(warURL.getFile() + "/WEB-INF/web.xml");
+      if (webXML.isFile() == false)
+         throw new WebServiceException("Cannot find web.xml: " + webXML);
+
+      try
+      {
+         // After redeployment there might be a stale copy of the original web.xml.org, we delete it
+         File orgWebXML = new File(webXML.getCanonicalPath() + ".org");
+         orgWebXML.delete();
+
+         // Rename the web.xml
+         if (webXML.renameTo(orgWebXML) == false)
+            throw new WebServiceException("Cannot rename web.xml: " + orgWebXML);
+
+         return rewriteWebXml(orgWebXML, webXML, dep);
+      }
+      catch (RuntimeException rte)
+      {
+         throw rte;
+      }
+      catch (Exception e)
+      {
+         throw new WebServiceException(e);
+      }
+   }
+
+   private RewriteResults rewriteWebXml(File input, File destFile, Deployment dep) throws Exception
+   {
+      if (destFile == null)
+      {
+         destFile = File.createTempFile("jbossws-alt-web", "xml", IOUtils.createTempDirectory());
+         destFile.deleteOnExit();
+      }
+
+      FileInputStream inputStream = null;
+      FileOutputStream outputStream = null;
+
+      try
+      {
+         SAXReader reader = new SAXReader();
+         reader.setEntityResolver(new JBossEntityResolver());
+
+         inputStream = new FileInputStream(input);
+         Document document = reader.read(inputStream);
+
+         RewriteResults results = modifyMetaData(dep, document);
+         results.webXML = destFile.toURL();
+
+         outputStream = new FileOutputStream(destFile);
+         OutputFormat format = OutputFormat.createPrettyPrint();
+         XMLWriter writer = new XMLWriter(outputStream, format);
+         writer.write(document);
+         writer.close();
+
+         return results;
+      }
+      finally
+      {
+         if (inputStream != null)
+            inputStream.close();
+
+         if (outputStream != null)
+            outputStream.close();
+      }
+   }
+
+   private RewriteResults modifyMetaData(Deployment dep, Document webXml) throws ClassNotFoundException
+   {
+      RewriteResults results = new RewriteResults();
+
+      Element root = webXml.getRootElement();
+
+      String servletClass = (String)dep.getProperty(PROPERTY_WEBAPP_SERVLET_CLASS);
+      if (servletClass == null)
+         throw new IllegalStateException("Cannot obtain context property: " + PROPERTY_WEBAPP_SERVLET_CLASS);
+
+      Map<String, String> contextParams = (Map<String, String>)dep.getProperty(PROPERTY_WEBAPP_CONTEXT_PARAMETERS);
+      if (contextParams != null)
+      {
+         for (Map.Entry<String, String> entry : contextParams.entrySet())
+         {
+            // Ugly way to insert at position 0
+            Element contextParamTmp = root.addElement("context-param-tmp");
+
+            Element contextParam = (Element)contextParamTmp.clone();
+            contextParam.setName("context-param");
+            contextParam.addElement("param-name").addText(entry.getKey());
+            contextParam.addElement("param-value").addText(entry.getValue());
+            root.content().add(0, contextParam);
+
+            root.remove(contextParamTmp);
+         }
+      }
+
+      String listenerClass = (String)dep.getProperty(PROPERTY_WEBAPP_SERVLET_CONTEXT_LISTENER);
+      if (listenerClass != null)
+      {
+         Element listener = root.addElement("listener");
+         listener.addElement("listener-class").setText(listenerClass);
+      }
+
+      for (Iterator it = root.elementIterator("servlet"); it.hasNext();)
+      {
+         Element servlet = (Element)it.next();
+         String linkName = servlet.element("servlet-name").getTextTrim();
+
+         // find the servlet-class
+         Element classElement = servlet.element("servlet-class");
+
+         // JSP
+         if (classElement == null)
+            continue;
+
+         String orgServletClassName = classElement.getTextTrim();
+
+         // Get the servlet class
+         Class orgServletClass = null;
+         try
+         {
+            ClassLoader loader = dep.getInitialClassLoader();
+            orgServletClass = loader.loadClass(orgServletClassName);
+         }
+         catch (ClassNotFoundException ex)
+         {
+            log.warn("Cannot load servlet class: " + orgServletClassName);
+         }
+
+         String targetBeanName = null;
+
+         // Nothing to do if we have an <init-param>
+         if (isAlreadyModified(servlet))
+         {
+            for (Iterator itParam = servlet.elementIterator("init-param"); itParam.hasNext();)
+            {
+               Element elParam = (Element)itParam.next();
+               String paramName = elParam.element("param-name").getTextTrim();
+               String paramValue = elParam.element("param-value").getTextTrim();
+               if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
+               {
+                  targetBeanName = paramValue;
+               }
+            }
+         }
+         else
+         {
+            // Check if it is a real servlet that we can ignore
+            if (orgServletClass != null && javax.servlet.Servlet.class.isAssignableFrom(orgServletClass))
+            {
+               log.info("Ignore servlet: " + orgServletClassName);
+               continue;
+            }
+            else if (orgServletClassName.endsWith("Servlet"))
+            {
+               log.info("Ignore <servlet-class> that ends with 'Servlet': " + orgServletClassName);
+               continue;
+            }
+
+            classElement.setText(servletClass);
+
+            // add additional init params
+            if (orgServletClassName.equals(servletClass) == false)
+            {
+               targetBeanName = orgServletClassName;
+               Element paramElement = servlet.addElement("init-param");
+               paramElement.addElement("param-name").addText(Endpoint.SEPID_DOMAIN_ENDPOINT);
+               paramElement.addElement("param-value").addText(targetBeanName);
+            }
+         }
+
+         if (targetBeanName == null)
+            throw new IllegalStateException("Cannot obtain service endpoint bean for: " + linkName);
+
+         // remember the target bean name
+         results.sepTargetMap.put(linkName, targetBeanName);
+      }
+
+      return results;
+   }
+
+   // Return true if the web.xml is already modified
+   private boolean isAlreadyModified(Element servlet)
+   {
+      for (Iterator it = servlet.elementIterator("init-param"); it.hasNext();)
+      {
+         Element elParam = (Element)it.next();
+         String paramName = elParam.element("param-name").getTextTrim();
+         if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
+            return true;
+      }
+      return false;
+   }
+}

Added: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/InMemoryWebMetaDataModifier.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/InMemoryWebMetaDataModifier.java	                        (rev 0)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/InMemoryWebMetaDataModifier.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -0,0 +1,205 @@
+/*
+ * 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.wsf.container.jboss50;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.ws.WebServiceException;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.javaee.spec.ParamValueMetaData;
+import org.jboss.metadata.web.jboss.JBossServletMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.metadata.web.spec.ListenerMetaData;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Endpoint;
+
+/**
+ * The rewriter for web.xml
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 19-May-2007
+ */
+public class InMemoryWebMetaDataModifier implements WebMetaDataModifier
+{
+   // logging support
+   private static Logger log = Logger.getLogger(InMemoryWebMetaDataModifier.class);
+
+   public RewriteResults modifyMetaData(Deployment dep)
+   {
+      JBossWebMetaData jbwmd = dep.getAttachment(JBossWebMetaData.class);
+      if (jbwmd == null)
+         throw new WebServiceException("Cannot find web meta data");
+
+      try
+      {
+         RewriteResults results = modifyMetaData(dep, jbwmd);
+         return results;
+      }
+      catch (RuntimeException rte)
+      {
+         throw rte;
+      }
+      catch (Exception e)
+      {
+         throw new WebServiceException(e);
+      }
+   }
+
+   private RewriteResults modifyMetaData(Deployment dep, JBossWebMetaData jbwmd) throws ClassNotFoundException
+   {
+      RewriteResults results = new RewriteResults();
+
+      String servletClass = (String)dep.getProperty(PROPERTY_WEBAPP_SERVLET_CLASS);
+      if (servletClass == null)
+         throw new IllegalStateException("Cannot obtain context property: " + PROPERTY_WEBAPP_SERVLET_CLASS);
+
+      Map<String, String> depCtxParams = (Map<String, String>)dep.getProperty(PROPERTY_WEBAPP_CONTEXT_PARAMETERS);
+      if (depCtxParams != null)
+      {
+         List<ParamValueMetaData> contextParams = jbwmd.getContextParams();
+         if (contextParams == null)
+         {
+            contextParams = new ArrayList<ParamValueMetaData>();
+            jbwmd.setContextParams(contextParams);
+         }
+
+         for (Map.Entry<String, String> entry : depCtxParams.entrySet())
+         {
+            ParamValueMetaData param = new ParamValueMetaData();
+            param.setParamName(entry.getKey());
+            param.setParamValue(entry.getValue());
+            contextParams.add(param);
+         }
+      }
+
+      String listenerClass = (String)dep.getProperty(PROPERTY_WEBAPP_SERVLET_CONTEXT_LISTENER);
+      if (listenerClass != null)
+      {
+         List<ListenerMetaData> listeners = jbwmd.getListeners();
+         if (listeners == null)
+         {
+            listeners = new ArrayList<ListenerMetaData>();
+            jbwmd.setListeners(listeners);
+         }
+         ListenerMetaData listener = new ListenerMetaData();
+         listener.setListenerClass(listenerClass);
+      }
+
+      for (Iterator it = jbwmd.getServlets().iterator(); it.hasNext();)
+      {
+         JBossServletMetaData servlet = (JBossServletMetaData)it.next();
+         List<ParamValueMetaData> initParams = servlet.getInitParam();
+         if (initParams == null)
+         {
+            initParams = new ArrayList<ParamValueMetaData>();
+            servlet.setInitParam(initParams);
+         }
+
+         String linkName = servlet.getServletName();
+
+         // find the servlet-class
+         String orgServletClassName = servlet.getServletClass();
+
+         // JSP
+         if (orgServletClassName == null)
+            continue;
+
+         // Get the servlet class
+         Class orgServletClass = null;
+         try
+         {
+            ClassLoader loader = dep.getInitialClassLoader();
+            orgServletClass = loader.loadClass(orgServletClassName);
+         }
+         catch (ClassNotFoundException ex)
+         {
+            log.warn("Cannot load servlet class: " + orgServletClassName);
+         }
+
+         String targetBeanName = null;
+
+         // Nothing to do if we have an <init-param>
+         if (isAlreadyModified(servlet))
+         {
+            for (ParamValueMetaData initParam : initParams)
+            {
+               String paramName = initParam.getParamName();
+               String paramValue = initParam.getParamValue();
+               if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
+               {
+                  targetBeanName = paramValue;
+               }
+            }
+         }
+         else
+         {
+            // Check if it is a real servlet that we can ignore
+            if (orgServletClass != null && javax.servlet.Servlet.class.isAssignableFrom(orgServletClass))
+            {
+               log.info("Ignore servlet: " + orgServletClassName);
+               continue;
+            }
+            else if (orgServletClassName.endsWith("Servlet"))
+            {
+               log.info("Ignore <servlet-class> that ends with 'Servlet': " + orgServletClassName);
+               continue;
+            }
+
+            servlet.setServletClass(servletClass);
+
+            // add additional init params
+            if (orgServletClassName.equals(servletClass) == false)
+            {
+               targetBeanName = orgServletClassName;
+               ParamValueMetaData initParam = new ParamValueMetaData();
+               initParam.setParamName(Endpoint.SEPID_DOMAIN_ENDPOINT);
+               initParam.setParamValue(targetBeanName);
+               initParams.add(initParam);
+            }
+         }
+
+         if (targetBeanName == null)
+            throw new IllegalStateException("Cannot obtain service endpoint bean for: " + linkName);
+
+         // remember the target bean name
+         results.sepTargetMap.put(linkName, targetBeanName);
+      }
+
+      return results;
+   }
+
+   // Return true if the web.xml is already modified
+   private boolean isAlreadyModified(JBossServletMetaData servlet)
+   {
+      for (ParamValueMetaData initParam : servlet.getInitParam())
+      {
+         String paramName = initParam.getParamName();
+         if (Endpoint.SEPID_DOMAIN_ENDPOINT.equals(paramName))
+            return true;
+      }
+      return false;
+   }
+}


Property changes on: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/InMemoryWebMetaDataModifier.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ModifyWebMetaDataDeploymentAspect.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ModifyWebMetaDataDeploymentAspect.java	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/ModifyWebMetaDataDeploymentAspect.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -46,17 +46,17 @@
    @Override
    public void create(Deployment dep)
    {
-      String servletClass = (String)dep.getProperty(WebAppDesciptorModifier.PROPERTY_WEBAPP_SERVLET_CLASS);
+      String servletClass = (String)dep.getProperty(WebMetaDataModifier.PROPERTY_WEBAPP_SERVLET_CLASS);
       if (servletClass == null)
-         throw new IllegalStateException("Cannot obtain context property: " + WebAppDesciptorModifier.PROPERTY_WEBAPP_SERVLET_CLASS);
+         throw new IllegalStateException("Cannot obtain context property: " + WebMetaDataModifier.PROPERTY_WEBAPP_SERVLET_CLASS);
 
       modifyServletClass(dep, servletClass);
 
-      String listenerClass = (String)dep.getProperty(WebAppDesciptorModifier.PROPERTY_WEBAPP_SERVLET_CONTEXT_LISTENER);
+      String listenerClass = (String)dep.getProperty(WebMetaDataModifier.PROPERTY_WEBAPP_SERVLET_CONTEXT_LISTENER);
       if (listenerClass != null)
          modifyListener(dep, listenerClass);
       
-      Map<String, String> contextParams = (Map<String, String>)dep.getProperty(WebAppDesciptorModifier.PROPERTY_WEBAPP_CONTEXT_PARAMETERS);
+      Map<String, String> contextParams = (Map<String, String>)dep.getProperty(WebMetaDataModifier.PROPERTY_WEBAPP_CONTEXT_PARAMETERS);
       if (contextParams != null)
          modifyContextParams(dep, contextParams);
    }

Modified: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDeploymentAspect.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDeploymentAspect.java	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDeploymentAspect.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -49,7 +49,7 @@
    private static Logger log = Logger.getLogger(WebAppDeploymentAspect.class);
 
    private DeployerClient mainDeployer;
-   private WebXMLRewriterImpl webXMLRewriter;
+   private WebMetaDataModifier webMetaDataModifier;
    private Map<String, org.jboss.deployers.client.spi.Deployment> deploymentMap = new HashMap<String, org.jboss.deployers.client.spi.Deployment>();
 
    public void setMainDeployer(DeployerClient mainDeployer)
@@ -57,26 +57,26 @@
       this.mainDeployer = mainDeployer;
    }
 
-   public void setWebXMLRewriter(WebXMLRewriterImpl serviceEndpointPublisher)
+   public void setWebMetaDataModifier(WebMetaDataModifier webMetaDataModifier)
    {
-      this.webXMLRewriter = serviceEndpointPublisher;
+      this.webMetaDataModifier = webMetaDataModifier;
    }
 
    public void create(Deployment dep)
    {
-      URL warURL = (URL)dep.getProperty(WebAppDesciptorModifier.PROPERTY_WEBAPP_URL);
+      URL warURL = (URL)dep.getProperty(WebMetaDataModifier.PROPERTY_WEBAPP_URL);
       if (warURL == null)
          throw new IllegalStateException("Cannot obtain generated webapp URL");
 
       log.debug("publishServiceEndpoint: " + warURL);
       try
       {
-         webXMLRewriter.rewriteWebXml(dep);
+         webMetaDataModifier.modifyMetaData(dep);
          org.jboss.deployers.client.spi.Deployment deployment = createDeploymentContext(warURL);
          
          // Mark the deployment as generated web app so the JSE deployer hook can ignore it 
          MutableAttachments attach = (MutableAttachments)deployment.getPredeterminedManagedObjects();
-         attach.addAttachment(WebAppDesciptorModifier.PROPERTY_GENERATED_WEBAPP, Boolean.TRUE);
+         attach.addAttachment(WebMetaDataModifier.PROPERTY_GENERATED_WEBAPP, Boolean.TRUE);
 
          mainDeployer.deploy(deployment);
 
@@ -90,7 +90,7 @@
 
    public void destroy(Deployment dep)
    {
-      URL warURL = (URL)dep.getProperty(WebAppDesciptorModifier.PROPERTY_WEBAPP_URL);
+      URL warURL = (URL)dep.getProperty(WebMetaDataModifier.PROPERTY_WEBAPP_URL);
       if (warURL == null)
       {
          log.error("Cannot obtain generated webapp URL");

Deleted: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDesciptorModifier.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDesciptorModifier.java	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDesciptorModifier.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -1,42 +0,0 @@
-/*
- * 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.wsf.container.jboss50;
-
-import org.jboss.wsf.spi.deployment.Deployment;
-import org.dom4j.Document;
-
-/**
- * Modifies the web app according to the stack requirements.
- *
- * @author Thomas.Diesler at jboss.org
- * @since 19-May-2007
- */
-public interface WebAppDesciptorModifier
-{
-   static final String PROPERTY_GENERATED_WEBAPP = "org.jboss.ws.generated.webapp";
-   static final String PROPERTY_WEBAPP_CONTEXT_PARAMETERS = "org.jboss.ws.webapp.ContextParameterMap";
-   static final String PROPERTY_WEBAPP_SERVLET_CLASS = "org.jboss.ws.webapp.ServletClass";
-   static final String PROPERTY_WEBAPP_SERVLET_CONTEXT_LISTENER = "org.jboss.ws.webapp.ServletContextListener";
-   static final String PROPERTY_WEBAPP_URL = "org.jboss.ws.webapp.url";
-
-   RewriteResults modifyDescriptor(Deployment dep, Document webXml) throws ClassNotFoundException;
-}

Copied: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebMetaDataModifier.java (from rev 69969, trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebAppDesciptorModifier.java)
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebMetaDataModifier.java	                        (rev 0)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebMetaDataModifier.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -0,0 +1,41 @@
+/*
+ * 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.wsf.container.jboss50;
+
+import org.jboss.wsf.spi.deployment.Deployment;
+
+/**
+ * Modifies the web app according to the stack requirements.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 19-May-2007
+ */
+public interface WebMetaDataModifier
+{
+   static final String PROPERTY_GENERATED_WEBAPP = "org.jboss.ws.generated.webapp";
+   static final String PROPERTY_WEBAPP_CONTEXT_PARAMETERS = "org.jboss.ws.webapp.ContextParameterMap";
+   static final String PROPERTY_WEBAPP_SERVLET_CLASS = "org.jboss.ws.webapp.ServletClass";
+   static final String PROPERTY_WEBAPP_SERVLET_CONTEXT_LISTENER = "org.jboss.ws.webapp.ServletContextListener";
+   static final String PROPERTY_WEBAPP_URL = "org.jboss.ws.webapp.url";
+
+   RewriteResults modifyMetaData(Deployment dep) throws ClassNotFoundException;
+}

Deleted: trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebXMLRewriterImpl.java
===================================================================
--- trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebXMLRewriterImpl.java	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/main/org/jboss/wsf/container/jboss50/WebXMLRewriterImpl.java	2008-02-20 14:45:56 UTC (rev 69975)
@@ -1,136 +0,0 @@
-/*
- * 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.wsf.container.jboss50;
-
-import org.jboss.util.xml.JBossEntityResolver;
-import org.jboss.wsf.spi.deployment.Deployment;
-import org.jboss.wsf.common.IOUtils;
-import org.dom4j.io.SAXReader;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.XMLWriter;
-import org.dom4j.Document;
-
-import javax.xml.ws.WebServiceException;
-import java.net.URL;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.FileOutputStream;
-
-/**
- * The rewriter for web.xml
- *
- * @author Thomas.Diesler at jboss.org
- * @since 19-May-2007
- */
-public class WebXMLRewriterImpl
-{
-   private WebAppDesciptorModifier desciptorModifier;
-
-   public WebXMLRewriterImpl()
-   {
-      this.desciptorModifier = new DefaultWebAppDesciptorModifierImpl();
-   }
-
-   public WebAppDesciptorModifier getDesciptorModifier()
-   {
-      return desciptorModifier;
-   }
-
-   public void setDesciptorModifier(WebAppDesciptorModifier desciptorModifier)
-   {
-      this.desciptorModifier = desciptorModifier;
-   }
-
-   public RewriteResults rewriteWebXml(Deployment dep)
-   {
-      URL warURL = (URL)dep.getProperty(WebAppDesciptorModifier.PROPERTY_WEBAPP_URL);
-      File warFile = new File(warURL.getFile());
-      if (warFile.isDirectory() == false)
-         throw new WebServiceException("Expected a war directory: " + warURL);
-
-      File webXML = new File(warURL.getFile() + "/WEB-INF/web.xml");
-      if (webXML.isFile() == false)
-         throw new WebServiceException("Cannot find web.xml: " + webXML);
-
-      try
-      {
-         // After redeployment there might be a stale copy of the original web.xml.org, we delete it
-         File orgWebXML = new File(webXML.getCanonicalPath() + ".org");
-         orgWebXML.delete();
-
-         // Rename the web.xml
-         if (webXML.renameTo(orgWebXML) == false)
-            throw new WebServiceException("Cannot rename web.xml: " + orgWebXML);
-
-         return rewriteWebXml(orgWebXML, webXML, dep);
-      }
-      catch (RuntimeException rte)
-      {
-         throw rte;
-      }
-      catch (Exception e)
-      {
-         throw new WebServiceException(e);
-      }
-   }
-
-   private RewriteResults rewriteWebXml(File input, File destFile, Deployment dep) throws Exception
-   {
-      if (destFile == null)
-      {
-         destFile = File.createTempFile("jbossws-alt-web", "xml", IOUtils.createTempDirectory());
-         destFile.deleteOnExit();
-      }
-
-      FileInputStream inputStream = null;
-      FileOutputStream outputStream = null;
-
-      try
-      {
-         SAXReader reader = new SAXReader();
-         reader.setEntityResolver(new JBossEntityResolver());
-         
-         inputStream = new FileInputStream(input);
-         Document document = reader.read(inputStream);
-
-         RewriteResults results = desciptorModifier.modifyDescriptor(dep, document);
-         results.webXML = destFile.toURL();
-
-         outputStream = new FileOutputStream(destFile);
-         OutputFormat format = OutputFormat.createPrettyPrint();
-         XMLWriter writer = new XMLWriter(outputStream, format);
-         writer.write(document);
-         writer.close();
-
-         return results;
-      }
-      finally
-      {
-         if(inputStream!=null)
-            inputStream.close();
-
-         if(outputStream!=null)
-            outputStream.close();
-      }
-   }
-}

Modified: trunk/webservices/src/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-beans.xml
===================================================================
--- trunk/webservices/src/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-beans.xml	2008-02-20 13:01:42 UTC (rev 69974)
+++ trunk/webservices/src/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-beans.xml	2008-02-20 14:45:56 UTC (rev 69975)
@@ -256,7 +256,7 @@
   
   <bean name="WSWebAppDeploymentAspect" class="org.jboss.wsf.container.jboss50.WebAppDeploymentAspect">
     <property name="requires">WebMetaData, ContextProperties</property>
-    <property name="webXMLRewriter"><inject bean="WSWebXMLRewriter"/></property>
+    <property name="webMetaDataModifier"><inject bean="WSWebMetaDataModifier"/></property>
     <property name="mainDeployer"><inject bean="MainDeployer"/></property>
   </bean>
   
@@ -270,10 +270,7 @@
   <!-- Deployment aspect helper beans -->
   <bean name="WSSecurityHandlerEJB21" class="org.jboss.wsf.container.jboss50.SecurityHandlerEJB21"/>
   <bean name="WSSecurityHandlerEJB3" class="org.jboss.wsf.container.jboss50.SecurityHandlerEJB3"/>
-  <bean name="WSWebAppDesciptorModifier" class="org.jboss.wsf.container.jboss50.DefaultWebAppDesciptorModifierImpl"/>
-  <bean name="WSWebXMLRewriter" class="org.jboss.wsf.container.jboss50.WebXMLRewriterImpl">
-    <property name="desciptorModifier"><inject bean="WSWebAppDesciptorModifier"/></property>
-  </bean>
+  <bean name="WSWebMetaDataModifier" class="org.jboss.wsf.container.jboss50.FileBasedWebMetaDataModifier"/>
   
   <!-- Deployment aspect installers -->
 




More information about the jboss-cvs-commits mailing list