butek 02/05/10 07:45:04
Modified: java/src/org/apache/axis/wsdl WSDL2Java.java
java/src/org/apache/axis/wsdl/gen Parser.java WSDL2.java
java/src/org/apache/axis/wsdl/toJava Emitter.java
Log:
Timeout was broken. The worst problem was that Wsdl2javaAntTask
just STOPPED when a timeout occurred. Secondly, the timeout really
belongs in Parser, not in Emitter. I tossed the version of timeout that I
wrote and replaced it with something a lot closer to the original. (My
version was erroneously written for the command line WSDL2Java, not
the programmatic Emitter).
Revision Changes Path
1.30 +0 -14 xml-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java
Index: WSDL2Java.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- WSDL2Java.java 10 May 2002 13:30:34 -0000 1.29
+++ WSDL2Java.java 10 May 2002 14:45:04 -0000 1.30
@@ -81,7 +81,6 @@
protected static final int PACKAGE_OPT = 'p';
protected static final int ALL_OPT = 'a';
protected static final int TYPEMAPPING_OPT = 'T';
- protected static final int NETWORK_TIMEOUT_OPT = 'O';
protected static final int FACTORY_CLASS_OPT = 'F';
protected static final int HELPER_CLASS_OPT = 'H';
protected static final int USERNAME_OPT = 'U';
@@ -148,10 +147,6 @@
CLOptionDescriptor.ARGUMENT_DISALLOWED,
HELPER_CLASS_OPT,
JavaUtils.getMessage("optionHelper00")),
- new CLOptionDescriptor("timeout",
- CLOptionDescriptor.ARGUMENT_REQUIRED,
- NETWORK_TIMEOUT_OPT,
- JavaUtils.getMessage("optionTimeout00")),
new CLOptionDescriptor("user",
CLOptionDescriptor.ARGUMENT_REQUIRED,
USERNAME_OPT,
@@ -250,15 +245,6 @@
} else {
System.out.println(JavaUtils.getMessage("badTypeMappingOption00"));
}
- break;
-
- case NETWORK_TIMEOUT_OPT:
- String timeoutValue = option.getArgument();
- long timeout = Long.parseLong(timeoutValue);
- // Convert seconds to milliseconds.
- if(timeout > 0)
- timeout = timeout * 1000;
- emitter.setTimeout(timeout);
break;
case USERNAME_OPT:
1.4 +71 -3 xml-axis/java/src/org/apache/axis/wsdl/gen/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/gen/Parser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Parser.java 10 May 2002 13:30:35 -0000 1.3
+++ Parser.java 10 May 2002 14:45:04 -0000 1.4
@@ -87,6 +87,9 @@
protected String username = null;
protected String password = null;
+ // Timeout, in milliseconds, to let the Emitter do its work
+ private long timeoutms = 45000; // 45 sec default
+
private GeneratorFactory genFactory = null;
private SymbolTable symbolTable = null;
@@ -114,6 +117,20 @@
this.verbose = verbose;
} // setVerbose
+ /**
+ * Return the current timeout setting
+ */
+ public long getTimeout() {
+ return timeoutms;
+ }
+
+ /**
+ * Set the timeout, in milliseconds
+ */
+ public void setTimeout(long timeout) {
+ this.timeoutms = timeout;
+ }
+
public String getUsername() {
return username;
} // getUsername
@@ -162,7 +179,14 @@
return symbolTable == null ? null : symbolTable.getWSDLURI();
} // getWSDLURI
- public void run(String wsdlURI) throws IOException, WSDLException {
+ /**
+ * Parse a WSDL at a given URL.
+ *
+ * This method will time out after the number of milliseconds specified
+ * by our timeoutms member.
+ *
+ */
+ public void run(String wsdlURI) throws Exception {
if (getFactory() == null) {
setFactory(new NoopFactory());
}
@@ -171,9 +195,53 @@
imports,
verbose,
debug);
- symbolTable.populate(wsdlURI, username, password);
- generate(symbolTable);
+
+ // We run the actual Emitter in a thread that we can kill
+ WSDLRunnable runnable = new WSDLRunnable(symbolTable, wsdlURI);
+ Thread wsdlThread = new Thread(runnable);
+ wsdlThread.start();
+
+ try {
+ if (timeoutms > 0)
+ wsdlThread.join(timeoutms);
+ else
+ wsdlThread.join();
+ } catch (InterruptedException e) {
+ }
+
+ if (wsdlThread.isAlive()) {
+ wsdlThread.interrupt();
+ throw new IOException(JavaUtils.getMessage("timedOut"));
+ }
+
+ if (runnable.getFailure() != null) {
+ throw runnable.getFailure();
+ }
} // run
+
+ private class WSDLRunnable implements Runnable {
+ private SymbolTable symbolTable;
+ private String wsdlURI;
+ private Exception failure = null;
+
+ public WSDLRunnable(SymbolTable symbolTable, String wsdlURI) {
+ this.symbolTable = symbolTable;
+ this.wsdlURI = wsdlURI;
+ } // ctor
+
+ public void run() {
+ try {
+ symbolTable.populate(wsdlURI, username, password);
+ generate(symbolTable);
+ } catch (Exception e) {
+ failure = e;
+ }
+ } // run
+
+ public Exception getFailure() {
+ return failure;
+ } // getFailure
+ } // WSDLRunnable
/**
* Call this method if your WSDL document has already been parsed as an XML DOM
document.
1.4 +14 -0 xml-axis/java/src/org/apache/axis/wsdl/gen/WSDL2.java
Index: WSDL2.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/gen/WSDL2.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WSDL2.java 9 May 2002 15:47:38 -0000 1.3
+++ WSDL2.java 10 May 2002 14:45:04 -0000 1.4
@@ -71,6 +71,7 @@
protected static final int DEBUG_OPT = 'D';
protected static final int HELP_OPT = 'h';
+ protected static final int NETWORK_TIMEOUT_OPT = 'O';
protected static final int NOIMPORTS_OPT = 'n';
protected static final int VERBOSE_OPT = 'v';
@@ -87,6 +88,10 @@
CLOptionDescriptor.ARGUMENT_DISALLOWED,
NOIMPORTS_OPT,
JavaUtils.getMessage("optionImport00")),
+ new CLOptionDescriptor("timeout",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ NETWORK_TIMEOUT_OPT,
+ JavaUtils.getMessage("optionTimeout00")),
new CLOptionDescriptor("Debug",
CLOptionDescriptor.ARGUMENT_DISALLOWED,
DEBUG_OPT,
@@ -133,6 +138,15 @@
case NOIMPORTS_OPT:
parser.setImports(false);
+ break;
+
+ case NETWORK_TIMEOUT_OPT:
+ String timeoutValue = option.getArgument();
+ long timeout = Long.parseLong(timeoutValue);
+ // Convert seconds to milliseconds.
+ if(timeout > 0)
+ timeout = timeout * 1000;
+ parser.setTimeout(timeout);
break;
case VERBOSE_OPT:
1.38 +2 -67 xml-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java
Index: Emitter.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Emitter.java 10 May 2002 13:30:35 -0000 1.37
+++ Emitter.java 10 May 2002 14:45:04 -0000 1.38
@@ -115,9 +115,6 @@
private HashMap delayedNamespacesMap = new HashMap();
private String outputDir = null;
- // Timeout, in milliseconds, to let the Emitter do its work
- private long timeoutms = 45000; // 45 sec default
-
/**
* Default constructor.
*/
@@ -279,20 +276,6 @@
return delayedNamespacesMap;
}
- /**
- * Return the current timeout setting
- */
- public long getTimeout() {
- return timeoutms;
- }
-
- /**
- * Set the timeout, in milliseconds
- */
- public void setTimeout(long timeout) {
- this.timeoutms = timeout;
- }
-
/**
* Sets the <code>WriterFactory Class</code> to use
* @param className the name of the factory <code>Class</code>
@@ -394,12 +377,9 @@
* by our timeoutms member.
*
*/
- public void run(String wsdlURL) throws IOException, WSDLException {
+ public void run(String wsdlURL) throws Exception {
setup();
-
- Timer timer = startTimer();
super.run(wsdlURL);
- timer.stop();
} // run
/**
@@ -409,9 +389,7 @@
*/
public void run(String context, Document doc) throws IOException, WSDLException
{
setup();
- Timer timer = startTimer();
super.run(context, doc);
- timer.stop();
} // run
private void setup() {
@@ -436,15 +414,6 @@
}
} // setup
- private Timer startTimer() {
- // We run a timout thread that can kill this one if it goes too long.
- Timer timer = new Timer(Thread.currentThread(), timeoutms);
- Thread timerThread = new Thread(timer);
- timerThread.setDaemon(true);
- timerThread.start();
- return timer;
- } // startTimer
-
/**
* Look for a NStoPkg.properties file in the CLASSPATH. If it exists,
* then collect the namespace->package mappings from it.
@@ -473,40 +442,6 @@
}
} // getNStoPkgFromPropsFile
- private class Timer implements Runnable {
- private Thread wsdl2JavaThread;
- private long timeout;
- private boolean stop = false;
-
- public Timer(Thread wsdl2JavaThread, long timeout) {
- this.wsdl2JavaThread = wsdl2JavaThread;
- this.timeout = timeout;
- }
-
- public void run() {
- try {
- if (timeout > 0)
- wsdl2JavaThread.join(timeoutms);
- else
- wsdl2JavaThread.join();
- }
- catch (InterruptedException e) {
- }
-
- if (!stop && wsdl2JavaThread.isAlive()) {
- // Calling this: wsdl2JavaThread.interrupt();
- // doesn't accomplish anything, so just exit.
- System.out.println(JavaUtils.getMessage("timedOut"));
- System.exit(1);
- }
- } // run
-
- public void stop() {
- stop = true;
- } // stop
-
- } // class Timer
-
public void setTypeMappingVersion(String typeMappingVersion) {
if (typeMappingVersion.equals("1.1")) {
baseTypeMapping =
@@ -559,7 +494,7 @@
* @param uri wsdlURI the location of the WSDL file.
* @deprecated Call run(uri) instead.
*/
- public void emit(String uri) throws IOException, WSDLException {
+ public void emit(String uri) throws Exception {
run(uri);
} // emit