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
This commit is contained in:
Oleg Kalnichevski 2012-05-05 15:53:45 +00:00
parent 63d06f06cd
commit 93296a4779
19 changed files with 105 additions and 102 deletions

View File

@ -27,6 +27,7 @@
package org.apache.http.client.fluent; package org.apache.http.client.fluent;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -71,11 +72,11 @@ public class FluentResponseHandling {
if (!contentType.equals(ContentType.APPLICATION_XML)) { if (!contentType.equals(ContentType.APPLICATION_XML)) {
throw new ClientProtocolException("Unexpected content type:" + contentType); throw new ClientProtocolException("Unexpected content type:" + contentType);
} }
String charset = contentType.getCharset(); Charset charset = contentType.getCharset();
if (charset == null) { 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) { } catch (ParserConfigurationException ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
} catch (SAXException ex) { } catch (SAXException ex) {

View File

@ -29,6 +29,7 @@ package org.apache.http.client.fluent;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HTTP;
@ -55,12 +56,12 @@ public class Content {
} }
public String asString() { public String asString() {
String charset = this.type.getCharset(); Charset charset = this.type.getCharset();
if (charset == null) { if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_TYPE; charset = HTTP.DEF_CONTENT_CHARSET;
} }
try { try {
return new String(this.raw, charset); return new String(this.raw, charset.name());
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
return new String(this.raw); return new String(this.raw);
} }

View File

@ -29,8 +29,8 @@ package org.apache.http.client.fluent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -266,24 +266,20 @@ public class Request {
return this; return this;
} }
public Request bodyForm(final Iterable <? extends NameValuePair> formParams, final String charset) { public Request bodyForm(final Iterable <? extends NameValuePair> formParams, final Charset charset) {
try { return body(new UrlEncodedFormEntity(formParams, charset));
return body(new UrlEncodedFormEntity(formParams));
} catch (UnsupportedEncodingException ex) {
throw new IllegalArgumentException(ex);
}
} }
public Request bodyForm(final Iterable <? extends NameValuePair> formParams) { public Request bodyForm(final Iterable <? extends NameValuePair> formParams) {
return bodyForm(formParams, HTTP.DEFAULT_CONTENT_CHARSET); return bodyForm(formParams, HTTP.DEF_CONTENT_CHARSET);
} }
public Request bodyForm(final NameValuePair... formParams) { 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) { 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) { public Request bodyFile(final File file, final ContentType contentType) {

View File

@ -28,6 +28,8 @@ package org.apache.http.examples.client;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.http.Consts;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; 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.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
/** /**
@ -77,7 +78,7 @@ public class ClientFormLogin {
nvps.add(new BasicNameValuePair("IDToken1", "username")); nvps.add(new BasicNameValuePair("IDToken1", "username"));
nvps.add(new BasicNameValuePair("IDToken2", "password")); 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); response = httpclient.execute(httpost);
entity = response.getEntity(); entity = response.getEntity();

View File

@ -51,16 +51,15 @@ public class ProxyTunnelDemo {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd");
Socket socket = proxyClient.tunnel(proxy, target, credentials); Socket socket = proxyClient.tunnel(proxy, target, credentials);
try { try {
Writer out = new OutputStreamWriter(socket.getOutputStream(), Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET);
HTTP.DEFAULT_CONTENT_CHARSET);
out.write("GET / HTTP/1.1\r\n"); out.write("GET / HTTP/1.1\r\n");
out.write("Host: " + target.toHostString() + "\r\n"); out.write("Host: " + target.toHostString() + "\r\n");
out.write("Agent: whatever\r\n"); out.write("Agent: whatever\r\n");
out.write("Connection: close\r\n"); out.write("Connection: close\r\n");
out.write("\r\n"); out.write("\r\n");
out.flush(); out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), BufferedReader in = new BufferedReader(
HTTP.DEFAULT_CONTENT_CHARSET)); new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET));
String line = null; String line = null;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
System.out.println(line); System.out.println(line);

View File

@ -61,7 +61,7 @@ public final class AuthParams {
String charset = (String) params.getParameter String charset = (String) params.getParameter
(AuthPNames.CREDENTIAL_CHARSET); (AuthPNames.CREDENTIAL_CHARSET);
if (charset == null) { if (charset == null) {
charset = HTTP.DEFAULT_PROTOCOL_CHARSET; charset = HTTP.DEF_PROTOCOL_CHARSET.name();
} }
return charset; return charset;
} }

View File

@ -27,6 +27,7 @@
package org.apache.http.client.entity; package org.apache.http.client.entity;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import org.apache.http.annotation.NotThreadSafe; import org.apache.http.annotation.NotThreadSafe;
@ -46,24 +47,6 @@ import org.apache.http.protocol.HTTP;
@NotThreadSafe // AbstractHttpEntity is not thread-safe @NotThreadSafe // AbstractHttpEntity is not thread-safe
public class UrlEncodedFormEntity extends StringEntity { public class UrlEncodedFormEntity extends StringEntity {
public static UrlEncodedFormEntity create(
final Iterable <? extends NameValuePair> 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 <? extends NameValuePair> parameters) {
try {
return new UrlEncodedFormEntity(parameters, null);
} catch (UnsupportedEncodingException ex) {
throw new IllegalArgumentException(ex.getMessage(), ex);
}
}
/** /**
* Constructs a new {@link UrlEncodedFormEntity} with the list * Constructs a new {@link UrlEncodedFormEntity} with the list
* of parameters in the specified encoding. * of parameters in the specified encoding.
@ -76,7 +59,7 @@ public class UrlEncodedFormEntity extends StringEntity {
final List <? extends NameValuePair> parameters, final List <? extends NameValuePair> parameters,
final String charset) throws UnsupportedEncodingException { final String charset) throws UnsupportedEncodingException {
super(URLEncodedUtils.format(parameters, 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)); ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset));
} }
@ -92,9 +75,9 @@ public class UrlEncodedFormEntity extends StringEntity {
*/ */
public UrlEncodedFormEntity ( public UrlEncodedFormEntity (
final Iterable <? extends NameValuePair> parameters, final Iterable <? extends NameValuePair> parameters,
final String charset) throws UnsupportedEncodingException { final Charset charset) {
super(URLEncodedUtils.format(parameters, super(URLEncodedUtils.format(parameters,
charset != null ? charset : HTTP.DEFAULT_CONTENT_CHARSET), charset != null ? charset : HTTP.DEF_CONTENT_CHARSET),
ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset)); ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset));
} }
@ -107,7 +90,7 @@ public class UrlEncodedFormEntity extends StringEntity {
*/ */
public UrlEncodedFormEntity ( public UrlEncodedFormEntity (
final List <? extends NameValuePair> parameters) throws UnsupportedEncodingException { final List <? extends NameValuePair> parameters) throws UnsupportedEncodingException {
this(parameters, null); this(parameters, (Charset) null);
} }
/** /**

View File

@ -28,13 +28,14 @@ package org.apache.http.client.utils;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.http.Consts;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
/** /**
* @since 4.2 * @since 4.2
@ -66,18 +67,18 @@ public class URIBuilder {
digestURI(uri); digestURI(uri);
} }
private List <NameValuePair> parseQuery(final String query, final String encoding) { private List <NameValuePair> parseQuery(final String query, final Charset charset) {
if (query != null && query.length() > 0) { if (query != null && query.length() > 0) {
return URLEncodedUtils.parse(query, encoding); return URLEncodedUtils.parse(query, charset);
} }
return null; return null;
} }
private String formatQuery(final List<NameValuePair> parameters, final String encoding) { private String formatQuery(final List<NameValuePair> parameters, final Charset charset) {
if (parameters == null) { if (parameters == null) {
return 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); return new URI(this.scheme, this.schemeSpecificPart, this.fragment);
} else if (this.authority != null) { } else if (this.authority != null) {
return new URI(this.scheme, this.authority, 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 { } else {
return new URI(this.scheme, this.userInfo, this.host, this.port, 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.port = uri.getPort();
this.userInfo = uri.getUserInfo(); this.userInfo = uri.getUserInfo();
this.path = uri.getPath(); this.path = uri.getPath();
this.queryParams = parseQuery(uri.getRawQuery(), HTTP.UTF_8); this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
this.fragment = uri.getFragment(); this.fragment = uri.getFragment();
} }
@ -175,7 +176,7 @@ public class URIBuilder {
* Set URI query. * Set URI query.
*/ */
public URIBuilder setQuery(final String query) { public URIBuilder setQuery(final String query) {
this.queryParams = parseQuery(query, HTTP.UTF_8); this.queryParams = parseQuery(query, Consts.UTF_8);
this.schemeSpecificPart = null; this.schemeSpecificPart = null;
return this; return this;
} }

View File

@ -32,6 +32,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -40,6 +41,7 @@ import java.util.Scanner;
import org.apache.http.annotation.Immutable; import org.apache.http.annotation.Immutable;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.Consts;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HeaderElement; import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
@ -79,7 +81,10 @@ public class URLEncodedUtils {
public static List <NameValuePair> parse (final URI uri, final String encoding) { public static List <NameValuePair> parse (final URI uri, final String encoding) {
final String query = uri.getRawQuery(); final String query = uri.getRawQuery();
if (query != null && query.length() > 0) { if (query != null && query.length() > 0) {
return parse(query, encoding); List<NameValuePair> result = new ArrayList<NameValuePair>();
Scanner scanner = new Scanner(query);
parse(result, scanner, encoding);
return result;
} else { } else {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -99,17 +104,18 @@ public class URLEncodedUtils {
*/ */
public static List <NameValuePair> parse ( public static List <NameValuePair> parse (
final HttpEntity entity) throws IOException { final HttpEntity entity) throws IOException {
List <NameValuePair> result = new ArrayList<NameValuePair>();
ContentType contentType = ContentType.get(entity); ContentType contentType = ContentType.get(entity);
if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) { 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) { if (content != null && content.length() > 0) {
Scanner scanner = new Scanner(entity.getContent(), HTTP.ASCII); Charset charset = contentType != null ? contentType.getCharset() : null;
parse(result, scanner, contentType.getCharset() != null ? if (charset == null) {
contentType.getCharset() : HTTP.DEFAULT_CONTENT_CHARSET); charset = HTTP.DEF_CONTENT_CHARSET;
}
return parse(content, charset);
} }
} }
return result; return Collections.emptyList();
} }
/** /**
@ -178,7 +184,7 @@ public class URLEncodedUtils {
* *
* @since 4.2 * @since 4.2
*/ */
public static List<NameValuePair> parse (final String s, final String charset) { public static List<NameValuePair> parse (final String s, final Charset charset) {
if (s == null) { if (s == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -235,7 +241,7 @@ public class URLEncodedUtils {
*/ */
public static String format ( public static String format (
final Iterable<? extends NameValuePair> parameters, final Iterable<? extends NameValuePair> parameters,
final String charset) { final Charset charset) {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
for (final NameValuePair parameter : parameters) { for (final NameValuePair parameter : parameters) {
final String encodedName = encode(parameter.getName(), charset); final String encodedName = encode(parameter.getName(), charset);
@ -258,22 +264,36 @@ public class URLEncodedUtils {
} }
try { try {
return URLDecoder.decode(content, return URLDecoder.decode(content,
charset != null ? charset : HTTP.DEFAULT_CONTENT_CHARSET); charset != null ? charset : HTTP.DEF_CONTENT_CHARSET.name());
} catch (UnsupportedEncodingException problem) { } catch (UnsupportedEncodingException ex) {
throw new IllegalArgumentException(problem); 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) { private static String encode (final String content, final String charset) {
if (content == null) { if (content == null) {
return null; return null;
} }
try { try {
return URLEncoder.encode(content, return URLEncoder.encode(content,
charset != null ? charset : HTTP.DEFAULT_CONTENT_CHARSET); charset != null ? charset : HTTP.DEF_CONTENT_CHARSET.name());
} catch (UnsupportedEncodingException problem) { } catch (UnsupportedEncodingException ex) {
throw new IllegalArgumentException(problem); 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);
}
} }

View File

@ -172,7 +172,7 @@ public class DefaultHttpClient extends AbstractHttpClient {
*/ */
public static void setDefaultHttpParams(HttpParams params) { public static void setDefaultHttpParams(HttpParams params) {
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 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.setTcpNoDelay(params, true);
HttpConnectionParams.setSocketBufferSize(params, 8192); HttpConnectionParams.setSocketBufferSize(params, 8192);

View File

@ -28,12 +28,12 @@ package org.apache.http.impl.conn;
import java.io.IOException; import java.io.IOException;
import org.apache.http.Consts;
import org.apache.http.annotation.Immutable; import org.apache.http.annotation.Immutable;
import org.apache.http.io.EofSensor; import org.apache.http.io.EofSensor;
import org.apache.http.io.HttpTransportMetrics; import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.io.SessionInputBuffer; import org.apache.http.io.SessionInputBuffer;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.CharArrayBuffer; import org.apache.http.util.CharArrayBuffer;
/** /**
@ -67,7 +67,7 @@ public class LoggingSessionInputBuffer implements SessionInputBuffer, EofSensor
this.in = in; this.in = in;
this.eofSensor = in instanceof EofSensor ? (EofSensor) in : null; this.eofSensor = in instanceof EofSensor ? (EofSensor) in : null;
this.wire = wire; 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) { public LoggingSessionInputBuffer(final SessionInputBuffer in, final Wire wire) {

View File

@ -28,11 +28,11 @@ package org.apache.http.impl.conn;
import java.io.IOException; import java.io.IOException;
import org.apache.http.Consts;
import org.apache.http.annotation.Immutable; import org.apache.http.annotation.Immutable;
import org.apache.http.io.HttpTransportMetrics; import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.io.SessionOutputBuffer; import org.apache.http.io.SessionOutputBuffer;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.CharArrayBuffer; import org.apache.http.util.CharArrayBuffer;
/** /**
@ -63,7 +63,7 @@ public class LoggingSessionOutputBuffer implements SessionOutputBuffer {
super(); super();
this.out = out; this.out = out;
this.wire = wire; 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) { public LoggingSessionOutputBuffer(final SessionOutputBuffer out, final Wire wire) {

View File

@ -31,6 +31,7 @@ import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.http.Consts;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
@ -132,13 +133,13 @@ public class TestURLEncodedUtils {
parameters.add(new BasicNameValuePair("russian", ru_hello)); parameters.add(new BasicNameValuePair("russian", ru_hello));
parameters.add(new BasicNameValuePair("swiss", ch_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" + 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); "&swiss=Gr%C3%BCezi_z%C3%A4m%C3%A4", s);
StringEntity entity = new StringEntity(s, ContentType.create( StringEntity entity = new StringEntity(s, ContentType.create(
URLEncodedUtils.CONTENT_TYPE, HTTP.UTF_8)); URLEncodedUtils.CONTENT_TYPE, Consts.UTF_8));
List <NameValuePair> result = URLEncodedUtils.parse(entity); List <NameValuePair> result = URLEncodedUtils.parse(entity);
Assert.assertEquals(2, result.size()); Assert.assertEquals(2, result.size());
assertNameValuePair(result.get(0), "russian", ru_hello); 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("russian", ru_hello));
parameters.add(new BasicNameValuePair("swiss", ch_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 <NameValuePair> result = URLEncodedUtils.parse(s, HTTP.UTF_8); List <NameValuePair> result = URLEncodedUtils.parse(s, Consts.UTF_8);
Assert.assertEquals(2, result.size()); Assert.assertEquals(2, result.size());
assertNameValuePair(result.get(0), "russian", ru_hello); assertNameValuePair(result.get(0), "russian", ru_hello);
assertNameValuePair(result.get(1), "swiss", ch_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("english", us_hello));
parameters.add(new BasicNameValuePair("swiss", ch_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); Assert.assertEquals("english=hi+there&swiss=Gr%FCezi_z%E4m%E4", s);
StringEntity entity = new StringEntity(s, ContentType.create( StringEntity entity = new StringEntity(s, ContentType.create(
URLEncodedUtils.CONTENT_TYPE, null)); URLEncodedUtils.CONTENT_TYPE, HTTP.DEF_CONTENT_CHARSET));
List <NameValuePair> result = URLEncodedUtils.parse(entity); List <NameValuePair> result = URLEncodedUtils.parse(entity);
Assert.assertEquals(2, result.size()); Assert.assertEquals(2, result.size());
assertNameValuePair(result.get(0), "english", us_hello); assertNameValuePair(result.get(0), "english", us_hello);
@ -198,46 +199,46 @@ public class TestURLEncodedUtils {
@Test @Test
public void testFormat () throws Exception { public void testFormat () throws Exception {
final List <NameValuePair> params = new ArrayList <NameValuePair>(); final List <NameValuePair> params = new ArrayList <NameValuePair>();
Assert.assertEquals(0, URLEncodedUtils.format(params, null).length()); Assert.assertEquals(0, URLEncodedUtils.format(params, Consts.ASCII).length());
params.clear(); params.clear();
params.add(new BasicNameValuePair("Name0", null)); params.add(new BasicNameValuePair("Name0", null));
Assert.assertEquals("Name0", URLEncodedUtils.format(params, null)); Assert.assertEquals("Name0", URLEncodedUtils.format(params, Consts.ASCII));
params.clear(); params.clear();
params.add(new BasicNameValuePair("Name1", "Value1")); 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.clear();
params.add(new BasicNameValuePair("Name2", "")); params.add(new BasicNameValuePair("Name2", ""));
Assert.assertEquals("Name2=", URLEncodedUtils.format(params, null)); Assert.assertEquals("Name2=", URLEncodedUtils.format(params, Consts.ASCII));
params.clear(); params.clear();
params.add(new BasicNameValuePair("Name4", "Value 4!")); 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.clear();
params.add(new BasicNameValuePair("Name4", "Value+4!")); 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.clear();
params.add(new BasicNameValuePair("Name4", "Value 4! !4")); 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.clear();
params.add(new BasicNameValuePair("Name5", "aaa")); params.add(new BasicNameValuePair("Name5", "aaa"));
params.add(new BasicNameValuePair("Name6", "bbb")); 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.clear();
params.add(new BasicNameValuePair("Name7", "aaa")); params.add(new BasicNameValuePair("Name7", "aaa"));
params.add(new BasicNameValuePair("Name7", "b,b")); params.add(new BasicNameValuePair("Name7", "b,b"));
params.add(new BasicNameValuePair("Name7", "ccc")); 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.clear();
params.add(new BasicNameValuePair("Name8", "xx, yy ,zz")); 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 <NameValuePair> parse (final String params, final String encoding) { private List <NameValuePair> parse (final String params, final String encoding) {

View File

@ -543,7 +543,7 @@ public class TestDigestScheme {
"qop=\"auth,auth-int\""; "qop=\"auth,auth-int\"";
Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge); Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/"); 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"); Credentials cred = new UsernamePasswordCredentials("username","password");
DigestScheme authscheme = new DigestScheme(); DigestScheme authscheme = new DigestScheme();
HttpContext context = new BasicHttpContext(); HttpContext context = new BasicHttpContext();

View File

@ -50,7 +50,7 @@ public class TestBasicResponseHandler {
public void testSuccessfulResponse() throws Exception { public void testSuccessfulResponse() throws Exception {
StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"); StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK");
HttpResponse response = Mockito.mock(HttpResponse.class); 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.getStatusLine()).thenReturn(sl);
Mockito.when(response.getEntity()).thenReturn(entity); Mockito.when(response.getEntity()).thenReturn(entity);

View File

@ -28,6 +28,7 @@ package org.apache.http.impl.client;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import org.apache.http.Consts;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpException; import org.apache.http.HttpException;
import org.apache.http.HttpHost; 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.params.CoreProtocolPNames;
import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.BasicHttpProcessor; import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpExpectationVerifier; import org.apache.http.protocol.HttpExpectationVerifier;
import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.protocol.HttpRequestHandler;
@ -96,7 +96,7 @@ public class TestClientAuthentication extends BasicServerTestBase {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED); response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
} else { } else {
response.setStatusCode(HttpStatus.SC_OK); response.setStatusCode(HttpStatus.SC_OK);
StringEntity entity = new StringEntity("success", HTTP.ASCII); StringEntity entity = new StringEntity("success", Consts.ASCII);
response.setEntity(entity); response.setEntity(entity);
} }
} }
@ -295,7 +295,7 @@ public class TestClientAuthentication extends BasicServerTestBase {
this.httpclient.setCredentialsProvider(credsProvider); this.httpclient.setCredentialsProvider(credsProvider);
HttpPost httppost = new HttpPost("/"); 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); HttpResponse response = this.httpclient.execute(getServerHttp(), httppost);
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();

View File

@ -27,6 +27,7 @@ package org.apache.http.impl.client;
import java.io.IOException; import java.io.IOException;
import org.apache.http.Consts;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpException; import org.apache.http.HttpException;
import org.apache.http.HttpRequest; 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.LocalTestServer;
import org.apache.http.localserver.RequestBasicAuth; import org.apache.http.localserver.RequestBasicAuth;
import org.apache.http.protocol.BasicHttpProcessor; import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.ResponseConnControl; import org.apache.http.protocol.ResponseConnControl;
@ -96,7 +96,7 @@ public class TestClientAuthenticationFallBack extends BasicServerTestBase {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED); response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
} else { } else {
response.setStatusCode(HttpStatus.SC_OK); response.setStatusCode(HttpStatus.SC_OK);
StringEntity entity = new StringEntity("success", HTTP.ASCII); StringEntity entity = new StringEntity("success", Consts.ASCII);
response.setEntity(entity); response.setEntity(entity);
} }
} }

View File

@ -28,6 +28,7 @@ package org.apache.http.impl.client;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.apache.http.Consts;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpException; import org.apache.http.HttpException;
import org.apache.http.HttpRequest; 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.localserver.RequestBasicAuth;
import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.BasicHttpProcessor; import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.ResponseConnControl; import org.apache.http.protocol.ResponseConnControl;
@ -103,7 +103,7 @@ public class TestClientReauthentication extends BasicServerTestBase {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED); response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
} else { } else {
response.setStatusCode(HttpStatus.SC_OK); response.setStatusCode(HttpStatus.SC_OK);
StringEntity entity = new StringEntity("success", HTTP.ASCII); StringEntity entity = new StringEntity("success", Consts.ASCII);
response.setEntity(entity); response.setEntity(entity);
} }
} }

View File

@ -67,7 +67,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<httpcore.version>4.2-beta1</httpcore.version> <httpcore.version>4.2</httpcore.version>
<commons-logging.version>1.1.1</commons-logging.version> <commons-logging.version>1.1.1</commons-logging.version>
<commons-codec.version>1.6</commons-codec.version> <commons-codec.version>1.6</commons-codec.version>
<ehcache.version>2.2.0</ehcache.version> <ehcache.version>2.2.0</ehcache.version>