Using the new HttpClient, there are some methods (ACL, LABEL, LOCK, OPTIONS, PROPFIND,
PROPPATCH, REPORT, SEARCH) where the request body is not encoded correctly.
XMLResponseMethodBase.getRequestContentLength() calls generateRequestBody() to create
the request body string and then calls setRequestBody with this string.
setRequestBody(String) does not take a charset into account and transforms this string
into an array of bytes using the platform's default charset.
HttpClient (EntityEnclosingMethod) approached this by checking the Content-Type header
and using the corresponding charset. This means that the charset (Content-Type header)
must be set before the getRequestContentLength method is called and hence the changes
to the addRequestHeaders method in each of the methods mentioned.
------
Rob Owen
SAS Institute Inc.
email: [EMAIL PROTECTED]
Index: HttpRequestBodyMethodBase.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/HttpRequestBodyMethodBase.java,v
retrieving revision 1.3
diff -u -r1.3 HttpRequestBodyMethodBase.java
--- HttpRequestBodyMethodBase.java 16 Dec 2002 16:46:00 -0000 1.3
+++ HttpRequestBodyMethodBase.java 10 Feb 2003 19:11:39 -0000
@@ -75,6 +75,7 @@
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpConstants;
/**
@@ -171,7 +172,7 @@
*/
public void setRequestBody(String bodydata) {
checkNotUsed();
- setRequestBody(bodydata.getBytes());
+ setRequestBody( HttpConstants.getContentBytes(bodydata, getRequestCharSet())
+);
}
/**
Index: AclMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/AclMethod.java,v
retrieving revision 1.8
diff -u -r1.8 AclMethod.java
--- AclMethod.java 16 Dec 2002 15:17:28 -0000 1.8
+++ AclMethod.java 10 Feb 2003 19:11:39 -0000
@@ -148,8 +148,8 @@
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
- super.addRequestHeaders(state, conn);
super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
+ super.addRequestHeaders(state, conn);
}
Index: LabelMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/LabelMethod.java,v
retrieving revision 1.8
diff -u -r1.8 LabelMethod.java
--- LabelMethod.java 16 Dec 2002 15:17:28 -0000 1.8
+++ LabelMethod.java 10 Feb 2003 19:11:40 -0000
@@ -204,8 +204,8 @@
*/
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
- super.addRequestHeaders(state, conn);
super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
+ super.addRequestHeaders(state, conn);
}
/**
Index: LockMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/LockMethod.java,v
retrieving revision 1.33
diff -u -r1.33 LockMethod.java
--- LockMethod.java 16 Dec 2002 15:17:28 -0000 1.33
+++ LockMethod.java 10 Feb 2003 19:11:40 -0000
@@ -439,6 +439,7 @@
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
+ super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
super.addRequestHeaders(state, conn);
switch (depth) {
@@ -461,7 +462,6 @@
super.setRequestHeader("If", "(<" + refreshOpaqueToken + ">)");
}
- super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
}
Index: OptionsMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/OptionsMethod.java,v
retrieving revision 1.14
diff -u -r1.14 OptionsMethod.java
--- OptionsMethod.java 16 Dec 2002 15:17:28 -0000 1.14
+++ OptionsMethod.java 10 Feb 2003 19:11:39 -0000
@@ -344,12 +344,12 @@
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
- super.addRequestHeaders(state, conn);
if (type!= 0){
super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
//System.out.println("Content-Type set" );
}
+ super.addRequestHeaders(state, conn);
}
/**
Index: PropFindMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/PropFindMethod.java,v
retrieving revision 1.32
diff -u -r1.32 PropFindMethod.java
--- PropFindMethod.java 16 Dec 2002 15:17:28 -0000 1.32
+++ PropFindMethod.java 10 Feb 2003 19:11:40 -0000
@@ -375,9 +375,9 @@
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
+ super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
super.addRequestHeaders(state, conn);
- super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
switch (depth) {
case DEPTH_0:
Index: PropPatchMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/PropPatchMethod.java,v
retrieving revision 1.23
diff -u -r1.23 PropPatchMethod.java
--- PropPatchMethod.java 16 Dec 2002 15:17:28 -0000 1.23
+++ PropPatchMethod.java 10 Feb 2003 19:11:39 -0000
@@ -225,9 +225,9 @@
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
+ super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
super.addRequestHeaders(state, conn);
- super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
}
Index: ReportMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/ReportMethod.java,v
retrieving revision 1.5
diff -u -r1.5 ReportMethod.java
--- ReportMethod.java 16 Dec 2002 15:17:28 -0000 1.5
+++ ReportMethod.java 10 Feb 2003 19:11:40 -0000
@@ -366,9 +366,9 @@
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
- super.addRequestHeaders(state, conn);
super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
+ super.addRequestHeaders(state, conn);
switch (depth) {
case DEPTH_0:
Index: SearchMethod.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/SearchMethod.java,v
retrieving revision 1.7
diff -u -r1.7 SearchMethod.java
--- SearchMethod.java 16 Dec 2002 15:17:28 -0000 1.7
+++ SearchMethod.java 10 Feb 2003 19:11:39 -0000
@@ -216,8 +216,8 @@
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
- super.addRequestHeaders(state, conn);
super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
+ super.addRequestHeaders(state, conn);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]