From 93296a4779f794dc61d60cf60346e283a4c41a71 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 5 May 2012 15:53:45 +0000 Subject: [PATCH] Upgraded to HttpCore 4.2; Fixed compile errors caused by API breakage (HTTPCLIENT-1189) git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1334436 13f79535-47bb-0310-9956-ffa450edef68 --- .../client/fluent/FluentResponseHandling.java | 7 +-- .../apache/http/client/fluent/Content.java | 7 +-- .../apache/http/client/fluent/Request.java | 16 +++--- .../http/examples/client/ClientFormLogin.java | 5 +- .../http/examples/client/ProxyTunnelDemo.java | 7 ++- .../apache/http/auth/params/AuthParams.java | 2 +- .../client/entity/UrlEncodedFormEntity.java | 27 ++-------- .../apache/http/client/utils/URIBuilder.java | 19 +++---- .../http/client/utils/URLEncodedUtils.java | 54 +++++++++++++------ .../http/impl/client/DefaultHttpClient.java | 2 +- .../impl/conn/LoggingSessionInputBuffer.java | 4 +- .../impl/conn/LoggingSessionOutputBuffer.java | 4 +- .../client/utils/TestURLEncodedUtils.java | 33 ++++++------ .../http/impl/auth/TestDigestScheme.java | 2 +- .../impl/client/TestBasicResponseHandler.java | 2 +- .../impl/client/TestClientAuthentication.java | 6 +-- .../TestClientAuthenticationFallBack.java | 4 +- .../client/TestClientReauthentication.java | 4 +- pom.xml | 2 +- 19 files changed, 105 insertions(+), 102 deletions(-) diff --git a/fluent-hc/src/examples/org/apache/http/client/fluent/FluentResponseHandling.java b/fluent-hc/src/examples/org/apache/http/client/fluent/FluentResponseHandling.java index 70f18c1fe..6e6071f48 100644 --- a/fluent-hc/src/examples/org/apache/http/client/fluent/FluentResponseHandling.java +++ b/fluent-hc/src/examples/org/apache/http/client/fluent/FluentResponseHandling.java @@ -27,6 +27,7 @@ package org.apache.http.client.fluent; import java.io.IOException; +import java.nio.charset.Charset; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -71,11 +72,11 @@ public class FluentResponseHandling { if (!contentType.equals(ContentType.APPLICATION_XML)) { throw new ClientProtocolException("Unexpected content type:" + contentType); } - String charset = contentType.getCharset(); + Charset charset = contentType.getCharset(); if (charset == null) { - charset = HTTP.DEFAULT_CONTENT_CHARSET; + charset = HTTP.DEF_CONTENT_CHARSET; } - return docBuilder.parse(entity.getContent(), charset); + return docBuilder.parse(entity.getContent(), charset.name()); } catch (ParserConfigurationException ex) { throw new IllegalStateException(ex); } catch (SAXException ex) { diff --git a/fluent-hc/src/main/java/org/apache/http/client/fluent/Content.java b/fluent-hc/src/main/java/org/apache/http/client/fluent/Content.java index af0e5155f..7d1ff5f38 100644 --- a/fluent-hc/src/main/java/org/apache/http/client/fluent/Content.java +++ b/fluent-hc/src/main/java/org/apache/http/client/fluent/Content.java @@ -29,6 +29,7 @@ package org.apache.http.client.fluent; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import org.apache.http.entity.ContentType; import org.apache.http.protocol.HTTP; @@ -55,12 +56,12 @@ public class Content { } public String asString() { - String charset = this.type.getCharset(); + Charset charset = this.type.getCharset(); if (charset == null) { - charset = HTTP.DEFAULT_CONTENT_TYPE; + charset = HTTP.DEF_CONTENT_CHARSET; } try { - return new String(this.raw, charset); + return new String(this.raw, charset.name()); } catch (UnsupportedEncodingException ex) { return new String(this.raw); } diff --git a/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java b/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java index 4d467b20e..4e96125c8 100644 --- a/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java +++ b/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java @@ -29,8 +29,8 @@ package org.apache.http.client.fluent; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.net.URI; +import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; @@ -266,24 +266,20 @@ public class Request { return this; } - public Request bodyForm(final Iterable formParams, final String charset) { - try { - return body(new UrlEncodedFormEntity(formParams)); - } catch (UnsupportedEncodingException ex) { - throw new IllegalArgumentException(ex); - } + public Request bodyForm(final Iterable formParams, final Charset charset) { + return body(new UrlEncodedFormEntity(formParams, charset)); } public Request bodyForm(final Iterable formParams) { - return bodyForm(formParams, HTTP.DEFAULT_CONTENT_CHARSET); + return bodyForm(formParams, HTTP.DEF_CONTENT_CHARSET); } public Request bodyForm(final NameValuePair... formParams) { - return bodyForm(Arrays.asList(formParams), HTTP.DEFAULT_CONTENT_CHARSET); + return bodyForm(Arrays.asList(formParams), HTTP.DEF_CONTENT_CHARSET); } public Request bodyString(final String s, final ContentType contentType) { - return body(StringEntity.create(s, contentType)); + return body(new StringEntity(s, contentType)); } public Request bodyFile(final File file, final ContentType contentType) { diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientFormLogin.java b/httpclient/src/examples/org/apache/http/examples/client/ClientFormLogin.java index aae777877..fedcacab3 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientFormLogin.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientFormLogin.java @@ -28,6 +28,8 @@ package org.apache.http.examples.client; import java.util.ArrayList; import java.util.List; + +import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; @@ -37,7 +39,6 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.cookie.Cookie; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; -import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; /** @@ -77,7 +78,7 @@ public class ClientFormLogin { nvps.add(new BasicNameValuePair("IDToken1", "username")); nvps.add(new BasicNameValuePair("IDToken2", "password")); - httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); + httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); response = httpclient.execute(httpost); entity = response.getEntity(); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ProxyTunnelDemo.java b/httpclient/src/examples/org/apache/http/examples/client/ProxyTunnelDemo.java index fba67365c..3fd646462 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ProxyTunnelDemo.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ProxyTunnelDemo.java @@ -51,16 +51,15 @@ public class ProxyTunnelDemo { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd"); Socket socket = proxyClient.tunnel(proxy, target, credentials); try { - Writer out = new OutputStreamWriter(socket.getOutputStream(), - HTTP.DEFAULT_CONTENT_CHARSET); + Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET); out.write("GET / HTTP/1.1\r\n"); out.write("Host: " + target.toHostString() + "\r\n"); out.write("Agent: whatever\r\n"); out.write("Connection: close\r\n"); out.write("\r\n"); out.flush(); - BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), - HTTP.DEFAULT_CONTENT_CHARSET)); + BufferedReader in = new BufferedReader( + new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET)); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); diff --git a/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java b/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java index 55cf9a240..8e8250a0e 100644 --- a/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java +++ b/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java @@ -61,7 +61,7 @@ public final class AuthParams { String charset = (String) params.getParameter (AuthPNames.CREDENTIAL_CHARSET); if (charset == null) { - charset = HTTP.DEFAULT_PROTOCOL_CHARSET; + charset = HTTP.DEF_PROTOCOL_CHARSET.name(); } return charset; } diff --git a/httpclient/src/main/java/org/apache/http/client/entity/UrlEncodedFormEntity.java b/httpclient/src/main/java/org/apache/http/client/entity/UrlEncodedFormEntity.java index 37705f441..bd1c54737 100644 --- a/httpclient/src/main/java/org/apache/http/client/entity/UrlEncodedFormEntity.java +++ b/httpclient/src/main/java/org/apache/http/client/entity/UrlEncodedFormEntity.java @@ -27,6 +27,7 @@ package org.apache.http.client.entity; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import java.util.List; import org.apache.http.annotation.NotThreadSafe; @@ -46,24 +47,6 @@ import org.apache.http.protocol.HTTP; @NotThreadSafe // AbstractHttpEntity is not thread-safe public class UrlEncodedFormEntity extends StringEntity { - public static UrlEncodedFormEntity create( - final Iterable parameters, final String charset) { - try { - return new UrlEncodedFormEntity(parameters, charset); - } catch (UnsupportedEncodingException ex) { - throw new IllegalArgumentException(ex.getMessage(), ex); - } - } - - public static UrlEncodedFormEntity create( - final Iterable parameters) { - try { - return new UrlEncodedFormEntity(parameters, null); - } catch (UnsupportedEncodingException ex) { - throw new IllegalArgumentException(ex.getMessage(), ex); - } - } - /** * Constructs a new {@link UrlEncodedFormEntity} with the list * of parameters in the specified encoding. @@ -76,7 +59,7 @@ public class UrlEncodedFormEntity extends StringEntity { final List parameters, final String charset) throws UnsupportedEncodingException { super(URLEncodedUtils.format(parameters, - charset != null ? charset : HTTP.DEFAULT_CONTENT_CHARSET), + charset != null ? charset : HTTP.DEF_CONTENT_CHARSET.name()), ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset)); } @@ -92,9 +75,9 @@ public class UrlEncodedFormEntity extends StringEntity { */ public UrlEncodedFormEntity ( final Iterable parameters, - final String charset) throws UnsupportedEncodingException { + final Charset charset) { super(URLEncodedUtils.format(parameters, - charset != null ? charset : HTTP.DEFAULT_CONTENT_CHARSET), + charset != null ? charset : HTTP.DEF_CONTENT_CHARSET), ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset)); } @@ -107,7 +90,7 @@ public class UrlEncodedFormEntity extends StringEntity { */ public UrlEncodedFormEntity ( final List parameters) throws UnsupportedEncodingException { - this(parameters, null); + this(parameters, (Charset) null); } /** diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java b/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java index 7639ba655..653a797d2 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java @@ -28,13 +28,14 @@ package org.apache.http.client.utils; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.http.Consts; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; -import org.apache.http.protocol.HTTP; /** * @since 4.2 @@ -66,18 +67,18 @@ public class URIBuilder { digestURI(uri); } - private List parseQuery(final String query, final String encoding) { + private List parseQuery(final String query, final Charset charset) { if (query != null && query.length() > 0) { - return URLEncodedUtils.parse(query, encoding); + return URLEncodedUtils.parse(query, charset); } return null; } - private String formatQuery(final List parameters, final String encoding) { + private String formatQuery(final List parameters, final Charset charset) { if (parameters == null) { return null; } - return URLEncodedUtils.format(parameters, encoding); + return URLEncodedUtils.format(parameters, charset); } /** @@ -88,11 +89,11 @@ public class URIBuilder { return new URI(this.scheme, this.schemeSpecificPart, this.fragment); } else if (this.authority != null) { return new URI(this.scheme, this.authority, - this.path, formatQuery(this.queryParams, HTTP.UTF_8), this.fragment); + this.path, formatQuery(this.queryParams, Consts.UTF_8), this.fragment); } else { return new URI(this.scheme, this.userInfo, this.host, this.port, - this.path, formatQuery(this.queryParams, HTTP.UTF_8), this.fragment); + this.path, formatQuery(this.queryParams, Consts.UTF_8), this.fragment); } } @@ -104,7 +105,7 @@ public class URIBuilder { this.port = uri.getPort(); this.userInfo = uri.getUserInfo(); this.path = uri.getPath(); - this.queryParams = parseQuery(uri.getRawQuery(), HTTP.UTF_8); + this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8); this.fragment = uri.getFragment(); } @@ -175,7 +176,7 @@ public class URIBuilder { * Set URI query. */ public URIBuilder setQuery(final String query) { - this.queryParams = parseQuery(query, HTTP.UTF_8); + this.queryParams = parseQuery(query, Consts.UTF_8); this.schemeSpecificPart = null; return this; } diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java index 56efdc94a..da576b71f 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java @@ -32,6 +32,7 @@ import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; import java.net.URLEncoder; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -40,6 +41,7 @@ import java.util.Scanner; import org.apache.http.annotation.Immutable; import org.apache.http.entity.ContentType; +import org.apache.http.Consts; import org.apache.http.Header; import org.apache.http.HeaderElement; import org.apache.http.HttpEntity; @@ -79,7 +81,10 @@ public class URLEncodedUtils { public static List parse (final URI uri, final String encoding) { final String query = uri.getRawQuery(); if (query != null && query.length() > 0) { - return parse(query, encoding); + List result = new ArrayList(); + Scanner scanner = new Scanner(query); + parse(result, scanner, encoding); + return result; } else { return Collections.emptyList(); } @@ -99,17 +104,18 @@ public class URLEncodedUtils { */ public static List parse ( final HttpEntity entity) throws IOException { - List result = new ArrayList(); ContentType contentType = ContentType.get(entity); if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) { - String content = EntityUtils.toString(entity, HTTP.ASCII); + String content = EntityUtils.toString(entity, Consts.ASCII); if (content != null && content.length() > 0) { - Scanner scanner = new Scanner(entity.getContent(), HTTP.ASCII); - parse(result, scanner, contentType.getCharset() != null ? - contentType.getCharset() : HTTP.DEFAULT_CONTENT_CHARSET); + Charset charset = contentType != null ? contentType.getCharset() : null; + if (charset == null) { + charset = HTTP.DEF_CONTENT_CHARSET; + } + return parse(content, charset); } } - return result; + return Collections.emptyList(); } /** @@ -178,7 +184,7 @@ public class URLEncodedUtils { * * @since 4.2 */ - public static List parse (final String s, final String charset) { + public static List parse (final String s, final Charset charset) { if (s == null) { return Collections.emptyList(); } @@ -235,7 +241,7 @@ public class URLEncodedUtils { */ public static String format ( final Iterable parameters, - final String charset) { + final Charset charset) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encode(parameter.getName(), charset); @@ -257,23 +263,37 @@ public class URLEncodedUtils { return null; } try { - return URLDecoder.decode(content, - charset != null ? charset : HTTP.DEFAULT_CONTENT_CHARSET); - } catch (UnsupportedEncodingException problem) { - throw new IllegalArgumentException(problem); + return URLDecoder.decode(content, + charset != null ? charset : HTTP.DEF_CONTENT_CHARSET.name()); + } catch (UnsupportedEncodingException ex) { + throw new IllegalArgumentException(ex); } } + private static String decode (final String content, final Charset charset) { + if (content == null) { + return null; + } + return decode(content, charset != null ? charset.name() : null); + } + private static String encode (final String content, final String charset) { if (content == null) { return null; } try { - return URLEncoder.encode(content, - charset != null ? charset : HTTP.DEFAULT_CONTENT_CHARSET); - } catch (UnsupportedEncodingException problem) { - throw new IllegalArgumentException(problem); + return URLEncoder.encode(content, + charset != null ? charset : HTTP.DEF_CONTENT_CHARSET.name()); + } catch (UnsupportedEncodingException ex) { + throw new IllegalArgumentException(ex); } } + private static String encode (final String content, final Charset charset) { + if (content == null) { + return null; + } + return encode(content, charset != null ? charset.name() : null); + } + } diff --git a/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java index 391e0e2cf..e4eb54f38 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java @@ -172,7 +172,7 @@ public class DefaultHttpClient extends AbstractHttpClient { */ public static void setDefaultHttpParams(HttpParams params) { HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); + HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name()); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, 8192); diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java index 0562075a8..ff6cfa21e 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java @@ -28,12 +28,12 @@ package org.apache.http.impl.conn; import java.io.IOException; +import org.apache.http.Consts; import org.apache.http.annotation.Immutable; import org.apache.http.io.EofSensor; import org.apache.http.io.HttpTransportMetrics; import org.apache.http.io.SessionInputBuffer; -import org.apache.http.protocol.HTTP; import org.apache.http.util.CharArrayBuffer; /** @@ -67,7 +67,7 @@ public class LoggingSessionInputBuffer implements SessionInputBuffer, EofSensor this.in = in; this.eofSensor = in instanceof EofSensor ? (EofSensor) in : null; this.wire = wire; - this.charset = charset != null ? charset : HTTP.ASCII; + this.charset = charset != null ? charset : Consts.ASCII.name(); } public LoggingSessionInputBuffer(final SessionInputBuffer in, final Wire wire) { diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java index 803853b39..d6a332ec3 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java @@ -28,11 +28,11 @@ package org.apache.http.impl.conn; import java.io.IOException; +import org.apache.http.Consts; import org.apache.http.annotation.Immutable; import org.apache.http.io.HttpTransportMetrics; import org.apache.http.io.SessionOutputBuffer; -import org.apache.http.protocol.HTTP; import org.apache.http.util.CharArrayBuffer; /** @@ -63,7 +63,7 @@ public class LoggingSessionOutputBuffer implements SessionOutputBuffer { super(); this.out = out; this.wire = wire; - this.charset = charset != null ? charset : HTTP.ASCII; + this.charset = charset != null ? charset : Consts.ASCII.name(); } public LoggingSessionOutputBuffer(final SessionOutputBuffer out, final Wire wire) { diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java index d78d30f06..79b4a9745 100644 --- a/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java +++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java @@ -31,6 +31,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; +import org.apache.http.Consts; import org.apache.http.NameValuePair; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; @@ -132,13 +133,13 @@ public class TestURLEncodedUtils { parameters.add(new BasicNameValuePair("russian", ru_hello)); parameters.add(new BasicNameValuePair("swiss", ch_hello)); - String s = URLEncodedUtils.format(parameters, HTTP.UTF_8); + String s = URLEncodedUtils.format(parameters, Consts.UTF_8); Assert.assertEquals("russian=%D0%92%D1%81%D0%B5%D0%BC_%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" + "&swiss=Gr%C3%BCezi_z%C3%A4m%C3%A4", s); StringEntity entity = new StringEntity(s, ContentType.create( - URLEncodedUtils.CONTENT_TYPE, HTTP.UTF_8)); + URLEncodedUtils.CONTENT_TYPE, Consts.UTF_8)); List result = URLEncodedUtils.parse(entity); Assert.assertEquals(2, result.size()); assertNameValuePair(result.get(0), "russian", ru_hello); @@ -153,9 +154,9 @@ public class TestURLEncodedUtils { parameters.add(new BasicNameValuePair("russian", ru_hello)); parameters.add(new BasicNameValuePair("swiss", ch_hello)); - String s = URLEncodedUtils.format(parameters, HTTP.UTF_8); + String s = URLEncodedUtils.format(parameters, Consts.UTF_8); - List result = URLEncodedUtils.parse(s, HTTP.UTF_8); + List result = URLEncodedUtils.parse(s, Consts.UTF_8); Assert.assertEquals(2, result.size()); assertNameValuePair(result.get(0), "russian", ru_hello); assertNameValuePair(result.get(1), "swiss", ch_hello); @@ -169,12 +170,12 @@ public class TestURLEncodedUtils { parameters.add(new BasicNameValuePair("english", us_hello)); parameters.add(new BasicNameValuePair("swiss", ch_hello)); - String s = URLEncodedUtils.format(parameters, HTTP.DEFAULT_CONTENT_CHARSET); + String s = URLEncodedUtils.format(parameters, HTTP.DEF_CONTENT_CHARSET); Assert.assertEquals("english=hi+there&swiss=Gr%FCezi_z%E4m%E4", s); StringEntity entity = new StringEntity(s, ContentType.create( - URLEncodedUtils.CONTENT_TYPE, null)); + URLEncodedUtils.CONTENT_TYPE, HTTP.DEF_CONTENT_CHARSET)); List result = URLEncodedUtils.parse(entity); Assert.assertEquals(2, result.size()); assertNameValuePair(result.get(0), "english", us_hello); @@ -198,46 +199,46 @@ public class TestURLEncodedUtils { @Test public void testFormat () throws Exception { final List params = new ArrayList (); - Assert.assertEquals(0, URLEncodedUtils.format(params, null).length()); + Assert.assertEquals(0, URLEncodedUtils.format(params, Consts.ASCII).length()); params.clear(); params.add(new BasicNameValuePair("Name0", null)); - Assert.assertEquals("Name0", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name0", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name1", "Value1")); - Assert.assertEquals("Name1=Value1", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name1=Value1", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name2", "")); - Assert.assertEquals("Name2=", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name2=", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name4", "Value 4!")); - Assert.assertEquals("Name4=Value+4%21", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name4=Value+4%21", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name4", "Value+4!")); - Assert.assertEquals("Name4=Value%2B4%21", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name4=Value%2B4%21", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name4", "Value 4! !4")); - Assert.assertEquals("Name4=Value+4%21+%214", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name4=Value+4%21+%214", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name5", "aaa")); params.add(new BasicNameValuePair("Name6", "bbb")); - Assert.assertEquals("Name5=aaa&Name6=bbb", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name5=aaa&Name6=bbb", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name7", "aaa")); params.add(new BasicNameValuePair("Name7", "b,b")); params.add(new BasicNameValuePair("Name7", "ccc")); - Assert.assertEquals("Name7=aaa&Name7=b%2Cb&Name7=ccc", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name7=aaa&Name7=b%2Cb&Name7=ccc", URLEncodedUtils.format(params, Consts.ASCII)); params.clear(); params.add(new BasicNameValuePair("Name8", "xx, yy ,zz")); - Assert.assertEquals("Name8=xx%2C++yy++%2Czz", URLEncodedUtils.format(params, null)); + Assert.assertEquals("Name8=xx%2C++yy++%2Czz", URLEncodedUtils.format(params, Consts.ASCII)); } private List parse (final String params, final String encoding) { diff --git a/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java b/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java index e6ae62394..d1f581ff8 100644 --- a/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java +++ b/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java @@ -543,7 +543,7 @@ public class TestDigestScheme { "qop=\"auth,auth-int\""; Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge); HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/"); - request.setEntity(new StringEntity("abc\u00e4\u00f6\u00fcabc", HTTP.DEFAULT_CONTENT_CHARSET)); + request.setEntity(new StringEntity("abc\u00e4\u00f6\u00fcabc", HTTP.DEF_CONTENT_CHARSET)); Credentials cred = new UsernamePasswordCredentials("username","password"); DigestScheme authscheme = new DigestScheme(); HttpContext context = new BasicHttpContext(); diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestBasicResponseHandler.java b/httpclient/src/test/java/org/apache/http/impl/client/TestBasicResponseHandler.java index 8ce627f27..2595cb341 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestBasicResponseHandler.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestBasicResponseHandler.java @@ -50,7 +50,7 @@ public class TestBasicResponseHandler { public void testSuccessfulResponse() throws Exception { StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"); HttpResponse response = Mockito.mock(HttpResponse.class); - HttpEntity entity = StringEntity.create("stuff"); + HttpEntity entity = new StringEntity("stuff"); Mockito.when(response.getStatusLine()).thenReturn(sl); Mockito.when(response.getEntity()).thenReturn(entity); diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java b/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java index cd5b61bbc..39813d655 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java @@ -28,6 +28,7 @@ package org.apache.http.impl.client; import java.io.ByteArrayInputStream; import java.io.IOException; +import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpException; import org.apache.http.HttpHost; @@ -53,7 +54,6 @@ import org.apache.http.localserver.ResponseBasicUnauthorized; import org.apache.http.params.CoreProtocolPNames; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpProcessor; -import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpExpectationVerifier; import org.apache.http.protocol.HttpRequestHandler; @@ -96,7 +96,7 @@ public class TestClientAuthentication extends BasicServerTestBase { response.setStatusCode(HttpStatus.SC_UNAUTHORIZED); } else { response.setStatusCode(HttpStatus.SC_OK); - StringEntity entity = new StringEntity("success", HTTP.ASCII); + StringEntity entity = new StringEntity("success", Consts.ASCII); response.setEntity(entity); } } @@ -295,7 +295,7 @@ public class TestClientAuthentication extends BasicServerTestBase { this.httpclient.setCredentialsProvider(credsProvider); HttpPost httppost = new HttpPost("/"); - httppost.setEntity(new StringEntity("some important stuff", HTTP.ISO_8859_1)); + httppost.setEntity(new StringEntity("some important stuff", Consts.ASCII)); HttpResponse response = this.httpclient.execute(getServerHttp(), httppost); HttpEntity entity = response.getEntity(); diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFallBack.java b/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFallBack.java index 3bb1cabbd..1dcbe2ef2 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFallBack.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFallBack.java @@ -27,6 +27,7 @@ package org.apache.http.impl.client; import java.io.IOException; +import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpException; import org.apache.http.HttpRequest; @@ -44,7 +45,6 @@ import org.apache.http.localserver.BasicServerTestBase; import org.apache.http.localserver.LocalTestServer; import org.apache.http.localserver.RequestBasicAuth; import org.apache.http.protocol.BasicHttpProcessor; -import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.protocol.ResponseConnControl; @@ -96,7 +96,7 @@ public class TestClientAuthenticationFallBack extends BasicServerTestBase { response.setStatusCode(HttpStatus.SC_UNAUTHORIZED); } else { response.setStatusCode(HttpStatus.SC_OK); - StringEntity entity = new StringEntity("success", HTTP.ASCII); + StringEntity entity = new StringEntity("success", Consts.ASCII); response.setEntity(entity); } } diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestClientReauthentication.java b/httpclient/src/test/java/org/apache/http/impl/client/TestClientReauthentication.java index c57bc9e46..7cde9c45b 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestClientReauthentication.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestClientReauthentication.java @@ -28,6 +28,7 @@ package org.apache.http.impl.client; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; +import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpException; import org.apache.http.HttpRequest; @@ -46,7 +47,6 @@ import org.apache.http.localserver.LocalTestServer; import org.apache.http.localserver.RequestBasicAuth; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpProcessor; -import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.protocol.ResponseConnControl; @@ -103,7 +103,7 @@ public class TestClientReauthentication extends BasicServerTestBase { response.setStatusCode(HttpStatus.SC_UNAUTHORIZED); } else { response.setStatusCode(HttpStatus.SC_OK); - StringEntity entity = new StringEntity("success", HTTP.ASCII); + StringEntity entity = new StringEntity("success", Consts.ASCII); response.setEntity(entity); } } diff --git a/pom.xml b/pom.xml index d0c1816fc..9fa0b6365 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ UTF-8 UTF-8 - 4.2-beta1 + 4.2 1.1.1 1.6 2.2.0