You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ib...@apache.org on 2004/07/21 01:32:07 UTC
cvs commit: jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods CopyMethod.java MoveMethod.java
ib 2004/07/20 16:32:07
Modified: webdavclient/clientlib/src/java/org/apache/webdav/lib/methods
Tag: SLIDE_2_0_RELEASE_BRANCH CopyMethod.java
MoveMethod.java
Log:
Fix for bug #30125: MoveMethod, CopyMethod should allow absolute URLs for destination and avoid adding default port
Revision Changes Path
No revision
No revision
1.1.2.2 +4 -6 jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/CopyMethod.java
Index: CopyMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/CopyMethod.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- CopyMethod.java 5 Feb 2004 15:51:21 -0000 1.1.2.1
+++ CopyMethod.java 20 Jul 2004 23:32:07 -0000 1.1.2.2
@@ -186,9 +186,7 @@
super.addRequestHeaders(state, conn);
- String absoluteDestination =
- conn.getProtocol().getScheme() + "://" + conn.getHost() + ":"
- + conn.getPort() + destination;
+ String absoluteDestination = MoveMethod.getAbsoluteDestination(conn, destination);
super.setRequestHeader("Destination", absoluteDestination);
if (!isOverwrite())
1.1.2.2 +50 -6 jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/MoveMethod.java
Index: MoveMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/MoveMethod.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- MoveMethod.java 5 Feb 2004 15:51:22 -0000 1.1.2.1
+++ MoveMethod.java 20 Jul 2004 23:32:07 -0000 1.1.2.2
@@ -27,6 +27,7 @@
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.protocol.Protocol;
/**
@@ -185,14 +186,57 @@
super.addRequestHeaders(state, conn);
- String absoluteDestination =
- conn.getProtocol().getScheme() + "://" + conn.getHost() + ":"
- + conn.getPort() + destination;
+ String absoluteDestination = getAbsoluteDestination(conn, destination);
super.setRequestHeader("Destination", absoluteDestination);
if (!isOverwrite())
super.setRequestHeader("Overwrite", "F");
+ }
+
+ /**
+ * A client of the {@link MoveMethod} can specify a destination as either an
+ * absolute URL (possibly to a different server), or as a absolute path on
+ * the same server, but this function makes sure that the path sent to the
+ * server is always an absolute URL.
+ *
+ * <p>Note that this function will add server and port to the request -
+ * however, port is not added if it is the default port for the scheme
+ * in question. </p>
+ *
+ * <p>This function is static so that it can be reused by the {@link CopyMethod}.
+ * </p>
+ *
+ * @param conn The connection for the current request, in case the caller
+ * specifies an absolute path.
+ *
+ * @param absolutePathOrURL If an absolute URL, nothing done, but if an absolute
+ * path, it is converted into an absolute URL.
+ *
+ * @return An absolute URL
+ */
+ static String getAbsoluteDestination(HttpConnection conn, String absolutePathOrURL) {
+
+ String absoluteDestination = absolutePathOrURL;
+
+ // is this an absolute path?
+ if (absolutePathOrURL.startsWith("/")) {
+
+ // yes - get the protocol to start the URL with the appropriate scheme.
+ Protocol protocol = conn.getProtocol();
+ StringBuffer bufDest = new StringBuffer(protocol.getScheme());
+ bufDest.append("://").append(conn.getHost());
+
+ // only add in the port if it is not the default port.
+ if (conn.getPort() != protocol.getDefaultPort()) {
+ bufDest.append(':').append(conn.getPort());
+ }
+
+ // append the path.
+ bufDest.append(absolutePathOrURL);
+ absoluteDestination = bufDest.toString();
+ }
+ return absoluteDestination;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org