oglueck 2002/12/19 02:23:39
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpClient.java HttpMethod.java HttpMethodBase.java
HttpUrlMethod.java
httpclient/src/java/org/apache/commons/httpclient/methods
DeleteMethod.java GetMethod.java HeadMethod.java
MultipartPostMethod.java OptionsMethod.java
PostMethod.java PutMethod.java TraceMethod.java
UrlDeleteMethod.java UrlGetMethod.java
UrlHeadMethod.java UrlOptionsMethod.java
UrlPostMethod.java UrlPutMethod.java
httpclient/src/test/org/apache/commons/httpclient
TestHttpUrlMethod.java
Log:
HttpMethod constructors now accept urls
Deprecated the URL*Methods
Patch contributed by: Michael Becke
Revision Changes Path
1.65 +11 -5
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
Index: HttpClient.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- HttpClient.java 17 Dec 2002 01:36:41 -0000 1.64
+++ HttpClient.java 19 Dec 2002 10:23:34 -0000 1.65
@@ -469,7 +469,13 @@
throws IOException, HttpException {
log.trace("enter HttpClient.executeMethod(HttpMethod)");
- return executeMethod(getHostConfiguration(), method);
+ // execute this method and use its host configuration, if it has one
+ return executeMethod(
+ method.getHostConfiguration() != null
+ ? method.getHostConfiguration()
+ : getHostConfiguration(),
+ method
+ );
}
1.21 +21 -4
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java
Index: HttpMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- HttpMethod.java 3 Dec 2002 05:46:15 -0000 1.20
+++ HttpMethod.java 19 Dec 2002 10:23:35 -0000 1.21
@@ -89,6 +89,13 @@
public String getName();
/**
+ * Gets the host configuration for this method.
+ *
+ * @return the HostConfiguration or <code>null</code> if none is set
+ */
+ public HostConfiguration getHostConfiguration();
+
+ /**
* Set the path part of my request.
* @param path the path to request
*/
@@ -105,6 +112,16 @@
* @return the path to request
*/
public String getPath();
+
+ /**
+ * Gets the URI for this method. The URI will be absolute if the host
+ * configuration has been set or relative otherwise.
+ *
+ * @return URI
+ *
+ * @throws URIException if a URI cannot be constructed
+ */
+ public URI getURI() throws URIException;
/**
* Turns strict mode on or off. In strict mode (the default)
1.91 +89 -13
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- HttpMethodBase.java 16 Dec 2002 05:16:04 -0000 1.90
+++ HttpMethodBase.java 19 Dec 2002 10:23:35 -0000 1.91
@@ -238,6 +238,9 @@
/** How many times did this transparently handle a recoverable exception? */
private int recoverableExceptionCount = 0;
+ /** the host configuration for this method, can be null */
+ private HostConfiguration hostConfiguration;
+
/**
* The maximum number of attempts to attempt recovery from an
* HttpRecoverableException.
@@ -263,18 +266,47 @@
}
/**
- * Path-specifying constructor.
+ * Constructor specifying a URI.
*
- * @param path my path which can include a query
+ * @param uri either an absolute or relative URI
*/
- public HttpMethodBase(String path) {
- int pa = path.indexOf("?");
- if (pa < 0) { //its just a path
- setPath(path);
- } else { //its a path with a query
- setPath(path.substring(0, pa));
- setQueryString(path.substring(pa+1, path.length()));
+ public HttpMethodBase(String uri) {
+
+ try {
+ // is this an absolute URI?
+ URL url = new URL( uri );
+
+ // set the path, defaulting to root
+ setPath(
+ url.getPath() == null
+ ? "/"
+ : url.getPath()
+ );
+ setQueryString( url.getQuery() );
+ hostConfiguration = new HostConfiguration();
+ hostConfiguration.setHost(
+ url.getHost(),
+ url.getPort(),
+ url.getProtocol()
+ );
+
+ } catch ( MalformedURLException e ) {
+ // this is not a URL
+ int pa = uri.indexOf("?");
+
+ if ( !uri.startsWith("/") ) {
+ // this path must be relative to root
+ uri = "/" + uri;
+ }
+
+ if (pa < 0) { //its just a path
+ setPath(uri);
+ } else { //its a path with a query
+ setPath(path.substring(0, pa));
+ setQueryString(uri.substring(pa+1, uri.length()));
+ }
}
+
}
//~ Methods ����������������������������������������������������������������
@@ -290,6 +322,34 @@
public abstract String getName();
/**
+ * @see org.apache.commons.httpclient.HttpMethod#getURI()
+ */
+ public URI getURI() throws URIException {
+
+ if ( hostConfiguration == null ) {
+ // just use a relative URI, the host hasn't been set
+ return new URI( null, null, path, queryString, null );
+ } else {
+
+ // we only want to include the port if it's not the default
+ int port = hostConfiguration.getPort();
+ if ( port == hostConfiguration.getProtocol().getDefaultPort() ) {
+ port = -1;
+ }
+
+ return new URI(
+ hostConfiguration.getProtocol().getScheme(),
+ null,
+ hostConfiguration.getHost(),
+ port,
+ path,
+ queryString
+ );
+ }
+
+ }
+
+ /**
* Set whether or not I should automatically follow HTTP redirects (status
* code 302, etc.)
*
@@ -2401,5 +2461,21 @@
responseBodyConsumed();
}
};
+
+ /**
+ * Returns the hostConfiguration.
+ * @return HostConfiguration
+ */
+ public HostConfiguration getHostConfiguration() {
+ return hostConfiguration;
+ }
+
+ /**
+ * Sets the hostConfiguration.
+ * @param hostConfiguration The hostConfiguration to set
+ */
+ public void setHostConfiguration(HostConfiguration hostConfiguration) {
+ this.hostConfiguration = hostConfiguration;
+ }
}
1.7 +5 -3
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpUrlMethod.java
Index: HttpUrlMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpUrlMethod.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HttpUrlMethod.java 3 Dec 2002 05:46:15 -0000 1.6
+++ HttpUrlMethod.java 19 Dec 2002 10:23:36 -0000 1.7
@@ -71,6 +71,8 @@
* HttpConnectoin (via MultiThreadedHttpConnectionManager) based on the host and
port in
* the URL.
*
+ * @deprecated use HttpMethod
+ *
* @author Marc A. Saegesser
*/
public interface HttpUrlMethod extends HttpMethod {
1.8 +8 -7
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java
Index: DeleteMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DeleteMethod.java 8 Aug 2002 21:51:36 -0000 1.7
+++ DeleteMethod.java 19 Dec 2002 10:23:37 -0000 1.8
@@ -91,13 +91,14 @@
/**
- * Path-setting constructor.
- * @param path the path to request
+ * Constructor specifying a URI.
+ *
+ * @param uri either an absolute or relative URI
*
* @since 1.0
*/
- public DeleteMethod(String path) {
- super(path);
+ public DeleteMethod(String uri) {
+ super(uri);
}
1.20 +8 -8
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java
Index: GetMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- GetMethod.java 9 Dec 2002 09:16:17 -0000 1.19
+++ GetMethod.java 19 Dec 2002 10:23:37 -0000 1.20
@@ -124,14 +124,14 @@
}
/**
- * Path-setting constructor.
- *
- * @param path the path to request
+ * Constructor specifying a URI.
+ *
+ * @param uri either an absolute or relative URI
*
* @since 1.0
*/
- public GetMethod(String path) {
- super(path);
+ public GetMethod(String uri) {
+ super(uri);
log.trace("enter GetMethod(String)");
setFollowRedirects(true);
}
1.13 +8 -8
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java
Index: HeadMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HeadMethod.java 9 Dec 2002 09:16:17 -0000 1.12
+++ HeadMethod.java 19 Dec 2002 10:23:37 -0000 1.13
@@ -94,14 +94,14 @@
}
/**
- * Path-setting constructor.
- *
- * @param path the path to request
+ * Constructor specifying a URI.
+ *
+ * @param uri either an absolute or relative URI
*
* @since 1.0
*/
- public HeadMethod(String path) {
- super(path);
+ public HeadMethod(String uri) {
+ super(uri);
setFollowRedirects(true);
}
1.5 +18 -15
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java
Index: MultipartPostMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MultipartPostMethod.java 17 Nov 2002 03:11:27 -0000 1.4
+++ MultipartPostMethod.java 19 Dec 2002 10:23:37 -0000 1.5
@@ -99,30 +99,33 @@
}
/**
- * Path-setting constructor.
- * @param path the path to request
+ * Constructor specifying a URI.
+ *
+ * @param uri either an absolute or relative URI
*/
- public MultipartPostMethod(String path) {
- super(path);
+ public MultipartPostMethod(String uri) {
+ super(uri);
}
/**
- * Constructor.
- * @param path the path to request
+ * Constructor specifying a URI and tempDir.
+ *
+ * @param uri either an absolute or relative URI
* @param tempDir directory to store temp files in
*/
- public MultipartPostMethod(String path, String tempDir) {
- super(path, tempDir);
+ public MultipartPostMethod(String uri, String tempDir) {
+ super(uri, tempDir);
}
/**
- * Constructor.
- * @param path the path to request
+ * Constructor specifying a URI, tempDir and tempFile.
+ *
+ * @param uri either an absolute or relative URI
* @param tempDir directory to store temp files in
* @param tempFile file to store temporary data in
*/
- public MultipartPostMethod(String path, String tempDir, String tempFile) {
- super(path, tempDir, tempFile);
+ public MultipartPostMethod(String uri, String tempDir, String tempFile) {
+ super(uri, tempDir, tempFile);
}
1.9 +8 -6
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/OptionsMethod.java
Index: OptionsMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/OptionsMethod.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- OptionsMethod.java 8 Aug 2002 21:51:36 -0000 1.8
+++ OptionsMethod.java 19 Dec 2002 10:23:37 -0000 1.9
@@ -103,12 +103,14 @@
/**
- * Method constructor.
+ * Constructor specifying a URI.
+ *
+ * @param uri either an absolute or relative URI
*
* @since 1.0
*/
- public OptionsMethod(String path) {
- super(path);
+ public OptionsMethod(String uri) {
+ super(uri);
}
1.31 +15 -15
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java
Index: PostMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- PostMethod.java 16 Dec 2002 15:19:37 -0000 1.30
+++ PostMethod.java 19 Dec 2002 10:23:37 -0000 1.31
@@ -171,41 +171,41 @@
}
/**
- * Path-setting constructor.
+ * Constructor specifying a URI.
*
- * @param path the path to request
+ * @param uri either an absolute or relative URI
*
* @since 1.0
*/
- public PostMethod(String path) {
- super(path);
+ public PostMethod(String uri) {
+ super(uri);
setFollowRedirects(false);
}
/**
- * Path and temp directory constructor.
+ * Constructor specifying a URI and a tempDir.
*
- * @param path the path to request
+ * @param uri either an absolute or relative URI
* @param tempDir directory to store temp files in
*
* @since 1.0
*/
- public PostMethod(String path, String tempDir) {
- super(path, tempDir);
+ public PostMethod(String uti, String tempDir) {
+ super(uti, tempDir);
setFollowRedirects(false);
}
/**
- * Path, temp directory and temp file constructor.
+ * Constructor specifying a URI, tempDir and tempFile.
*
- * @param path the path to request
+ * @param uri either an absolute or relative URI
* @param tempDir directory to store temp files in
* @param tempFile file to store temporary data in
*
* @since 1.0
*/
- public PostMethod(String path, String tempDir, String tempFile) {
- super(path, tempDir, tempFile);
+ public PostMethod(String uri, String tempDir, String tempFile) {
+ super(uri, tempDir, tempFile);
setFollowRedirects(false);
}
1.17 +8 -7
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java
Index: PutMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- PutMethod.java 25 Oct 2002 10:15:52 -0000 1.16
+++ PutMethod.java 19 Dec 2002 10:23:38 -0000 1.17
@@ -104,13 +104,14 @@
/**
- * Path-setting constructor.
- * @param path the path to request
+ * Constructor specifying a URI.
+ *
+ * @param uri either an absolute or relative URI
*
* @since 1.0
*/
- public PutMethod(String path) {
- super(path);
+ public PutMethod(String uri) {
+ super(uri);
setFollowRedirects(false);
}
1.6 +5 -6
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/TraceMethod.java
Index: TraceMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/TraceMethod.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TraceMethod.java 3 Sep 2002 03:05:34 -0000 1.5
+++ TraceMethod.java 19 Dec 2002 10:23:38 -0000 1.6
@@ -96,16 +96,15 @@
//~ Constructors �����������������������������������������������������������
/**
- *
- * Path-setting constructor.
- *
- * @param path the path to request
+ * Constructor specifying a URI.
+ *
+ * @param uri either an absolute or relative URI
*
* @since 2.0
*
*/
- public TraceMethod(String path) {
- super(path);
+ public TraceMethod(String uri) {
+ super(uri);
setFollowRedirects(false);
}
1.9 +5 -3
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlDeleteMethod.java
Index: UrlDeleteMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlDeleteMethod.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UrlDeleteMethod.java 20 Oct 2002 13:38:34 -0000 1.8
+++ UrlDeleteMethod.java 19 Dec 2002 10:23:38 -0000 1.9
@@ -70,6 +70,8 @@
/**
* HttpUrlMethod version of DeleteMethod.
*
+ * @deprecated use DeleteMethod
+ *
* @author Marc A. Saegesser
*/
public class UrlDeleteMethod extends DeleteMethod implements HttpUrlMethod
1.9 +5 -3
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlGetMethod.java
Index: UrlGetMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlGetMethod.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UrlGetMethod.java 20 Oct 2002 13:38:34 -0000 1.8
+++ UrlGetMethod.java 19 Dec 2002 10:23:38 -0000 1.9
@@ -73,6 +73,8 @@
* same purpose as GetMethod but it takes URL instead of
* a path.
*
+ * @deprecated use GetMethod
+ *
* @author Marc A. Saegesser
*/
public class UrlGetMethod extends GetMethod implements HttpUrlMethod
1.9 +5 -3
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlHeadMethod.java
Index: UrlHeadMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlHeadMethod.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UrlHeadMethod.java 20 Oct 2002 13:38:34 -0000 1.8
+++ UrlHeadMethod.java 19 Dec 2002 10:23:38 -0000 1.9
@@ -70,6 +70,8 @@
/**
* HttpUrlMethod version of HeadMethod.
*
+ * @deprecated use HeadMethod
+ *
* @author Marc A. Saegesser
*/
public class UrlHeadMethod extends HeadMethod implements HttpUrlMethod
1.9 +5 -3
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlOptionsMethod.java
Index: UrlOptionsMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlOptionsMethod.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UrlOptionsMethod.java 20 Oct 2002 13:38:34 -0000 1.8
+++ UrlOptionsMethod.java 19 Dec 2002 10:23:38 -0000 1.9
@@ -70,6 +70,8 @@
/**
* HttpUrlMethod version of Options method.
*
+ * @deprecated use OptionsMethod
+ *
* @author Marc A. Saegesser
*/
public class UrlOptionsMethod extends OptionsMethod implements HttpUrlMethod
1.8 +5 -3
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlPostMethod.java
Index: UrlPostMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlPostMethod.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- UrlPostMethod.java 20 Oct 2002 13:38:34 -0000 1.7
+++ UrlPostMethod.java 19 Dec 2002 10:23:38 -0000 1.8
@@ -70,6 +70,8 @@
/**
* HttpUrlMethod version of PostMethod.
*
+ * @deprecated use PostMethod
+ *
* @author Marc A. Saegesser
*/
public class UrlPostMethod extends PostMethod implements HttpUrlMethod
1.9 +5 -3
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlPutMethod.java
Index: UrlPutMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlPutMethod.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UrlPutMethod.java 20 Oct 2002 13:38:34 -0000 1.8
+++ UrlPutMethod.java 19 Dec 2002 10:23:38 -0000 1.9
@@ -70,6 +70,8 @@
/**
* HttpUrlMethod version of PutMethod.
*
+ * @deprecated use PutMethod
+ *
* @author Marc A. Saegesser
*/
public class UrlPutMethod extends PutMethod implements HttpUrlMethod
1.3 +48 -186
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpUrlMethod.java
Index: TestHttpUrlMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpUrlMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestHttpUrlMethod.java 22 Apr 2002 03:14:47 -0000 1.2
+++ TestHttpUrlMethod.java 19 Dec 2002 10:23:39 -0000 1.3
@@ -62,16 +62,17 @@
package org.apache.commons.httpclient;
-import junit.framework.*;
-import java.net.MalformedURLException;
-import java.lang.reflect.*;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
-import org.apache.commons.httpclient.methods.*;
+import org.apache.commons.httpclient.methods.GetMethod;
/**
*
- * Unit tests for {@link HttpUrlMethod} based methods. These tests
- * do not require any network connection or web app.
+ * Unit tests for {@link org.apache.commons.httpclient.HttpMethod}
+ * constructors that take URLs. These tests do not require any network
+ * connection or web app.
*
* @author Marc A. Saegesser
* @version $Id$
@@ -99,192 +100,53 @@
// ----------------------------------------------------------- Test Methods
// Test constructors
- public void testUrlDeleteMethodConstructor() {
- try{
- UrlDeleteMethod method = new
UrlDeleteMethod("http://www.fubar.com/path1/path2?query=string");
- validateConstructorResults(method);
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
- }
- }
-
- public void testUrlGetMethodConstructor() {
- try{
- UrlGetMethod method = new
UrlGetMethod("http://www.fubar.com/path1/path2?query=string");
- validateConstructorResults(method);
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
- }
- }
-
- public void testUrlHeadMethodConstructor() {
- try{
- UrlHeadMethod method = new
UrlHeadMethod("http://www.fubar.com/path1/path2?query=string");
- validateConstructorResults(method);
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
- }
- }
- public void testUrlOptionsMethodConstructor() {
- try{
- UrlOptionsMethod method = new
UrlOptionsMethod("http://www.fubar.com/path1/path2?query=string");
- validateConstructorResults(method);
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
+ public void testUrlGetMethodWithPathQuery() {
+ GetMethod method = new
GetMethod("http://www.fubar.com/path1/path2?query=string");
+ try {
+ assertEquals(
+ "Get URL",
+ "http://www.fubar.com/path1/path2?query=string",
+ method.getURI().toString()
+ );
+ } catch ( URIException e ) {
+ fail( "trouble getting URI: " + e );
}
- }
-
- public void testUrlPostMethodConstructor() {
- try{
- UrlPostMethod method = new
UrlPostMethod("http://www.fubar.com/path1/path2?query=string");
- validateConstructorResults(method);
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
- }
- }
-
- public void testUrlPutMethodConstructor() {
- try{
- UrlPutMethod method = new
UrlPutMethod("http://www.fubar.com/path1/path2?query=string");
- validateConstructorResults(method);
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
- }
- }
-
- private void validateConstructorResults(HttpUrlMethod method)
- {
- assertEquals("Get URL", "http://www.fubar.com/path1/path2?query=string",
method.getUrl());
assertEquals("Get Path", "/path1/path2", method.getPath());
assertEquals("Get query string", "query=string", method.getQueryString());
+
}
-
- // Test UrlDeleteMethod
- public void testUrlDeleteMethodAccessorsValidPath() {
- UrlDeleteMethod method = new UrlDeleteMethod();
- testAccessorsValidPath(method);
- }
-
- public void testUrlDeleteMethodAccessorsNoPath() {
- UrlDeleteMethod method = new UrlDeleteMethod();
- testAccessorsNoPath(method);
- }
-
- public void testUrlDeleteMethodAccessorsWithQuery() {
- UrlDeleteMethod method = new UrlDeleteMethod();
- testAccessorsWithQuery(method);
- }
-
- // Test UrlGetMethod
- public void testUrlGetMethodAccessorsValidPath() {
- UrlGetMethod method = new UrlGetMethod();
- testAccessorsValidPath(method);
- }
-
- public void testUrlGetMethodAccessorsNoPath() {
- UrlGetMethod method = new UrlGetMethod();
- testAccessorsNoPath(method);
- }
-
- public void testUrlGetMethodAccessorsWithQuery() {
- UrlGetMethod method = new UrlGetMethod();
- testAccessorsWithQuery(method);
- }
-
- // Test UrlHeadMethod
- public void testUrlHeadMethodAccessorsValidPath() {
- UrlHeadMethod method = new UrlHeadMethod();
- testAccessorsValidPath(method);
- }
-
- public void testUrlHeadMethodAccessorsNoPath() {
- UrlHeadMethod method = new UrlHeadMethod();
- testAccessorsNoPath(method);
- }
-
- public void testUrlHeadMethodAccessorsWithQuery() {
- UrlHeadMethod method = new UrlHeadMethod();
- testAccessorsWithQuery(method);
- }
-
- // Test UrlOptionsMethod
- public void testUrlOptionsMethodAccessorsValidPath() {
- UrlOptionsMethod method = new UrlOptionsMethod();
- testAccessorsValidPath(method);
- }
-
- public void testUrlOptionsMethodAccessorsNoPath() {
- UrlOptionsMethod method = new UrlOptionsMethod();
- testAccessorsNoPath(method);
- }
-
- public void testUrlOptionsMethodAccessorsWithQuery() {
- UrlOptionsMethod method = new UrlOptionsMethod();
- testAccessorsWithQuery(method);
- }
-
- // Test UrlPostMethod
- public void testUrlPostMethodAccessorsValidPath() {
- UrlPostMethod method = new UrlPostMethod();
- testAccessorsValidPath(method);
- }
-
- public void testUrlPostMethodAccessorsNoPath() {
- UrlPostMethod method = new UrlPostMethod();
- testAccessorsNoPath(method);
- }
-
- public void testUrlPostMethodAccessorsWithQuery() {
- UrlPostMethod method = new UrlPostMethod();
- testAccessorsWithQuery(method);
- }
-
- // Test UrlPutMethod
- public void testUrlPutMethodAccessorsValidPath() {
- UrlPutMethod method = new UrlPutMethod();
- testAccessorsValidPath(method);
- }
-
- public void testUrlPutMethodAccessorsNoPath() {
- UrlPutMethod method = new UrlPutMethod();
- testAccessorsNoPath(method);
- }
-
- public void testUrlPutMethodAccessorsWithQuery() {
- UrlPutMethod method = new UrlPutMethod();
- testAccessorsWithQuery(method);
- }
-
- private void testAccessorsValidPath(HttpUrlMethod method) {
- try{
- method.setUrl("http://www.fubar.com/path1/path2");
- assertEquals("Get URL", "http://www.fubar.com/path1/path2",
method.getUrl());
- assertEquals("Get Path", "/path1/path2", method.getPath());
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
+ public void testUrlGetMethodWithPath() {
+ GetMethod method = new GetMethod("http://www.fubar.com/path1/path2");
+ try {
+ assertEquals(
+ "Get URL",
+ "http://www.fubar.com/path1/path2",
+ method.getURI().toString()
+ );
+ } catch ( URIException e ) {
+ fail( "trouble getting URI: " + e );
}
- }
+ assertEquals("Get Path", "/path1/path2", method.getPath());
+ assertEquals("Get query string", null, method.getQueryString());
- private void testAccessorsNoPath(HttpUrlMethod method) {
- try{
- method.setUrl("http://www.fubar.com");
- assertEquals("Get URL", "http://www.fubar.com", method.getUrl());
- assertEquals("Get Path", "/", method.getPath());
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
- }
}
- private void testAccessorsWithQuery(HttpUrlMethod method) {
- try{
- method.setUrl("http://www.fubar.com/path1/path2?query=string");
- assertEquals("Get URL",
"http://www.fubar.com/path1/path2?query=string", method.getUrl());
- assertEquals("Get Path", "/path1/path2", method.getPath());
- assertEquals("Get query string", "query=string",
method.getQueryString());
- }catch(MalformedURLException e){
- fail("Caught unexpected exception " + e.toString());
+ public void testUrlGetMethod() {
+ GetMethod method = new GetMethod("http://www.fubar.com/");
+ try {
+ assertEquals(
+ "Get URL",
+ "http://www.fubar.com/",
+ method.getURI().toString()
+ );
+ } catch ( URIException e ) {
+ fail( "trouble getting URI: " + e );
}
+ assertEquals("Get Path", "/", method.getPath());
+ assertEquals("Get query string", null, method.getQueryString());
+
}
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>