You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by gd...@apache.org on 2002/03/13 06:18:07 UTC
cvs commit: xml-axis/java/src/org/apache/axis/utils resources.properties
gdaniels 02/03/12 21:18:06
Modified: java/test/wsdl Wsdl2javaAntTask.java
java/src/org/apache/axis/wsdl WSDL2Java.java
java/src/org/apache/axis/utils resources.properties
Log:
Introduce a timeout (defaulted to 45 seconds) on the WSDL2Java
emitter. This is exposed as a "timeout" option in the WSDL2Java ant
task, but not yet as a command-line option for WSDL2Java.
Revision Changes Path
1.22 +14 -9 xml-axis/java/test/wsdl/Wsdl2javaAntTask.java
Index: Wsdl2javaAntTask.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/wsdl/Wsdl2javaAntTask.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Wsdl2javaAntTask.java 5 Mar 2002 14:52:53 -0000 1.21
+++ Wsdl2javaAntTask.java 13 Mar 2002 05:18:06 -0000 1.22
@@ -86,6 +86,7 @@
private String deployScope = "";
private String url = "";
private String tm = "1.2";
+ private long timeout = 45000;
// The method executing the task
public void execute() throws BuildException {
@@ -102,7 +103,8 @@
log("\tURL:" + url, Project.MSG_VERBOSE);
log("\tall:" + all, Project.MSG_VERBOSE);
log("\ttypeMappingVersion:" + tm, Project.MSG_VERBOSE);
-
+ log("\ttimeout:" + timeout, Project.MSG_VERBOSE);
+
// Instantiate the emitter
WSDL2Java emitter = new WSDL2Java();
@@ -133,15 +135,11 @@
emitter.verbose(verbose);
emitter.setTypeMappingVersion(tm);
emitter.setNStoPkg(project.resolveFile("NStoPkg.properties"));
-
- Document doc;
+ emitter.setTimeout(timeout);
log("WSDL2Java " + url, Project.MSG_INFO);
try {
- doc = XMLUtils.newDocument(url);
- doc.getDocumentElement().getTagName();
- // THIS IS WRONG - the one outside the try-catch block is right
- emitter.emit(url, doc);
+ emitter.emit(url);
} catch (Throwable e) {
if (url.startsWith("http://")) {
// What we have is either a network error or invalid XML -
@@ -153,8 +151,6 @@
}
throw e;
}
-
- // emitter.emit(doc);
} catch (Throwable t) {
t.printStackTrace();
throw new BuildException("Error while running " + getClass().getName(), t);
@@ -213,6 +209,15 @@
// The setter for the "typeMappingVersion" attribute
public void setTypeMappingVersion(String parameter) {
this.tm = parameter;
+ }
+
+ // The setter for the "timeout" attribute
+ public void setTimeout(String parameter) {
+ try {
+ this.timeout = new Long(parameter).longValue();
+ } catch (NumberFormatException e) {
+ // Sorry, stick with default.
+ }
}
/** the command arguments */
1.12 +99 -30 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- WSDL2Java.java 11 Mar 2002 14:51:36 -0000 1.11
+++ WSDL2Java.java 13 Mar 2002 05:18:06 -0000 1.12
@@ -78,6 +78,7 @@
import java.util.HashMap;
import java.util.List;
+import java.util.Date;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
@@ -112,6 +113,8 @@
// The emitter framework Emitter class.
private Emitter emitter;
+ // Timeout, in milliseconds, to let the Emitter do its work
+ private long timeoutms = 45000; // 45 sec default
JavaWriterFactory writerFactory = null;
@@ -208,7 +211,7 @@
/**
* Indicate if we should be emitting server side code and deploy/undeploy
- */
+ */
public boolean getGenerateServerSide() {
return emitter.getGenerateServerSide();
}
@@ -223,7 +226,7 @@
/**
* Indicate if we should be deploying skeleton or implementation
- */
+ */
public boolean getDeploySkeleton() {
return emitter.getDeploySkeleton();
}
@@ -238,11 +241,11 @@
/**
* Return the current definition
- */
+ */
public Definition getCurrentDefinition() {
return emitter.getCurrentDefinition();
}
-
+
/**
* Turn on/off generation of elements from imported files.
* @param boolean generateImports
@@ -287,14 +290,14 @@
/**
* Return the status of the verbose switch
- */
+ */
public boolean getVerbose() {
return emitter.getVerbose();
}
/**
* Set a map of namespace -> Java package names
- */
+ */
public void setNamespaceMap(HashMap map) {
emitter.setNamespaceMap(map);
}
@@ -309,25 +312,25 @@
/**
* Get global package name to use instead of mapping namespaces
- */
+ */
public String getPackageName() {
return emitter.getPackageName();
}
/**
* Set a global package name to use instead of mapping namespaces
- */
+ */
public void setPackageName(String packageName) {
emitter.setPackageName(packageName);
}
-
+
/**
* Get the output directory to use for emitted source files
*/
public String getOutputDir() {
return emitter.getOutputDir();
}
-
+
/**
* Set the scope for the deploy.xml file.
* @param scope One of Emitter.NO_EXPLICIT_SCOPE, Emitter.APPLICATION_SCOPE, Emitter.REQUEST_SCOPE, Emitter.SESSION_SCOPE. Anything else is equivalent to NO_EXPLICIT_SCOPE and no explicit scope tag will appear in deploy.xml.
@@ -357,6 +360,19 @@
emitter.setNStoPkg(NStoPkgFile);
} // setNStoPkg
+ /**
+ * Return the current timeout setting
+ */
+ public long getTimeout() {
+ return timeoutms;
+ }
+
+ /**
+ * Set the timeout, in milliseconds
+ */
+ public void setTimeout(long timeout) {
+ this.timeoutms = timeout;
+ }
//
// Command line switches
//
@@ -365,10 +381,10 @@
/**
* Returns an object which contains of information on all generated files
* including the class name, filename and a type string.
- *
+ *
* @return A org.apache.axis.wsdl.toJava.GeneratedFileInfo object
* @see org.apache.axis.wsdl.toJava.GeneratedFileInfo
- */
+ */
public GeneratedFileInfo getGeneratedFileInfo()
{
return emitter.getGeneratedFileInfo();
@@ -376,7 +392,7 @@
/**
* Return a list of all generated class names.
- *
+ *
* @return list of class names (strings)
*/
public List getGeneratedClassNames() {
@@ -385,21 +401,45 @@
/**
* Return a list of all generated file names.
- *
+ *
* @return list of relative path names (strings)
*/
public List getGeneratedFileNames() {
return emitter.getGeneratedFileNames();
}
-
+
/**
- * Call this method if you have a uri for the WSDL document
+ * Emit appropriate Java files for a WSDL at a given URL.
+ *
+ * This method will time out after the number of milliseconds specified
+ * by our timeoutms member.
+ *
* @param String wsdlURI the location of the WSDL file.
*/
- public void emit(String wsdlURI)
- throws IOException, WSDLException {
- emitter.emit(wsdlURI);
+ public void emit(String wsdlURL)
+ throws Exception {
+
+ // We run the actual Emitter in a thread that we can kill
+ WSDLRunnable runnable = new WSDLRunnable(emitter, wsdlURL);
+ Thread wsdlThread = new Thread(runnable);
+
+ long timeout = new Date().getTime() + timeoutms;
+
+ wsdlThread.start();
+
+ while (!runnable.isDone()) {
+ // Check at one-second intervals
+ Thread.sleep(1000);
+ if (new Date().getTime() > timeout) {
+ wsdlThread.interrupt();
+ throw new Exception(JavaUtils.getMessage("timedOut"));
+ }
+ }
+
+ if (runnable.getFailure() != null) {
+ throw runnable.getFailure();
+ }
} // emit
/**
@@ -533,10 +573,10 @@
} else {
System.out.println(JavaUtils.getMessage("badTypeMappingOption00"));
}
- break;
+ break;
}
}
-
+
// validate argument combinations
//
if (wsdlURI == null) {
@@ -557,7 +597,7 @@
wsdl2java.setTypeMappingVersion(typeMappingVersion);
wsdl2java.emit(wsdlURI);
-
+
// everything is good
System.exit(0);
}
@@ -567,39 +607,68 @@
}
}
+ private class WSDLRunnable implements Runnable {
+ private Emitter emitter;
+ private String uri;
+ private boolean done = false;
+ private Exception failure = null;
+
+ public WSDLRunnable(Emitter emitter, String uri) {
+ this.emitter = emitter;
+ this.uri = uri;
+ }
+
+ public void run() {
+ try {
+ emitter.emit(uri);
+ } catch (Exception e) {
+ failure = e;
+ }
+ done = true;
+ }
+
+ public boolean isDone() {
+ return done;
+ }
+
+ public Exception getFailure() {
+ return failure;
+ }
+ }
+
public void setTypeMappingVersion(String typeMappingVersion) {
if (typeMappingVersion.equals("1.1")) {
writerFactory.setBaseTypeMapping(
new BaseTypeMapping() {
final TypeMapping defaultTM = DefaultTypeMappingImpl.create();
public String getBaseName(QName qNameIn) {
- javax.xml.rpc.namespace.QName qName =
+ javax.xml.rpc.namespace.QName qName =
new javax.xml.rpc.namespace.QName(
- qNameIn.getNamespaceURI(),
+ qNameIn.getNamespaceURI(),
qNameIn.getLocalPart());
Class cls = defaultTM.getClassForQName(qName);
if (cls == null)
return null;
- else
+ else
return JavaUtils.getTextClassName(cls.getName());
}
- });
+ });
} else {
writerFactory.setBaseTypeMapping(
new BaseTypeMapping() {
final TypeMapping defaultTM = DefaultSOAP12TypeMappingImpl.create();
public String getBaseName(QName qNameIn) {
- javax.xml.rpc.namespace.QName qName =
+ javax.xml.rpc.namespace.QName qName =
new javax.xml.rpc.namespace.QName(
- qNameIn.getNamespaceURI(),
+ qNameIn.getNamespaceURI(),
qNameIn.getLocalPart());
Class cls = defaultTM.getClassForQName(qName);
if (cls == null)
return null;
- else
+ else
return JavaUtils.getTextClassName(cls.getName());
}
- });
+ });
}
}
/**
1.68 +2 -0 xml-axis/java/src/org/apache/axis/utils/resources.properties
Index: resources.properties
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/resources.properties,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- resources.properties 11 Mar 2002 16:25:31 -0000 1.67
+++ resources.properties 13 Mar 2002 05:18:06 -0000 1.68
@@ -691,3 +691,5 @@
badSkeleton00=Error: --skeletonDeploy cannot be specified without --server-side.
badStyle=Bad string for style value - was ''{0}'', should be ''rpc'', ''document'', or ''wrapped''.
onlyOneMapping=Only a single <elementMapping> is allowed per-operation at present.
+
+timedOut=WSDL2Java emitter timed out (this often means the WSDL at the specified URL is inaccessible)!