geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r513815 - in /geronimo/server/trunk/modules: geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/ geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/ geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/de...
Date Fri, 02 Mar 2007 15:49:48 GMT
Author: jgenender
Date: Fri Mar  2 07:49:46 2007
New Revision: 513815

URL: http://svn.apache.org/viewvc?view=rev&rev=513815
Log:
GERONIMO-2922 - ALlow deployment without web.xml

Modified:
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java
    geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
    geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
    geronimo/server/trunk/modules/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java?view=diff&rev=513815&r1=513814&r2=513815
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java
Fri Mar  2 07:49:46 2007
@@ -37,6 +37,7 @@
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.classloader.JarFileClassLoader;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.xbeans.javaee.ServletMappingType;
 import org.apache.geronimo.xbeans.javaee.ServletType;
 import org.apache.geronimo.xbeans.javaee.WebAppType;
 import org.apache.xbean.finder.ClassFinder;
@@ -46,7 +47,6 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.Modifier;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -98,52 +98,85 @@
                                                       boolean isEJB,
                                                       Map correctedPortLocations)
             throws DeploymentException {
-        if (isEJB) {
-            return discoverWebServices(module.getModuleFile(), isEJB, correctedPortLocations);
-        } else {
-            Map<String, PortInfo> map = new HashMap<String, PortInfo>();
+        Map<String, PortInfo> map = new HashMap<String, PortInfo>();
+        
+        if (isEJB) {            
+            List<Class> services = discoverWebServices(module.getModuleFile(), isEJB);
+            updatePortMap(services, map, correctedPortLocations);
+        } else {                        
             ClassLoader classLoader = module.getEarContext().getClassLoader();
             WebAppType webApp = (WebAppType) module.getSpecDD();
             
             // find web services
             ServletType[] servletTypes = webApp.getServletArray();
-            for (ServletType servletType : servletTypes) {
-                String servletName = servletType.getServletName().getStringValue().trim();
-                if (servletType.isSetServletClass()) {
-                    String servletClassName = servletType.getServletClass().getStringValue().trim();
-                    try {
-                        Class servletClass = classLoader.loadClass(servletClassName);
-                        if (JAXWSUtils.isWebService(servletClass)) {
-                            PortInfo portInfo = new PortInfo();                         
                             
-                            map.put(servletName, portInfo);
+                                                
+            if (webApp.getDomNode().getChildNodes().getLength() == 0) {
+                // web.xml not present (empty really), discover annotated classes and update
DD
+                List<Class> services = discoverWebServices(module.getModuleFile(),
isEJB);
+                String contextRoot = ((WebModule) module).getContextRoot();
+                for (Class service : services) {
+                    // skip interfaces and such
+                    if (!JAXWSUtils.isWebService(service)) {
+                        continue;
+                    }
+                    
+                    // add new <servlet/> element
+                    ServletType servlet = webApp.addNewServlet();
+                    servlet.addNewServletName().setStringValue(service.getName());
+                    servlet.addNewServletClass().setStringValue(service.getName());
+                    
+                    // add new <servlet-mapping/> element
+                    String location = "/" + JAXWSUtils.getServiceName(service);
+                    ServletMappingType servletMapping = webApp.addNewServletMapping();
+                    servletMapping.addNewServletName().setStringValue(service.getName());
                                     
+                    servletMapping.addNewUrlPattern().setStringValue(location);
+                    
+                    // map service
+                    PortInfo portInfo = new PortInfo();
+                    portInfo.setLocation(contextRoot + location);
+                    map.put(service.getName(), portInfo);
+                }
+            } else {
+                // web.xml present, examine servlet classes and check for web services
+                for (ServletType servletType : servletTypes) {
+                    String servletName = servletType.getServletName().getStringValue().trim();
+                    if (servletType.isSetServletClass()) {
+                        String servletClassName = servletType.getServletClass().getStringValue().trim();
+                        try {
+                            Class servletClass = classLoader.loadClass(servletClassName);
+                            if (JAXWSUtils.isWebService(servletClass)) {
+                                PortInfo portInfo = new PortInfo();
+                                map.put(servletName, portInfo);
+                            }
+                        } catch (Exception e) {
+                            throw new DeploymentException("Failed to load servlet class "
+                                                          + servletClassName, e);
                         }
-                    } catch (Exception e) {                       
-                        throw new DeploymentException("Failed to load servlet class " + servletClassName,
e);
+                    }
+                }
+                                  
+                // update web service locations
+                for (Map.Entry entry : map.entrySet()) {
+                    String servletName = (String) entry.getKey();
+                    PortInfo portInfo = (PortInfo) entry.getValue();
+
+                    String location = (String) correctedPortLocations.get(servletName);
+                    if (location != null) {
+                        portInfo.setLocation(location);
                     }
                 }
             }
-                        
-            // update web service locations
-            for (Map.Entry entry : map.entrySet()) {
-                String servletName = (String)entry.getKey();
-                PortInfo portInfo = (PortInfo)entry.getValue();
-                
-                String location = (String)correctedPortLocations.get(servletName);
-                if (location == null) {
-                    // TODO: not sure this case should be handled: Web service without servlet-mapping?
-                    throw new DeploymentException("Unsupported: Web Service without servlet-mapping");
-                } else {
-                    portInfo.setLocation(location);
-                }                                   
-            }
-            
-            return map;
         }
+        
+        return map;        
     }
                        
-    private Map<String, PortInfo> discoverWebServices(JarFile moduleFile,
-                                                      boolean isEJB,
-                                                      Map correctedPortLocations)
+    /**
+     * Returns a list of any classes annotated with @WebService or 
+     * @WebServiceProvider annotation.
+     */
+    private List<Class> discoverWebServices(JarFile moduleFile,
+                                            boolean isEJB)                              
                       
             throws DeploymentException {
         LOG.debug("Discovering web service classes");
 
@@ -202,18 +235,15 @@
                 }
             }
         }
-
+        
         URL[] urls = urlList.toArray(new URL[] {});
         JarFileClassLoader tempClassLoader = new JarFileClassLoader(null, urls, this.getClass().getClassLoader());
         ClassFinder classFinder = new ClassFinder(tempClassLoader, urlList);
 
-        Map<String, PortInfo> map = null;
-        List<Class> classes = null;
+        List<Class> classes = new ArrayList<Class>();
 
-        classes = classFinder.findAnnotatedClasses(WebService.class);
-        map = updatePortMap(classes, map, correctedPortLocations);
-        classes = classFinder.findAnnotatedClasses(WebServiceProvider.class);
-        map = updatePortMap(classes, map, correctedPortLocations);
+        classes.addAll(classFinder.findAnnotatedClasses(WebService.class));
+        classes.addAll(classFinder.findAnnotatedClasses(WebServiceProvider.class));     
 
 
         tempClassLoader.destroy();
 
@@ -221,25 +251,21 @@
             DeploymentUtil.recursiveDelete(tmpDir);
         }
 
-        return map;
+        return classes;
     }
 
-    private static Map<String, PortInfo> updatePortMap(List<Class> classes,
-                                                       Map<String, PortInfo> map,
-                                                       Map correctedPortLocations) {
+    private static void updatePortMap(List<Class> classes,
+                                      Map<String, PortInfo> map,
+                                      Map correctedPortLocations) {
         for (Class clazz : classes) {
             if (JAXWSUtils.isWebService(clazz)) {
                 LOG.debug("Found web service class: " + clazz.getName());
-                if (map == null) {
-                    map = new HashMap<String, PortInfo>();
-                }
                 PortInfo portInfo = new PortInfo();
                 String location = (String) correctedPortLocations.get(clazz.getName());
                 portInfo.setLocation(location);
                 map.put(clazz.getName(), portInfo);
             }
         }
-        return map;
     }
 
     protected abstract Map<String, PortInfo> parseWebServiceDescriptor(InputStream
in,

Modified: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java?view=diff&rev=513815&r1=513814&r2=513815
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
Fri Mar  2 07:49:46 2007
@@ -80,4 +80,27 @@
                 !Modifier.isFinal(modifiers) &&
                 !Modifier.isAbstract(modifiers));
     }
+    
+    public static String getServiceName(Class clazz) {
+        WebService webService = 
+            (WebService)clazz.getAnnotation(WebService.class);
+        if (webService == null) {
+            WebServiceProvider webServiceProvider = 
+                (WebServiceProvider)clazz.getAnnotation(WebServiceProvider.class);
+            if (webServiceProvider == null) {
+                throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated");
+            }
+            return getServiceName(clazz, webServiceProvider.serviceName());
+        } else {
+            return getServiceName(clazz, webService.serviceName());
+        }
+    }
+    
+    private static String getServiceName(Class clazz, String name) {
+        if (name == null || name.trim().length() == 0) {
+            return clazz.getSimpleName() + "Service";
+        } else {
+            return name.trim();
+        }       
+    }
 }

Modified: geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java?view=diff&rev=513815&r1=513814&r2=513815
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
Fri Mar  2 07:49:46 2007
@@ -214,6 +214,10 @@
             //else ignore as jee5 allows optional spec dd for .war's
         }
 
+        if (webApp == null) {
+            webApp = WebAppType.Factory.newInstance();
+        }
+        
         // parse vendor dd
         JettyWebAppType jettyWebApp = getJettyWebApp(plan, moduleFile, standAlone, targetPath,
webApp);
         if (contextRoot == null || contextRoot.trim().equals("")) {

Modified: geronimo/server/trunk/modules/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java?view=diff&rev=513815&r1=513814&r2=513815
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
Fri Mar  2 07:49:46 2007
@@ -144,6 +144,10 @@
             }
             //else ignore as jee5 allows optional spec dd for .war's
         }
+        
+        if (webApp == null) {
+            webApp = WebAppType.Factory.newInstance();
+        }
 
         // parse vendor dd
         TomcatWebAppType tomcatWebApp = getTomcatWebApp(plan, moduleFile, standAlone, targetPath,
webApp);



Mime
View raw message