geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r569119 - in /geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder: JAXWSTools.java JAXWSToolsCLI.java WsdlGenerator.java
Date Thu, 23 Aug 2007 19:01:43 GMT
Author: gawor
Date: Thu Aug 23 12:01:42 2007
New Revision: 569119

URL: http://svn.apache.org/viewvc?rev=569119&view=rev
Log:
refactored so that we can expose wsgen and wsimport command line tools. also, added a timeout
for forked wsgen process so that we don't wait forever in case wsgen did not exit

Added:
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSTools.java
  (with props)
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java
  (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java

Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSTools.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSTools.java?rev=569119&view=auto
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSTools.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSTools.java
Thu Aug 23 12:01:42 2007
@@ -0,0 +1,195 @@
+/**
+ * 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.OutputStream;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.SortedSet;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ListableRepository;
+import org.apache.geronimo.kernel.repository.Version;
+
+public class JAXWSTools {
+
+    private static final Log LOG = LogFactory.getLog(JAXWSTools.class);
+        
+    private final static Artifact AXIS2_JAXWS_API_ARTIFACT = new Artifact("org.apache.axis2","axis2-jaxws-api",
(Version)null, "jar");
+    private final static Artifact AXIS2_SAAJ_API_ARTIFACT = new Artifact("org.apache.axis2","axis2-saaj-api",
(Version)null, "jar");
+    private final static Artifact AXIS2_SAAJ_IMPL_ARTIFACT = new Artifact("org.apache.axis2","axis2-saaj",
(Version)null, "jar");
+    private final static Artifact JAXB_API_ARTIFACT = new Artifact("javax.xml.bind","jaxb-api",
(Version)null, "jar");
+    private final static Artifact JAXB_IMPL_ARTIFACT = new Artifact("com.sun.xml.bind","jaxb-impl",
(Version)null, "jar");
+    private final static Artifact JAXB_XJC_ARTIFACT = new Artifact("com.sun.xml.bind","jaxb-xjc",
(Version)null, "jar");    
+    private final static Artifact JAXWS_TOOLS_ARTIFACT = new Artifact("com.sun.xml.ws","jaxws-tools",
(Version)null, "jar");
+    private final static Artifact JAXWS_RT_ARTIFACT = new Artifact("com.sun.xml.ws","jaxws-rt",
(Version)null, "jar");
+    private final static Artifact GERONIMO_ACTIVATION_SPEC_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-activation_1.1_spec",
(Version)null, "jar");    
+    private final static Artifact GERONIMO_ANNOTATION_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-annotation_1.0_spec",
(Version)null, "jar");     
+    private final static Artifact GERONIMO_WS_METADATA_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-ws-metadata_2.0_spec",
(Version)null, "jar");  
+    private final static Artifact GERONIMO_EJB_SPEC_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-ejb_3.0_spec",
(Version)null, "jar");
+    private final static Artifact SUN_SAAJ_IMPL_ARTIFACT = new Artifact("com.sun.xml.messaging.saaj","saaj-impl",
(Version)null, "jar");
+    private final static String TOOLS = "tools.jar";
+
+    private Artifact saajImpl;
+    private boolean overrideContextClassLoader;
+    
+    public JAXWSTools() {
+    }
+    
+    public void setUseSunSAAJ() {
+        this.saajImpl = SUN_SAAJ_IMPL_ARTIFACT;
+    }
+    
+    public void setUseAxis2SAAJ() {
+        this.saajImpl = AXIS2_SAAJ_IMPL_ARTIFACT;
+    }
+    
+    public void setOverrideContextClassLoader(boolean overrideContextClassLoader) {
+        this.overrideContextClassLoader = overrideContextClassLoader;
+    }
+    
+    public boolean getOverrideContextClassLoader() {
+        return this.overrideContextClassLoader;
+    }
+       
+    public static URL[] toURL(File[] jars) throws MalformedURLException {
+        URL [] urls = new URL[jars.length];
+        for (int i = 0; i < jars.length; i++) {
+            urls[i] = jars[i].toURL();
+        }
+        return urls;
+    }
+    
+    public static String toString(File [] jars) {
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < jars.length; i++) {
+            buf.append(jars[i].getAbsolutePath());
+            if (i+1 < jars.length) {
+                buf.append(File.pathSeparatorChar);
+            }
+        }
+        return buf.toString();
+    }
+    
+    public File[] getClasspath(Collection<ListableRepository> repositories) throws
Exception {
+        ArrayList<File> jars = new ArrayList<File>();
+        jars.add(getLocation(repositories, JAXB_API_ARTIFACT));
+        jars.add(getLocation(repositories, JAXB_IMPL_ARTIFACT));
+        jars.add(getLocation(repositories, JAXB_XJC_ARTIFACT));
+        jars.add(getLocation(repositories, JAXWS_TOOLS_ARTIFACT));
+        jars.add(getLocation(repositories, JAXWS_RT_ARTIFACT));
+        jars.add(getLocation(repositories, AXIS2_JAXWS_API_ARTIFACT));
+        jars.add(getLocation(repositories, AXIS2_SAAJ_API_ARTIFACT));
+        jars.add(getLocation(repositories, GERONIMO_ACTIVATION_SPEC_ARTIFACT));
+        jars.add(getLocation(repositories, GERONIMO_ANNOTATION_ARTIFACT));
+        jars.add(getLocation(repositories, GERONIMO_WS_METADATA_ARTIFACT));
+        jars.add(getLocation(repositories, GERONIMO_EJB_SPEC_ARTIFACT));
+        if (this.saajImpl != null) {
+            jars.add(getLocation(repositories, this.saajImpl));
+        }
+        jars.add(getToolsJarLocation());
+        
+        return jars.toArray(new File[jars.size()]);
+    }
+       
+    private static File getLocation(Collection<ListableRepository> repositories, Artifact
artifactQuery) throws Exception {
+        File file = null;
+        
+        for (ListableRepository repository : repositories) {
+            SortedSet artifactSet = repository.list(artifactQuery);
+            // if we have exactly one artifact found
+            if (artifactSet.size() == 1) {
+                file = repository.getLocation((Artifact) artifactSet.first());          
     
+                return file.getAbsoluteFile();
+            } else if (artifactSet.size() > 1) {// if we have more than 1 artifacts found
use the latest one.
+                file = repository.getLocation((Artifact) artifactSet.last());
+                return file.getAbsoluteFile();
+            } 
+        }
+        
+        throw new Exception("Missing artifact in repositories: " + artifactQuery.toString());
+    }
+    
+    private static File getToolsJarLocation() throws Exception {
+        //create a new File then check exists()
+        String jreHomePath = System.getProperty("java.home");
+        String javaHomePath = "";
+        int jreHomePathLength = jreHomePath.length();
+        if (jreHomePathLength > 0) {
+            int i = jreHomePath.substring(0, jreHomePathLength -1).lastIndexOf(java.io.File.separator);
+            javaHomePath = jreHomePath.substring(0, i);
+        }
+        File jdkhomelib = new File(javaHomePath, "lib");
+        if (!jdkhomelib.exists()) {
+            throw new Exception("Missing " + jdkhomelib.getAbsolutePath() 
+                    + ". This is required for wsgen to run. ");
+        }
+        else {
+            File tools = new File(jdkhomelib, TOOLS);
+            if (!tools.exists()) {
+                throw new Exception("Missing tools.jar in" + jdkhomelib.getAbsolutePath()

+                        + ". This is required for wsgen to run. ");                
+            } else {
+                return tools.getAbsoluteFile();
+            }               
+        }
+    }
+                           
+    public boolean invokeWsgen(URL[] jars, OutputStream os, String[] arguments) throws Exception
{
+        return invoke("wsgen", jars, os, arguments);
+    
+    }
+    public boolean invokeWsimport(URL[] jars, OutputStream os, String[] arguments) throws
Exception {
+        return invoke("wsimport", jars, os, arguments);
+    }
+    
+    private boolean invoke(String toolName, URL[] jars, OutputStream os, String[] arguments)
throws Exception {        
+        URLClassLoader loader = new URLClassLoader(jars, ClassLoader.getSystemClassLoader());
+        if (this.overrideContextClassLoader) {
+            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+            Thread.currentThread().setContextClassLoader(loader);
+            try {
+                return invoke(toolName, loader, os, arguments);
+            } finally {
+                Thread.currentThread().setContextClassLoader(oldClassLoader);
+            }            
+        } else {
+            return invoke(toolName, loader, os, arguments);
+        }
+    }
+    
+    private boolean invoke(String toolName, ClassLoader loader, OutputStream os, String[]
arguments) throws Exception {
+        LOG.debug("Invoking " + toolName);
+        Class clazz = loader.loadClass("com.sun.tools.ws.spi.WSToolsObjectFactory");
+        Method method = clazz.getMethod("newInstance");
+        Object factory = method.invoke(null);
+        Method method2 = clazz.getMethod(toolName, OutputStream.class, String[].class);
+        
+        Boolean result = (Boolean) method2.invoke(factory, os, arguments);
+        
+        return result;
+    }
+    
+}

Propchange: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSTools.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java?rev=569119&view=auto
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java
Thu Aug 23 12:01:42 2007
@@ -0,0 +1,84 @@
+/**
+ * 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.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.ArrayList;
+
+import org.apache.geronimo.kernel.repository.ListableRepository;
+import org.apache.geronimo.kernel.repository.Maven2Repository;
+
+public class JAXWSToolsCLI {
+
+    private static final String USAGE_MSG =
+        "Usage: jaxws-tools <toolName> <tool options>\n\n" +
+        "where <toolName> is:\n" +
+        "  wsgen       - generate portable artifacts from class\n" +
+        "  wsimport    - generate portable artifacts from WSDL\n";
+           
+    public static void main(String[] args) throws Throwable {
+        if (args.length == 0) {
+            System.err.println(USAGE_MSG);
+            System.exit(1);
+        }
+
+        String geroninoHome = System.getProperty("org.apache.geronimo.home.dir", "..");
+        String repository = System.getProperty("Xorg.apache.geronimo.repository.boot.path",
"repository");
+        Maven2Repository mavenRepository = new Maven2Repository((new File(geroninoHome, repository)).getCanonicalFile());
+        ArrayList<ListableRepository> repositories = new ArrayList<ListableRepository>(1);
+        repositories.add(mavenRepository);
+
+        JAXWSTools tools = new JAXWSTools();
+        tools.setUseAxis2SAAJ();
+        tools.setOverrideContextClassLoader(true);
+        
+        File [] jars = tools.getClasspath(repositories);
+                       
+        System.setProperty("java.class.path", JAXWSTools.toString(jars));
+        
+        URL[] jarUrls = JAXWSTools.toURL(jars);
+
+        boolean rs = false;
+        
+        try {
+            if (args[0].equalsIgnoreCase("wsgen")) {
+                rs = tools.invokeWsgen(jarUrls, System.out, getCmdArguments(args));
+            } else if (args[0].equalsIgnoreCase("wsimport")) {
+                rs = tools.invokeWsimport(jarUrls, System.out, getCmdArguments(args));
+            } else {
+                System.err.println("Error: Unsupported toolName [" + args[0] + "].");
+                System.err.println();
+                System.err.println(USAGE_MSG);
+                System.exit(1);
+            }
+        } catch (InvocationTargetException e) {
+            throw e.getTargetException();
+        }
+        
+        System.exit( (rs) ? 0 : 1 );
+    }
+    
+    private static String[] getCmdArguments(String[] args) {
+        String [] cmdArgs = new String[args.length - 1];
+        System.arraycopy(args, 1, cmdArgs, 0, args.length - 1);
+        return cmdArgs;
+    }
+
+}

Propchange: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java?rev=569119&r1=569118&r2=569119&view=diff
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
Thu Aug 23 12:01:42 2007
@@ -21,17 +21,12 @@
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Random;
-import java.util.SortedSet;
 
 import javax.xml.namespace.QName;
 
@@ -42,35 +37,25 @@
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.jaxws.PortInfo;
-import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.ListableRepository;
-import org.apache.geronimo.kernel.repository.Version;
 
 public class WsdlGenerator {
 
     private static final Log LOG = LogFactory.getLog(WsdlGenerator.class);
     
-    private final static String FORK_WSGEN_PROPERTY = "org.apache.geronimo.jaxws.wsgen.fork";
+    private final static String FORK_WSGEN_PROPERTY = 
+        "org.apache.geronimo.jaxws.wsgen.fork";
+    
+    private final static String FORK_TIMEOUT_WSGEN_PROPERTY = 
+        "org.apache.geronimo.jaxws.wsgen.fork.timeout";
+    
+    private final static long FORK_POLL_FREQUENCY = 1000 * 2; // 2 seconds
     
-    private final static Artifact AXIS2_JAXWS_API_ARTIFACT = new Artifact("org.apache.axis2","axis2-jaxws-api",
(Version)null, "jar");
-    private final static Artifact AXIS2_SAAJ_API_ARTIFACT = new Artifact("org.apache.axis2","axis2-saaj-api",
(Version)null, "jar");
-    private final static Artifact AXIS2_SAAJ_IMPL_ARTIFACT = new Artifact("org.apache.axis2","axis2-saaj",
(Version)null, "jar");
-    private final static Artifact JAXB_API_ARTIFACT = new Artifact("javax.xml.bind","jaxb-api",
(Version)null, "jar");
-    private final static Artifact JAXB_IMPL_ARTIFACT = new Artifact("com.sun.xml.bind","jaxb-impl",
(Version)null, "jar");
-    private final static Artifact JAXB_XJC_ARTIFACT = new Artifact("com.sun.xml.bind","jaxb-xjc",
(Version)null, "jar");    
-    private final static Artifact JAXWS_TOOLS_ARTIFACT = new Artifact("com.sun.xml.ws","jaxws-tools",
(Version)null, "jar");
-    private final static Artifact JAXWS_RT_ARTIFACT = new Artifact("com.sun.xml.ws","jaxws-rt",
(Version)null, "jar");
-    private final static Artifact GERONIMO_ACTIVATION_SPEC_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-activation_1.1_spec",
(Version)null, "jar");    
-    private final static Artifact GERONIMO_ANNOTATION_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-annotation_1.0_spec",
(Version)null, "jar");     
-    private final static Artifact GERONIMO_WS_METADATA_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-ws-metadata_2.0_spec",
(Version)null, "jar");  
-    private final static Artifact GERONIMO_EJB_SPEC_ARTIFACT = new Artifact("org.apache.geronimo.specs","geronimo-ejb_3.0_spec",
(Version)null, "jar");
-    private final static Artifact SUN_SAAJ_IMPL_ARTIFACT = new Artifact("com.sun.xml.messaging.saaj","saaj-impl",
(Version)null, "jar");
-    private final static String TOOLS = "tools.jar";
-
-    private Artifact saajImpl;
     private QName wsdlService;
     private QName wsdlPort;
     private boolean forkWsgen = getForkWsgen();
+    private long forkTimeout = getForTimeout();
+    private JAXWSTools jaxwsTools;
         
     private static boolean getForkWsgen() {
         String value = System.getProperty(FORK_WSGEN_PROPERTY);
@@ -87,15 +72,25 @@
         }
     }
     
+    private static long getForTimeout() {
+        String value = System.getProperty(FORK_TIMEOUT_WSGEN_PROPERTY);
+        if (value != null) {
+            return Long.parseLong(value);
+        } else {
+            return 1000 * 60; // 60 seconds
+        }
+    }
+    
     public WsdlGenerator() {
+        this.jaxwsTools = new JAXWSTools();
     }
     
     public void setSunSAAJ() {
-        this.saajImpl = SUN_SAAJ_IMPL_ARTIFACT;
+        this.jaxwsTools.setUseSunSAAJ();
     }
     
     public void setAxis2SAAJ() {
-        this.saajImpl = AXIS2_SAAJ_IMPL_ARTIFACT;
+        this.jaxwsTools.setUseAxis2SAAJ();
     }
     
     public void setWsdlService(QName name) {
@@ -114,30 +109,11 @@
         return this.wsdlPort;
     }
     
-    private URL[] getWsgenClasspath(DeploymentContext context) 
-        throws DeploymentException, MalformedURLException {
-        ArrayList<URL> jars = new ArrayList<URL>();
-        
+    private URL[] getWsgenClasspath(DeploymentContext context) throws Exception {       
       
         DeploymentConfigurationManager cm = (DeploymentConfigurationManager)context.getConfigurationManager();
-        Collection<ListableRepository> repositories = cm.getRepositories();
-
-        jars.add(getLocation(repositories, JAXB_API_ARTIFACT));
-        jars.add(getLocation(repositories, JAXB_IMPL_ARTIFACT));
-        jars.add(getLocation(repositories, JAXB_XJC_ARTIFACT));
-        jars.add(getLocation(repositories, JAXWS_TOOLS_ARTIFACT));
-        jars.add(getLocation(repositories, JAXWS_RT_ARTIFACT));
-        jars.add(getLocation(repositories, AXIS2_JAXWS_API_ARTIFACT));
-        jars.add(getLocation(repositories, AXIS2_SAAJ_API_ARTIFACT));
-        jars.add(getLocation(repositories, GERONIMO_ACTIVATION_SPEC_ARTIFACT));
-        jars.add(getLocation(repositories, GERONIMO_ANNOTATION_ARTIFACT));
-        jars.add(getLocation(repositories, GERONIMO_WS_METADATA_ARTIFACT));
-        jars.add(getLocation(repositories, GERONIMO_EJB_SPEC_ARTIFACT));
-        if (this.saajImpl != null) {
-            jars.add(getLocation(repositories, this.saajImpl));
-        }
-        jars.add(new File(getToolsJarLoc()).toURL());
-         
-        return jars.toArray(new URL[jars.size()]);        
+        Collection<ListableRepository> repositories = cm.getRepositories();       

+        File[] jars = this.jaxwsTools.getClasspath(repositories);
+        return JAXWSTools.toURL(jars);
     }
     
     private static String getModuleClasspath(Module module, DeploymentContext context) throws
DeploymentException {
@@ -156,52 +132,7 @@
         }
         return classpath.toString();
     }
-    
-    private static URL getLocation(Collection<ListableRepository> repositories, Artifact
artifactQuery) throws DeploymentException, MalformedURLException {
-        File file = null;
         
-        for (ListableRepository repository : repositories) {
-            SortedSet artifactSet = repository.list(artifactQuery);
-            // if we have exactly one artifact found
-            if (artifactSet.size() == 1) {
-                file = repository.getLocation((Artifact) artifactSet.first());
-                return file.getAbsoluteFile().toURL();
-            } else if (artifactSet.size() > 1) {// if we have more than 1 artifacts found
use the latest one.
-                file = repository.getLocation((Artifact) artifactSet.last());
-                return file.getAbsoluteFile().toURL();
-            } 
-        }
-        if (file == null) {
-            throw new DeploymentException("Missing artifact in repositories: " + artifactQuery.toString());
-        }
-        return null;
-    }
-    
-    private static String getToolsJarLoc() throws DeploymentException {
-        //create a new File then check exists()
-        String jreHomePath = System.getProperty("java.home");
-        String javaHomePath = "";
-        int jreHomePathLength = jreHomePath.length();
-        if (jreHomePathLength > 0) {
-            int i = jreHomePath.substring(0, jreHomePathLength -1).lastIndexOf(java.io.File.separator);
-            javaHomePath = jreHomePath.substring(0, i);
-        }
-        File jdkhomelib = new File(javaHomePath + java.io.File.separator + "lib");
-        if (!jdkhomelib.exists()) {
-            throw new DeploymentException("Missing " + jdkhomelib.getAbsolutePath() 
-                    + ". This is required for wsgen to run. ");
-        }
-        else {
-            File tools = new File(jdkhomelib + java.io.File.separator + TOOLS);
-            if (!tools.exists()) {
-                throw new DeploymentException("Missing tools.jar in" + jdkhomelib.getAbsolutePath()

-                        + ". This is required for wsgen to run. ");                
-            } else {
-                return tools.getAbsolutePath();
-            }               
-        }
-    }
-    
     private static File toFile(URL url) {
         if (url == null || !url.getProtocol().equals("file")) {
             return null;
@@ -332,8 +263,8 @@
         //let's figure out the classpath for wsgen tools
         try {
              urls = getWsgenClasspath(context);
-        } catch (MalformedURLException e) {
-            throw new DeploymentException("unable to generate the wsdl file using wsgen.
- unable to get the location of the required artifact(s).", e);
+        } catch (Exception e) {
+            throw new DeploymentException("Failed to generate the wsdl file using wsgen:
unable to get the location of the required artifact(s).", e);
         } 
         //let's figure out the classpath string for the module and wsgen tools.
         if (urls != null && urls.length > 0) {
@@ -373,27 +304,18 @@
         }
     }
 
-    private boolean invokeWsgen(URL[] urls, String[] arguments) throws Exception {
-        URLClassLoader loader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
-        Class clazz = loader.loadClass("com.sun.tools.ws.spi.WSToolsObjectFactory");
-        Method method = clazz.getMethod("newInstance");
-        Object factory = method.invoke(null);
-        Method method2 = clazz.getMethod("wsgen", OutputStream.class, String[].class);
+    private boolean invokeWsgen(URL[] jars, String[] arguments) throws Exception {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        
-        LOG.debug("Invoking wsgen");
-        
-        Boolean result = (Boolean) method2.invoke(factory, os, arguments);
+        boolean rs = this.jaxwsTools.invokeWsgen(jars, os, arguments);
         os.close();
         
-        byte [] arr = os.toByteArray();
-        String wsgenOutput = new String(arr, 0, arr.length);
-        
         if (LOG.isDebugEnabled()) {
+            byte [] arr = os.toByteArray();
+            String wsgenOutput = new String(arr, 0, arr.length);
             LOG.debug("wsgen output: " + wsgenOutput);
         }
         
-        return result;
+        return rs;
     }
     
     private boolean forkWsgen(StringBuilder classPath, String[] arguments) throws Exception
{           
@@ -413,8 +335,8 @@
         String [] cmdArray = (String[]) cmd.toArray(new String[] {});
         
         Process process = Runtime.getRuntime().exec(cmdArray);
-        int errorCode = process.waitFor();
-        
+        int errorCode = waitFor(process);
+                
         if (errorCode == 0) {
             return true;
         } else {
@@ -423,5 +345,28 @@
             }
             return false;
         }
+    }
+    
+    private int waitFor(Process process) throws DeploymentException {
+        long sleepTime = 0;        
+        while(sleepTime < this.forkTimeout) {            
+            try {
+                return process.exitValue();
+            } catch (IllegalThreadStateException e) {
+                // still running
+                try {
+                    Thread.sleep(FORK_POLL_FREQUENCY);
+                } catch (InterruptedException ee) {
+                    // interrupted
+                    process.destroy();
+                    throw new DeploymentException("wsgen interrupted");
+                }
+                sleepTime += FORK_POLL_FREQUENCY;
+            }
+        }
+        
+        // timeout;
+        process.destroy();      
+        throw new DeploymentException("wsgen timed out");
     }
 }



Mime
View raw message