Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java (revision 240197) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java (working copy) @@ -189,8 +189,12 @@ if (LOG.isWarnEnabled()) { LOG.warn(charset + " not supported"); } - this.requestEntity = new StringRequestEntity( - requestString); + try { + this.requestEntity = new StringRequestEntity( + requestString, null, null); + } catch (UnsupportedEncodingException e1) { + //wont happen + } } } Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/java/org/apache/commons/httpclient/methods/StringRequestEntity.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/java/org/apache/commons/httpclient/methods/StringRequestEntity.java (revision 240197) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/java/org/apache/commons/httpclient/methods/StringRequestEntity.java (working copy) @@ -55,9 +55,11 @@ /** - * Creates a new entity with the given content + * Creates a new entity with the given content. The request entity will use + * the default platform encoding to convert characters to bytes. * * @param content The content to set. + * @deprecated use the constructor that explicitely sets the encoding. */ public StringRequestEntity(String content) { super(); @@ -100,12 +102,15 @@ break; } } - if (charset == null && charsetPair != null) { + if ((charset == null) && (charsetPair != null)) { // use the charset from the content type this.charset = charsetPair.getValue(); - } else if (charset != null && charsetPair == null) { + } else if ((charset != null) && (charsetPair == null)) { // append the charset to the content type this.contentType = contentType + "; charset=" + charset; + } else if ((charset != null) && (charsetPair != null)) { + if (!charset.equals(charsetPair.getValue())) + throw new IllegalArgumentException("charset and contentType specify a different character set"); } } if (this.charset != null) { Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java (revision 280804) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java (working copy) @@ -78,7 +78,7 @@ this.client.setHttpConnectionManager(connman); PostMethod httppost = new PostMethod("/test/"); - httppost.setRequestEntity(new StringRequestEntity("stuff")); + httppost.setRequestEntity(new StringRequestEntity("stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -87,7 +87,7 @@ assertFalse(connman.getConection().isOpen()); httppost = new PostMethod("/test/"); - httppost.setRequestEntity(new StringRequestEntity("more stuff")); + httppost.setRequestEntity(new StringRequestEntity("more stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -105,7 +105,7 @@ this.client.setHttpConnectionManager(connman); PostMethod httppost = new PostMethod("/test/"); - httppost.setRequestEntity(new StringRequestEntity("stuff")); + httppost.setRequestEntity(new StringRequestEntity("stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -114,7 +114,7 @@ assertTrue(connman.getConection().isOpen()); httppost = new PostMethod("/test/"); - httppost.setRequestEntity(new StringRequestEntity("more stuff")); + httppost.setRequestEntity(new StringRequestEntity("more stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -132,7 +132,7 @@ this.client.setHttpConnectionManager(connman); PostMethod httppost = new PostMethod("/test/"); - httppost.setRequestEntity(new StringRequestEntity("stuff")); + httppost.setRequestEntity(new StringRequestEntity("stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -142,7 +142,7 @@ httppost = new PostMethod("/test/"); httppost.setRequestHeader("Connection", "close"); - httppost.setRequestEntity(new StringRequestEntity("more stuff")); + httppost.setRequestEntity(new StringRequestEntity("more stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -160,7 +160,7 @@ this.client.setHttpConnectionManager(connman); PostMethod httppost = new PostMethod("/test/"); - httppost.setRequestEntity(new StringRequestEntity("stuff")); + httppost.setRequestEntity(new StringRequestEntity("stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -170,7 +170,7 @@ httppost = new PostMethod("/test/"); httppost.setRequestHeader("Connection", "keep-alive"); - httppost.setRequestEntity(new StringRequestEntity("more stuff")); + httppost.setRequestEntity(new StringRequestEntity("more stuff", null, null)); try { this.client.executeMethod(httppost); } finally { @@ -208,7 +208,7 @@ PostMethod httppost = new PostMethod("/test/"); httppost.setRequestHeader("Connection", "close"); - httppost.setRequestEntity(new StringRequestEntity("stuff")); + httppost.setRequestEntity(new StringRequestEntity("stuff", null, null)); try { this.client.executeMethod(httppost); } finally { Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestEntityEnclosingMethod.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestEntityEnclosingMethod.java (revision 240197) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestEntityEnclosingMethod.java (working copy) @@ -323,7 +323,7 @@ method = new PostMethod("/"); method.setRequestHeader("Content-Type", "text/plain"); - method.setRequestEntity(new StringRequestEntity("")); + method.setRequestEntity(new StringRequestEntity("", null, null)); this.client.executeMethod(method); assertEquals(200,method.getStatusLine().getStatusCode()); assertNotNull(method.getRequestHeader("Content-Length")); @@ -341,7 +341,7 @@ method = new PostMethod("/"); method.setRequestHeader("Content-Type", "text/plain"); - method.setRequestEntity(new StringRequestEntity("")); + method.setRequestEntity(new StringRequestEntity("", null, null)); method.setContentChunked(true); this.client.executeMethod(method); assertNull(method.getRequestHeader("Content-Length")); Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestNoncompliant.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestNoncompliant.java (revision 240197) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestNoncompliant.java (working copy) @@ -77,7 +77,7 @@ method.getParams().setBooleanParameter( HttpMethodParams.USE_EXPECT_CONTINUE, true); method.setRequestEntity(new StringRequestEntity( - "This is data to be sent in the body of an HTTP POST.")); + "This is data to be sent in the body of an HTTP POST.", null, null)); client.executeMethod(method); assertEquals(200, method.getStatusCode()); } Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestPostMethod.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestPostMethod.java (revision 240197) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestPostMethod.java (working copy) @@ -105,7 +105,7 @@ PostMethod method = new PostMethod("/"); String stringBody = "pname1=pvalue1&pname2=pvalue2"; - method.setRequestEntity(new StringRequestEntity(stringBody)); + method.setRequestEntity(new StringRequestEntity(stringBody, null, null)); this.server.setHttpService(new EchoService()); try { this.client.executeMethod(method); Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestPostParameterEncoding.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestPostParameterEncoding.java (revision 240197) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestPostParameterEncoding.java (working copy) @@ -100,7 +100,7 @@ public void testPostSetRequestBody() throws Exception { PostMethod post = new PostMethod("/foo"); String body = "this+is+the+body"; - post.setRequestEntity(new StringRequestEntity(body)); + post.setRequestEntity(new StringRequestEntity(body, null, null)); assertEquals(body, getRequestAsString(post.getRequestEntity())); } Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestProxy.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestProxy.java (revision 349941) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestProxy.java (working copy) @@ -438,7 +438,7 @@ public void testSimplePost() throws Exception { this.server.setHttpService(new FeedbackService()); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -464,7 +464,7 @@ this.server.setRequestHandler(handlerchain); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -490,7 +490,7 @@ this.server.setRequestHandler(handlerchain); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -520,7 +520,7 @@ this.server.setRequestHandler(handlerchain); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_UNAUTHORIZED, post.getStatusCode()); @@ -546,7 +546,7 @@ this.server.setRequestHandler(handlerchain); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -573,7 +573,7 @@ this.server.setRequestHandler(handlerchain); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -596,7 +596,7 @@ this.proxy.requireAuthentication(creds, "test", true); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -625,7 +625,7 @@ this.proxy.requireAuthentication(creds, "test", true); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -654,7 +654,7 @@ this.proxy.requireAuthentication(creds, "test", true); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -686,7 +686,7 @@ this.proxy.requireAuthentication(creds, "test", true); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_UNAUTHORIZED, post.getStatusCode()); @@ -714,7 +714,7 @@ this.proxy.requireAuthentication(creds, "test", true); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); @@ -743,7 +743,7 @@ this.proxy.requireAuthentication(creds, "test", true); PostMethod post = new PostMethod("/"); - post.setRequestEntity(new StringRequestEntity("Like tons of stuff")); + post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null)); try { this.client.executeMethod(post); assertEquals(HttpStatus.SC_OK, post.getStatusCode()); Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestRedirects.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestRedirects.java (revision 280804) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/TestRedirects.java (working copy) @@ -361,7 +361,7 @@ int port = this.server.getLocalPort(); this.server.setHttpService(new BasicRedirectService(host, port)); PostMethod httppost = new PostMethod("/oldlocation/"); - httppost.setRequestEntity(new StringRequestEntity("stuff")); + httppost.setRequestEntity(new StringRequestEntity("stuff", null, null)); try { this.client.executeMethod(httppost); assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httppost.getStatusCode()); Index: C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java =================================================================== --- C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java (revision 349941) +++ C:/Documents and Settings/Ortwin/My Documents/code/HttpClient-3/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java (working copy) @@ -492,7 +492,7 @@ this.server.setRequestHandler(handlerchain); PostMethod post = new PostMethod("/test/"); - post.setRequestEntity(new StringRequestEntity("Test body")); + post.setRequestEntity(new StringRequestEntity("Test body", null, null)); try { this.client.executeMethod(post); assertEquals("Test body", post.getResponseBodyAsString()); @@ -531,7 +531,7 @@ this.server.setRequestHandler(handlerchain); PutMethod put = new PutMethod("/test/"); - put.setRequestEntity(new StringRequestEntity("Test body")); + put.setRequestEntity(new StringRequestEntity("Test body", null, null)); try { this.client.executeMethod(put); assertEquals("Test body", put.getResponseBodyAsString());