tomj 02/04/11 08:45:09
Modified: java/src/org/apache/axis/wsdl WSDL2Java.java
java/docs user-guide.html
java/src/org/apache/axis/utils resources.properties
java/src/org/apache/axis/wsdl/toJava Emitter.java
Log:
Username and password on WSDL URL did not work.
- Add the -U/--user and -P/-password options to WSDL2Java command line
- Parse the URL and extract the userInfo to get username/password
- Register a default Authenticator to use when the URL is resolved,
to provide login info. This will fall back to http.ProxyUser and
http.proxyPassword properties if user or password is not found via switch or
the URI.
- Check for a null document and print a error instead of NPE when we
fail to get the WSDL
- Update the use-guide with new -U/-P switch info.
Revision Changes Path
1.22 +78 -6 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- WSDL2Java.java 29 Mar 2002 22:13:05 -0000 1.21
+++ WSDL2Java.java 11 Apr 2002 15:45:09 -0000 1.22
@@ -75,6 +75,8 @@
import java.io.IOException;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.HashMap;
import java.util.List;
@@ -102,6 +104,8 @@
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';
+ protected static final int PASSWORD_OPT = 'P';
// Scope constants
@@ -110,6 +114,10 @@
public static final byte REQUEST_SCOPE = 0x10;
public static final byte SESSION_SCOPE = 0x11;
+ // Username and password for Authentication
+ protected String username = null;
+ protected String password = null;
+
// The emitter framework Emitter class.
protected Emitter emitter;
// Timeout, in milliseconds, to let the Emitter do its work
@@ -194,7 +202,15 @@
new CLOptionDescriptor("timeout",
CLOptionDescriptor.ARGUMENT_REQUIRED,
NETWORK_TIMEOUT_OPT,
- JavaUtils.getMessage("optionTimeout00"))
+ JavaUtils.getMessage("optionTimeout00")),
+ new CLOptionDescriptor("user",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ USERNAME_OPT,
+ JavaUtils.getMessage("optionUsername")),
+ new CLOptionDescriptor("password",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ PASSWORD_OPT,
+ JavaUtils.getMessage("optionPassword"))
};
/**
@@ -409,6 +425,22 @@
public void setTimeout(long timeout) {
this.timeoutms = timeout;
}
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
//
// Command line switches
//
@@ -456,7 +488,7 @@
public void emit(String wsdlURL)
throws Exception {
- Authenticator.setDefault(new DefaultAuthenticator());
+ Authenticator.setDefault(new DefaultAuthenticator(this));
// We run the actual Emitter in a thread that we can kill
WSDLRunnable runnable = new WSDLRunnable(emitter, wsdlURL);
@@ -632,6 +664,15 @@
timeout = timeout * 1000;
wsdl2java.setTimeout(timeout);
break;
+
+ case USERNAME_OPT:
+ wsdl2java.setUsername(option.getArgument());
+ break;
+
+ case PASSWORD_OPT:
+ wsdl2java.setPassword(option.getArgument());
+ break;
+
}
}
@@ -652,6 +693,9 @@
if (!namespaceMap.isEmpty()) {
wsdl2java.setNamespaceMap(namespaceMap);
}
+
+ // Set username and password if provided in URL
+ wsdl2java.checkForAuthInfo(wsdlURI);
wsdl2java.setTypeMappingVersion(typeMappingVersion);
wsdl2java.emit(wsdlURI);
@@ -747,12 +791,40 @@
System.exit(1);
}
+ private void checkForAuthInfo(String uri) throws MalformedURLException {
+ URL url = new URL(uri);
+ String userInfo = url.getUserInfo();
+ if (userInfo != null) {
+ int i = userInfo.indexOf(':');
+ if (i >= 0) {
+ this.username = userInfo.substring(0,i);
+ this.password = userInfo.substring(i+1);
+ } else {
+ this.username = userInfo;
+ }
+ }
+ }
+
private class DefaultAuthenticator extends Authenticator {
+ private WSDL2Java wsdl2java;
+
+ DefaultAuthenticator(WSDL2Java wsdl2java) {
+ this.wsdl2java = wsdl2java;
+ }
protected PasswordAuthentication getPasswordAuthentication() {
- String proxyUser = System.getProperty("http.proxyUser","");
- String proxyPassword = System.getProperty("http.proxyPassword","");
- System.out.println("Authenticator:" + getRequestingPrompt() + "[" +
proxyUser + ":" + proxyPassword + "]");
- return new PasswordAuthentication (proxyUser,
proxyPassword.toCharArray());
+ // First check command line options
+ String user = wsdl2java.getUsername();
+ String password = wsdl2java.getPassword();
+
+ // if we didn't get them, check the system properties
+ if (user == null) {
+ user = System.getProperty("http.proxyUser","");
+ }
+ if (password == null) {
+ password = System.getProperty("http.proxyPassword","");
+ }
+
+ return new PasswordAuthentication (user, password.toCharArray());
}
}
}
1.54 +16 -1 xml-axis/java/docs/user-guide.html
Index: user-guide.html
===================================================================
RCS file: /home/cvs/xml-axis/java/docs/user-guide.html,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- user-guide.html 11 Apr 2002 14:57:23 -0000 1.53
+++ user-guide.html 11 Apr 2002 15:45:09 -0000 1.54
@@ -982,7 +982,12 @@
<br> -O, --timeout <argument>
<br>
timeout in seconds (default is 45, specify -1 to disable)
-<br>
+<br> -U, --user <argument>
+<br>
+username to access the WSDL-URI
+<br> -P, --password <argument>
+<br>
+password to access the WSDL-URI <br>
<h4>
-h, --help</h4>
Print the usage statement and exit
@@ -1111,6 +1116,16 @@
<h4>
-T, --typeMappingVersion <argument></h4>
Indicate 1.1 or 1.2. The default is 1.2 (SOAP 1.2 JAX-RPC compliant).
+<h4> -U, --user <argument></h4>
+This username is used in resolving the WSDL-URI provided as the input to
+WSDL2Java. If the URI contains a username, this will override the command
+line switch. An example of a URL with a username and password is:
+<code>http://user:password@hostname:port/path/to/service?WSDL</code><br>
+<h4> -P, --password <argument></h4>
+ This password is used in resolving the WSDL-URI provided as the input to WSDL2Java.
+ If the URI contains a password, this will override the command
+line switch.<br>
+
<br>
<h3>
<a NAME="Java2WSDL: Building WSDL from Java"></a>Java2WSDL: Building WSDL
1.90 +5 -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.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- resources.properties 11 Apr 2002 13:30:55 -0000 1.89
+++ resources.properties 11 Apr 2002 15:45:09 -0000 1.90
@@ -798,3 +798,8 @@
attach.bounday.mns=Marking streams not supported.
noSuchOperation=No such operation ''{0}''
+
+optionUsername=username to access the WSDL-URI
+optionPassword=password to access the WSDL-URI
+cantGetDoc00=Unable to retrieve WSDL document: {0}
+
1.31 +5 -1 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.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- Emitter.java 29 Mar 2002 22:13:05 -0000 1.30
+++ Emitter.java 11 Apr 2002 15:45:09 -0000 1.31
@@ -160,7 +160,11 @@
if (bVerbose)
System.out.println(JavaUtils.getMessage("parsing00", uri));
- emit(uri, XMLUtils.newDocument(uri));
+ Document doc = XMLUtils.newDocument(uri);
+ if (doc == null) {
+ throw new IOException(JavaUtils.getMessage("cantGetDoc00", uri));
+ }
+ emit(uri, doc);
} // emit
/**