geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r522731 - in /geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder: JAXWSEJBModuleBuilderExtension.java JAXWSServiceBuilder.java
Date Tue, 27 Mar 2007 03:56:28 GMT
Author: gawor
Date: Mon Mar 26 20:56:28 2007
New Revision: 522731

URL: http://svn.apache.org/viewvc?view=rev&rev=522731
Log:
use openejb metadata to discover/configure ejb-based ws

Modified:
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSEJBModuleBuilderExtension.java
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSEJBModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSEJBModuleBuilderExtension.java?view=diff&rev=522731&r1=522730&r2=522731
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSEJBModuleBuilderExtension.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSEJBModuleBuilderExtension.java
Mon Mar 26 20:56:28 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.geronimo.jaxws.builder;
 
-import java.io.File;
 import java.net.URL;
 import java.util.Collection;
 import java.util.HashMap;
@@ -76,26 +75,26 @@
     }
 
     public void createModule(Module module, Object plan, JarFile moduleFile, String targetPath,
URL specDDUrl, Environment environment, Object moduleContextInfo, AbstractName earName, Naming
naming, ModuleIDBuilder idBuilder) throws DeploymentException {
-        if (module.getType() != ConfigurationModuleType.EJB) {
-            return;
-        }
-       
-        EjbModule ejbModule = (EjbModule) module;
-        
-        //overridden web service locations
-        Map correctedPortLocations = new HashMap();
-               
-        jaxwsBuilder.findWebServices(module, true, correctedPortLocations, environment, ejbModule.getSharedContext());
-        
         if (this.defaultEnvironment != null) {
             EnvironmentBuilder.mergeEnvironments(environment, this.defaultEnvironment);
-        }        
+        } 
     }
 
     public void installModule(JarFile earFile, EARContext earContext, Module module, Collection
configurationStores, ConfigurationStore targetConfigurationStore, Collection repository) throws
DeploymentException {
     }
 
     public void initContext(EARContext earContext, Module module, ClassLoader cl) throws
