Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 38336 invoked from network); 27 Sep 2007 17:46:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Sep 2007 17:46:58 -0000 Received: (qmail 37550 invoked by uid 500); 27 Sep 2007 17:46:47 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 37519 invoked by uid 500); 27 Sep 2007 17:46:47 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 37508 invoked by uid 99); 27 Sep 2007 17:46:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Sep 2007 10:46:47 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Sep 2007 17:49:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 025A81A9832; Thu, 27 Sep 2007 10:46:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r580113 - in /geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder: WARWebServiceFinder.java WebServiceFinder.java Date: Thu, 27 Sep 2007 17:46:32 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070927174633.025A81A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gawor Date: Thu Sep 27 10:46:30 2007 New Revision: 580113 URL: http://svn.apache.org/viewvc?rev=580113&view=rev Log: forgot to commit Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WARWebServiceFinder.java (with props) geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceFinder.java (with props) Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WARWebServiceFinder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WARWebServiceFinder.java?rev=580113&view=auto ============================================================================== --- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WARWebServiceFinder.java (added) +++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WARWebServiceFinder.java Thu Sep 27 10:46:30 2007 @@ -0,0 +1,217 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.geronimo.jaxws.builder; + +import java.io.File; +import java.io.IOException; +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; +import org.apache.geronimo.deployment.util.DeploymentUtil; +import org.apache.geronimo.j2ee.deployment.Module; +import org.apache.geronimo.j2ee.deployment.WebModule; +import org.apache.geronimo.jaxws.JAXWSUtils; +import org.apache.geronimo.jaxws.PortInfo; +import org.apache.geronimo.kernel.classloader.JarFileClassLoader; +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; + +public class WARWebServiceFinder implements WebServiceFinder { + + private static final Log LOG = LogFactory.getLog(WARWebServiceFinder.class); + + public Map discoverWebServices(Module module, + boolean isEJB, + Map correctedPortLocations) + throws DeploymentException { + Map map = new HashMap(); + discoverPOJOWebServices(module, correctedPortLocations, map); + return map; + } + + private void discoverPOJOWebServices(Module module, + Map correctedPortLocations, + Map 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 services = discoverWebServices(module.getModuleFile(), false); + String contextRoot = ((WebModule) module).getContextRoot(); + for (Class service : services) { + // skip interfaces and such + if (!JAXWSUtils.isWebService(service)) { + continue; + } + + LOG.debug("Discovered POJO Web Service: " + service.getName()); + + // add new element + ServletType servlet = webApp.addNewServlet(); + servlet.addNewServletName().setStringValue(service.getName()); + servlet.addNewServletClass().setStringValue(service.getName()); + + // add new 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); + } + } + } + } + + /** + * Returns a list of any classes annotated with @WebService or + * @WebServiceProvider annotation. + */ + private List discoverWebServices(JarFile moduleFile, + boolean isEJB) + throws DeploymentException { + LOG.debug("Discovering web service classes"); + + File tmpDir = null; + List urlList = new ArrayList(); + if (isEJB) { + File jarFile = new File(moduleFile.getName()); + try { + urlList.add(jarFile.toURL()); + } catch (MalformedURLException e) { + // this should not happen + throw new DeploymentException(e); + } + } else { + /* + * Can't get ClassLoader to load nested Jar files, so + * unpack the module Jar file and discover all nested Jar files + * within it and the classes/ directory. + */ + try { + tmpDir = DeploymentUtil.createTempDir(); + /* + * This is needed becuase DeploymentUtil.unzipToDirectory() + * always closes the passed JarFile. + */ + JarFile module = new JarFile(moduleFile.getName()); + DeploymentUtil.unzipToDirectory(module, tmpDir); + } catch (IOException e) { + if (tmpDir != null) { + DeploymentUtil.recursiveDelete(tmpDir); + } + throw new DeploymentException("Failed to expand the module archive", e); + } + + // create URL list + Enumeration jarEnum = moduleFile.entries(); + while (jarEnum.hasMoreElements()) { + JarEntry entry = jarEnum.nextElement(); + String name = entry.getName(); + if (name.equals("WEB-INF/classes/")) { + // ensure it is first + File classesDir = new File(tmpDir, "WEB-INF/classes/"); + try { + urlList.add(0, classesDir.toURL()); + } catch (MalformedURLException e) { + // this should not happen, ignore + } + } else if (name.startsWith("WEB-INF/lib/") + && name.endsWith(".jar")) { + File jarFile = new File(tmpDir, name); + try { + urlList.add(jarFile.toURL()); + } catch (MalformedURLException e) { + // this should not happen, ignore + } + } + } + } + + URL[] urls = urlList.toArray(new URL[] {}); + JarFileClassLoader tempClassLoader = new JarFileClassLoader(null, urls, this.getClass().getClassLoader()); + ClassFinder classFinder = new ClassFinder(tempClassLoader, urlList); + + List classes = new ArrayList(); + + classes.addAll(classFinder.findAnnotatedClasses(WebService.class)); + classes.addAll(classFinder.findAnnotatedClasses(WebServiceProvider.class)); + + tempClassLoader.destroy(); + + if (tmpDir != null) { + DeploymentUtil.recursiveDelete(tmpDir); + } + + return classes; + } +} Propchange: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WARWebServiceFinder.java ------------------------------------------------------------------------------ svn:eol-style = native Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceFinder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceFinder.java?rev=580113&view=auto ============================================================================== --- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceFinder.java (added) +++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceFinder.java Thu Sep 27 10:46:30 2007 @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.geronimo.jaxws.builder; + +import java.util.Map; + +import org.apache.geronimo.common.DeploymentException; +import org.apache.geronimo.j2ee.deployment.Module; +import org.apache.geronimo.jaxws.PortInfo; + +public interface WebServiceFinder { + + Map discoverWebServices(Module module, + boolean isEJB, + Map correctedPortLocations) + throws DeploymentException; + +} Propchange: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceFinder.java ------------------------------------------------------------------------------ svn:eol-style = native