Index: src/java/org/apache/commons/httpclient/HttpURL.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java,v retrieving revision 1.12.2.4 diff -u -r1.12.2.4 HttpURL.java --- src/java/org/apache/commons/httpclient/HttpURL.java 2 May 2004 15:15:34 -0000 1.12.2.4 +++ src/java/org/apache/commons/httpclient/HttpURL.java 8 Sep 2004 12:01:35 -0000 @@ -119,8 +119,7 @@ * @see #getDefaultProtocolCharset */ public HttpURL(String host, int port, String path) throws URIException { - this(null, host, port, path, null, null); - checkValid(); + this(null, null, host, port, path, null, null); } @@ -137,8 +136,7 @@ public HttpURL(String host, int port, String path, String query) throws URIException { - this(null, host, port, path, query, null); - checkValid(); + this(null, null, host, port, path, query, null); } @@ -154,10 +152,7 @@ public HttpURL(String user, String password, String host) throws URIException { - this((user == null) ? null : user - + ((password == null) ? "" : ':' + password), - host, -1, null, null, null); - checkValid(); + this(user, password, host, -1, null, null, null); } @@ -174,10 +169,7 @@ public HttpURL(String user, String password, String host, int port) throws URIException { - this((user == null) ? null : user - + ((password == null) ? "" : ':' + password), - host, port, null, null, null); - checkValid(); + this(user, password, host, port, null, null, null); } @@ -195,10 +187,7 @@ public HttpURL(String user, String password, String host, int port, String path) throws URIException { - this((user == null) ? null : user - + ((password == null) ? "" : ':' + password), - host, port, path, null, null); - checkValid(); + this(user, password, host, port, path, null, null); } @@ -217,10 +206,7 @@ public HttpURL(String user, String password, String host, int port, String path, String query) throws URIException { - this((user == null) ? null : user - + ((password == null) ? "" : ':' + password), - host, port, path, query, null); - checkValid(); + this(user, password, host, port, path, query, null); } @@ -237,8 +223,7 @@ public HttpURL(String host, String path, String query, String fragment) throws URIException { - this(null, host, -1, path, query, fragment); - checkValid(); + this(null, null, host, -1, path, query, fragment); } @@ -252,12 +237,12 @@ * @param fragment the fragment string * @throws URIException If {@link #checkValid()} fails * @see #getDefaultProtocolCharset + * @deprecated The userinfo does not get escaped correctly. */ public HttpURL(String userinfo, String host, String path, String query, String fragment) throws URIException { this(userinfo, host, -1, path, query, fragment); - checkValid(); } @@ -270,12 +255,12 @@ * @param path the path string * @throws URIException If {@link #checkValid()} fails * @see #getDefaultProtocolCharset + * @deprecated The userinfo does not get escaped correctly. */ public HttpURL(String userinfo, String host, int port, String path) throws URIException { this(userinfo, host, port, path, null, null); - checkValid(); } @@ -289,12 +274,12 @@ * @param query the query string * @throws URIException If {@link #checkValid()} fails * @see #getDefaultProtocolCharset + * @deprecated The userinfo does not get escaped correctly. */ public HttpURL(String userinfo, String host, int port, String path, String query) throws URIException { this(userinfo, host, port, path, query, null); - checkValid(); } @@ -309,6 +294,7 @@ * @param fragment the fragment string * @throws URIException If {@link #checkValid()} fails * @see #getDefaultProtocolCharset + * @deprecated The userinfo does not get escaped correctly. */ public HttpURL(String userinfo, String host, int port, String path, String query, String fragment) throws URIException { @@ -321,6 +307,64 @@ buff.append("://"); if (userinfo != null) { buff.append(URIUtil.encode(userinfo, URI.allowed_userinfo)); + buff.append('@'); + } + if (host != null) { + buff.append(URIUtil.encode(host, URI.allowed_host)); + if (port != -1 || port != DEFAULT_PORT) { + buff.append(':'); + buff.append(port); + } + } + } + if (path != null) { // accept empty path + if (scheme != null && !path.startsWith("/")) { + throw new URIException(URIException.PARSING, + "abs_path requested"); + } + buff.append(URIUtil.encode(path, URI.allowed_abs_path)); + } + if (query != null) { + buff.append('?'); + buff.append(URIUtil.encode(query, URI.allowed_query)); + } + if (fragment != null) { + buff.append('#'); + buff.append(URIUtil.encode(fragment, URI.allowed_fragment)); + } + parseUriReference(buff.toString(), true); + checkValid(); + } + + + /** + * Construct a HTTP URL from given components. + * + * @param user the user name + * @param password his or her password + * @param host the host string + * @param port the port number + * @param path the path string + * @param query the query string + * @param fragment the fragment string + * @throws URIException If {@link #checkValid()} fails + * @see #getDefaultProtocolCharset + */ + public HttpURL(String user, String password, String host, int port, + String path, String query, String fragment) throws URIException { + + // validate and contruct the URI character sequence + StringBuffer buff = new StringBuffer(); + if (user != null || password != null || host != null || port != -1) { + _scheme = DEFAULT_SCHEME; // in order to verify the own protocol + buff.append(_default_scheme); + buff.append("://"); + if (user != null) { + buff.append(URIUtil.encode(user, URI.allowed_within_userinfo)); + if (password != null) { + buff.append(':').append( + URIUtil.encode(password, URI.allowed_within_userinfo)); + } buff.append('@'); } if (host != null) {