DeploymentException {
+        if (module.getType() != ConfigurationModuleType.EJB) {
+            return;
+        }
+       
+        EjbModule ejbModule = (EjbModule) module;
+        Environment environment = module.getEnvironment();
+                
+        //overridden web service locations       
+        Map correctedPortLocations = new HashMap();       
+               
+        jaxwsBuilder.findWebServices(module, true, correctedPortLocations, environment, ejbModule.getSharedContext());
     }
 
     public void addGBeans(EARContext earContext, Module module, ClassLoader cl, Collection
repository) throws DeploymentException {
@@ -120,7 +119,7 @@
             ejbWebServiceGBean.setAttribute("ejbName", ejbName);
             ejbWebServiceGBean.setAttribute("ejbClass", bean.ejbClass);
             
-            if (jaxwsBuilder.configureEJB(ejbWebServiceGBean, bean.ejbClass, ejbModule.getModuleFile(),

+            if (jaxwsBuilder.configureEJB(ejbWebServiceGBean, bean.ejbName, ejbModule.getModuleFile(),

                                           ejbModule.getSharedContext(), cl)) {
 
                 try {

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=522731&r1=522730&r2=522731
==============================================================================
--- 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
Mon Mar 26 20:56:28 2007
@@ -17,6 +17,22 @@
 
 package org.apache.geronimo.jaxws.builder;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceProvider;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.common.DeploymentException;
@@ -37,26 +53,13 @@
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.classloader.JarFileClassLoader;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.openejb.deployment.EjbModule;
 import org.apache.geronimo.xbeans.javaee.ServletMappingType;
 import org.apache.geronimo.xbeans.javaee.ServletType;
 import org.apache.geronimo.xbeans.javaee.WebAppType;
+import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
 import org.apache.xbean.finder.ClassFinder;
 
-import javax.jws.WebService;
-import javax.xml.ws.WebServiceProvider;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
 public abstract class JAXWSServiceBuilder implements WebServiceBuilder {
     private static final Log LOG = LogFactory.getLog(JAXWSServiceBuilder.class);
 
@@ -98,81 +101,120 @@
                                                       boolean isEJB,
                                                       Map correctedPortLocations)
             throws DeploymentException {
-        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();
-                                                
-            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);
+            discoverEJBWebServices(module, correctedPortLocations, map);
+        } else {          
+            discoverPOJOWebServices(module, correctedPortLocations, map);
+        }        
+        return map;
+    }
+    
+    private void discoverPOJOWebServices(Module module,
+                                         Map correctedPortLocations,
+                                         Map<String, PortInfo> map) 
+        throws DeploymentException {
+        ClassLoader classLoader = module.getEarContext().getClassLoader();
+        WebAppType webApp = (WebAppType) module.getSpecDD();
+
+        // find web services
+        ServletType[] servletTypes = webApp.getServletArray();
+
+        if (webApp.getDomNode().getChildNodes().getLength() == 0) {
+            // web.xml not present (empty really), discover annotated
+            // classes and update DD
+            List<Class> services = discoverWebServices(module.getModuleFile(), false);
+            String contextRoot = ((WebModule) module).getContextRoot();
+            for (Class service : services) {
+                // skip interfaces and such
+                if (!JAXWSUtils.isWebService(service)) {
+                    continue;
                 }
-            } 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);
+
+                LOG.debug("Discovered POJO Web Service: " + service.getName());
+                
+                // 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)) {
+                            LOG.debug("Found POJO Web Service: " + servletName);
+                            PortInfo portInfo = new PortInfo();
+                            map.put(servletName, portInfo);
                         }
+                    } 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) {
+                    portInfo.setLocation(location);
+                }
+            }
+        }
+    }       
+                   
+    private void discoverEJBWebServices(Module module,
+                                        Map correctedPortLocations,
+                                        Map<String, PortInfo> map) 
+        throws DeploymentException {
+        ClassLoader classLoader = module.getEarContext().getClassLoader();
+        EjbModule ejbModule = (EjbModule) module;
+        for (EnterpriseBeanInfo bean : ejbModule.getEjbJarInfo().enterpriseBeans) {
+            if (bean.type != EnterpriseBeanInfo.STATELESS) {
+                continue;
+            }            
+            try {
+                Class ejbClass = classLoader.loadClass(bean.ejbClass);
+                if (JAXWSUtils.isWebService(ejbClass)) {
+                    LOG.debug("Found EJB Web Service: " + bean.ejbName);
+                    PortInfo portInfo = new PortInfo();
+                    String location = (String) correctedPortLocations.get(bean.ejbName);
+                    if (location == null) {
+                        // set default location, i.e. /@WebService.serviceName/@WebService.name
+                        location = "/" + JAXWSUtils.getServiceName(ejbClass) + "/" + JAXWSUtils.getName(ejbClass);
                     }
+                    portInfo.setLocation(location);
+                    map.put(bean.ejbName, portInfo);
                 }
+            } catch (Exception e) {
+                throw new DeploymentException("Failed to load ejb class "
+                                              + bean.ejbName, e);
             }
         }
-        
-        return map;        
     }
-                       
+    
     /**
-     * Returns a list of any classes annotated with @WebService or 
+     * Returns a list of any classes annotated with @WebService or
      * @WebServiceProvider annotation.
      */
     private List<Class> discoverWebServices(JarFile moduleFile,
@@ -254,20 +296,6 @@
         return classes;
     }
 
-    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());
-                PortInfo portInfo = new PortInfo();
-                String location = (String) correctedPortLocations.get(clazz.getName());
-                portInfo.setLocation(location);
-                map.put(clazz.getName(), portInfo);
-            }
-        }
-    }
-
     protected abstract Map<String, PortInfo> parseWebServiceDescriptor(InputStream
in,
                                                                        URL wsDDUrl,
                                                                        JarFile moduleFile,
@@ -348,16 +376,10 @@
             // not ours
             return false;
         }
-        
-        String shortEjbName = (String)targetGBean.getAttribute("ejbName");
-        String ejbClass = (String)targetGBean.getAttribute("ejbClass");
-                
+       
         String location = portInfo.getLocation();
         if (location == null) {                   
-            // set default location, i.e. /@WebService.serviceName/@WebService.name
-            Class beanClass = loadClass(ejbClass, classLoader);
-            location = "/" + JAXWSUtils.getServiceName(beanClass) + "/" + JAXWSUtils.getName(beanClass);
-            portInfo.setLocation(location);
+            throw new DeploymentException("Endpoint URI for EJB WebService is missing");
         }
 
         LOG.info("Configuring EJB Web Service: " + ejbName + " at " + location);



Mime
View raw message