You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dw...@apache.org on 2008/03/06 16:00:19 UTC
svn commit: r634285 -
/geronimo/server/branches/2.0/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
Author: dwoods
Date: Thu Mar 6 07:00:18 2008
New Revision: 634285
URL: http://svn.apache.org/viewvc?rev=634285&view=rev
Log:
GERONIMO-3828 Provide jaxws-tools stack traces to the server.log
Modified:
geronimo/server/branches/2.0/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
Modified: geronimo/server/branches/2.0/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java?rev=634285&r1=634284&r2=634285&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java (original)
+++ geronimo/server/branches/2.0/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java Thu Mar 6 07:00:18 2008
@@ -21,6 +21,8 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.ArrayList;
@@ -116,7 +118,7 @@
private URL[] getWsgenClasspath(DeploymentContext context) throws Exception {
DeploymentConfigurationManager cm = (DeploymentConfigurationManager)context.getConfigurationManager();
- Collection<Repository> repositories = cm.getRepositories();
+ Collection<? extends Repository> repositories = cm.getRepositories();
File[] jars = this.jaxwsTools.getClasspath(repositories);
return JAXWSTools.toURL(jars);
}
@@ -313,7 +315,7 @@
}
return getRelativeNameOrURL(moduleBase, wsdlFile);
} else {
- throw new DeploymentException("wsgen failed");
+ throw new DeploymentException("WSDL generation failed");
}
} catch (DeploymentException e) {
@@ -350,27 +352,32 @@
if (LOG.isDebugEnabled()) {
LOG.debug("Executing wsgen: " + cmd);
}
+
+ ProcessBuilder builder = new ProcessBuilder(cmd);
+ builder.redirectErrorStream(true);
- String [] cmdArray = (String[]) cmd.toArray(new String[] {});
-
- Process process = Runtime.getRuntime().exec(cmdArray);
- int errorCode = waitFor(process);
-
- if (errorCode == 0) {
- return true;
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("wsgen error code: " + errorCode);
- }
- return false;
- }
+ Process process = builder.start();
+ return waitFor(process);
}
- private int waitFor(Process process) throws DeploymentException {
+ private boolean waitFor(Process process) throws DeploymentException {
+ CaptureOutputThread outputThread = new CaptureOutputThread(process.getInputStream());
+ outputThread.start();
+
long sleepTime = 0;
while(sleepTime < this.forkTimeout) {
try {
- return process.exitValue();
+ int errorCode = process.exitValue();
+ if (errorCode == 0) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("wsgen output: " + outputThread.getOutput());
+ }
+ return true;
+ } else {
+ LOG.error("WSDL generation process failed");
+ LOG.error(outputThread.getOutput());
+ return false;
+ }
} catch (IllegalThreadStateException e) {
// still running
try {
@@ -378,14 +385,68 @@
} catch (InterruptedException ee) {
// interrupted
process.destroy();
- throw new DeploymentException("wsgen interrupted");
+ throw new DeploymentException("WSDL generation process was interrupted");
}
sleepTime += FORK_POLL_FREQUENCY;
}
}
// timeout;
- process.destroy();
- throw new DeploymentException("wsgen timed out");
+ process.destroy();
+
+ LOG.error("WSDL generation process timed out");
+ LOG.error(outputThread.getOutput());
+
+ throw new DeploymentException("WSDL generation process timed out");
+ }
+
+ private static class CaptureOutputThread extends Thread {
+
+ private InputStream in;
+ private ByteArrayOutputStream out;
+
+ public CaptureOutputThread(InputStream in) {
+ this.in = in;
+ this.out = new ByteArrayOutputStream();
+ }
+
+ public String getOutput() {
+ // make sure the thread is done
+ try {
+ join(10 * 1000);
+
+ // if it's still not done, interrupt it
+ if (isAlive()) {
+ interrupt();
+ }
+ } catch (InterruptedException e) {
+ // that's ok
+ }
+
+ // get the output
+ byte [] arr = this.out.toByteArray();
+ String output = new String(arr, 0, arr.length);
+ return output;
+ }
+
+ public void run() {
+ try {
+ copyAll(this.in, this.out);
+ } catch (IOException e) {
+ // ignore
+ } finally {
+ try { this.out.close(); } catch (IOException ee) {}
+ try { this.in.close(); } catch (IOException ee) {}
+ }
+ }
+
+ private static void copyAll(InputStream in, OutputStream out) throws IOException {
+ byte[] buffer = new byte[4096];
+ int count;
+ while ((count = in.read(buffer)) > 0) {
+ out.write(buffer, 0, count);
+ }
+ out.flush();
+ }
}
}