Renamed classes

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1189323 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2011-10-26 17:13:09 +00:00
parent 66e7b84915
commit d8b5071301
3 changed files with 81 additions and 81 deletions

View File

@ -50,14 +50,14 @@ import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.SchemeRegistryFactory; import org.apache.http.impl.conn.SchemeRegistryFactory;
import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpContext;
public class FluentExecutor { public class Executor {
final static PoolingClientConnectionManager CONNMGR = new PoolingClientConnectionManager( final static PoolingClientConnectionManager CONNMGR = new PoolingClientConnectionManager(
SchemeRegistryFactory.createSystemDefault()); SchemeRegistryFactory.createSystemDefault());
final static DefaultHttpClient CLIENT = new DefaultHttpClient(CONNMGR); final static DefaultHttpClient CLIENT = new DefaultHttpClient(CONNMGR);
public static FluentExecutor newInstance() { public static Executor newInstance() {
return new FluentExecutor(CLIENT); return new Executor(CLIENT);
} }
private final HttpClient httpclient; private final HttpClient httpclient;
@ -67,14 +67,14 @@ public class FluentExecutor {
private CredentialsProvider credentialsProvider; private CredentialsProvider credentialsProvider;
private CookieStore cookieStore; private CookieStore cookieStore;
FluentExecutor(final HttpClient httpclient) { Executor(final HttpClient httpclient) {
super(); super();
this.httpclient = httpclient; this.httpclient = httpclient;
this.localContext = new BasicHttpContext(); this.localContext = new BasicHttpContext();
this.authCache = new BasicAuthCache(); this.authCache = new BasicAuthCache();
} }
public FluentExecutor auth(final AuthScope authScope, final Credentials creds) { public Executor auth(final AuthScope authScope, final Credentials creds) {
if (this.credentialsProvider == null) { if (this.credentialsProvider == null) {
this.credentialsProvider = new BasicCredentialsProvider(); this.credentialsProvider = new BasicCredentialsProvider();
} }
@ -82,75 +82,75 @@ public class FluentExecutor {
return this; return this;
} }
public FluentExecutor auth(final HttpHost host, final Credentials creds) { public Executor auth(final HttpHost host, final Credentials creds) {
AuthScope authScope = host != null ? new AuthScope(host) : AuthScope.ANY; AuthScope authScope = host != null ? new AuthScope(host) : AuthScope.ANY;
return auth(authScope, creds); return auth(authScope, creds);
} }
public FluentExecutor authPreemptive(final HttpHost host, final Credentials creds) { public Executor authPreemptive(final HttpHost host, final Credentials creds) {
auth(host, creds); auth(host, creds);
this.authCache.put(host, new BasicScheme()); this.authCache.put(host, new BasicScheme());
return this; return this;
} }
public FluentExecutor auth(final Credentials cred) { public Executor auth(final Credentials cred) {
return auth(AuthScope.ANY, cred); return auth(AuthScope.ANY, cred);
} }
public FluentExecutor auth(final String username, final String password) { public Executor auth(final String username, final String password) {
return auth(new UsernamePasswordCredentials(username, password)); return auth(new UsernamePasswordCredentials(username, password));
} }
public FluentExecutor auth(final String username, final String password, public Executor auth(final String username, final String password,
final String workstation, final String domain) { final String workstation, final String domain) {
return auth(new NTCredentials(username, password, workstation, domain)); return auth(new NTCredentials(username, password, workstation, domain));
} }
public FluentExecutor auth(final HttpHost host, public Executor auth(final HttpHost host,
final String username, final String password) { final String username, final String password) {
return auth(host, new UsernamePasswordCredentials(username, password)); return auth(host, new UsernamePasswordCredentials(username, password));
} }
public FluentExecutor auth(final HttpHost host, public Executor auth(final HttpHost host,
final String username, final String password, final String username, final String password,
final String workstation, final String domain) { final String workstation, final String domain) {
return auth(host, new NTCredentials(username, password, workstation, domain)); return auth(host, new NTCredentials(username, password, workstation, domain));
} }
public FluentExecutor authPreemptive(final HttpHost host, public Executor authPreemptive(final HttpHost host,
final String username, final String password) { final String username, final String password) {
auth(host, username, password); auth(host, username, password);
this.authCache.put(host, new BasicScheme()); this.authCache.put(host, new BasicScheme());
return this; return this;
} }
public FluentExecutor clearAuth() { public Executor clearAuth() {
if (this.credentialsProvider != null) { if (this.credentialsProvider != null) {
this.credentialsProvider.clear(); this.credentialsProvider.clear();
} }
return this; return this;
} }
public FluentExecutor cookieStore(final CookieStore cookieStore) { public Executor cookieStore(final CookieStore cookieStore) {
this.cookieStore = cookieStore; this.cookieStore = cookieStore;
return this; return this;
} }
public FluentExecutor clearCookies() { public Executor clearCookies() {
if (this.cookieStore != null) { if (this.cookieStore != null) {
this.cookieStore.clear(); this.cookieStore.clear();
} }
return this; return this;
} }
public FluentResponse exec( public Response exec(
final FluentRequest req) throws ClientProtocolException, IOException { final Request req) throws ClientProtocolException, IOException {
this.localContext.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider); this.localContext.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
this.localContext.setAttribute(ClientContext.AUTH_CACHE, this.authCache); this.localContext.setAttribute(ClientContext.AUTH_CACHE, this.authCache);
this.localContext.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore); this.localContext.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
HttpRequestBase httprequest = req.getHttpRequest(); HttpRequestBase httprequest = req.getHttpRequest();
httprequest.reset(); httprequest.reset();
return new FluentResponse(this.httpclient.execute(httprequest, this.localContext)); return new Response(this.httpclient.execute(httprequest, this.localContext));
} }
public static void setMaxTotal(int max) { public static void setMaxTotal(int max) {

View File

@ -62,7 +62,7 @@ import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HTTP;
public class FluentRequest { public class Request {
public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz"; public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
public static final Locale DATE_LOCALE = Locale.US; public static final Locale DATE_LOCALE = Locale.US;
@ -73,63 +73,63 @@ public class FluentRequest {
private SimpleDateFormat dateFormatter; private SimpleDateFormat dateFormatter;
public static FluentRequest Get(final URI uri) { public static Request Get(final URI uri) {
return new FluentRequest(new HttpGet(uri)); return new Request(new HttpGet(uri));
} }
public static FluentRequest Get(final String uri) { public static Request Get(final String uri) {
return new FluentRequest(new HttpGet(uri)); return new Request(new HttpGet(uri));
} }
public static FluentRequest Head(final URI uri) { public static Request Head(final URI uri) {
return new FluentRequest(new HttpHead(uri)); return new Request(new HttpHead(uri));
} }
public static FluentRequest Head(final String uri) { public static Request Head(final String uri) {
return new FluentRequest(new HttpHead(uri)); return new Request(new HttpHead(uri));
} }
public static FluentRequest Post(final URI uri) { public static Request Post(final URI uri) {
return new FluentRequest(new HttpPost(uri)); return new Request(new HttpPost(uri));
} }
public static FluentRequest Post(final String uri) { public static Request Post(final String uri) {
return new FluentRequest(new HttpPost(uri)); return new Request(new HttpPost(uri));
} }
public static FluentRequest Put(final URI uri) { public static Request Put(final URI uri) {
return new FluentRequest(new HttpPut(uri)); return new Request(new HttpPut(uri));
} }
public static FluentRequest Put(final String uri) { public static Request Put(final String uri) {
return new FluentRequest(new HttpPut(uri)); return new Request(new HttpPut(uri));
} }
public static FluentRequest Trace(final URI uri) { public static Request Trace(final URI uri) {
return new FluentRequest(new HttpTrace(uri)); return new Request(new HttpTrace(uri));
} }
public static FluentRequest Trace(final String uri) { public static Request Trace(final String uri) {
return new FluentRequest(new HttpTrace(uri)); return new Request(new HttpTrace(uri));
} }
public static FluentRequest Delete(final URI uri) { public static Request Delete(final URI uri) {
return new FluentRequest(new HttpDelete(uri)); return new Request(new HttpDelete(uri));
} }
public static FluentRequest Delete(final String uri) { public static Request Delete(final String uri) {
return new FluentRequest(new HttpDelete(uri)); return new Request(new HttpDelete(uri));
} }
public static FluentRequest Options(final URI uri) { public static Request Options(final URI uri) {
return new FluentRequest(new HttpOptions(uri)); return new Request(new HttpOptions(uri));
} }
public static FluentRequest Options(final String uri) { public static Request Options(final String uri) {
return new FluentRequest(new HttpOptions(uri)); return new Request(new HttpOptions(uri));
} }
FluentRequest(final HttpRequestBase request) { Request(final HttpRequestBase request) {
super(); super();
this.request = request; this.request = request;
this.localParams = request.getParams(); this.localParams = request.getParams();
@ -139,8 +139,8 @@ public class FluentRequest {
return this.request; return this.request;
} }
public FluentResponse exec() throws ClientProtocolException, IOException { public Response exec() throws ClientProtocolException, IOException {
return new FluentResponse(FluentExecutor.CLIENT.execute(this.request)); return new Response(Executor.CLIENT.execute(this.request));
} }
public void abort() throws UnsupportedOperationException { public void abort() throws UnsupportedOperationException {
@ -149,32 +149,32 @@ public class FluentRequest {
//// HTTP header operations //// HTTP header operations
public FluentRequest addHeader(final Header header) { public Request addHeader(final Header header) {
this.request.addHeader(header); this.request.addHeader(header);
return this; return this;
} }
public FluentRequest addHeader(final String name, final String value) { public Request addHeader(final String name, final String value) {
this.request.addHeader(name, value); this.request.addHeader(name, value);
return this; return this;
} }
public FluentRequest removeHeader(final Header header) { public Request removeHeader(final Header header) {
this.request.removeHeader(header); this.request.removeHeader(header);
return this; return this;
} }
public FluentRequest removeHeaders(final String name) { public Request removeHeaders(final String name) {
this.request.removeHeaders(name); this.request.removeHeaders(name);
return this; return this;
} }
public FluentRequest setHeaders(final Header[] headers) { public Request setHeaders(final Header[] headers) {
this.request.setHeaders(headers); this.request.setHeaders(headers);
return this; return this;
} }
public FluentRequest setCacheControl(String cacheControl) { public Request setCacheControl(String cacheControl) {
this.request.setHeader(HttpHeader.CACHE_CONTROL, cacheControl); this.request.setHeader(HttpHeader.CACHE_CONTROL, cacheControl);
return this; return this;
} }
@ -187,78 +187,78 @@ public class FluentRequest {
return this.dateFormatter; return this.dateFormatter;
} }
public FluentRequest setDate(final Date date) { public Request setDate(final Date date) {
this.request.setHeader(HttpHeader.DATE, getDateFormat().format(date)); this.request.setHeader(HttpHeader.DATE, getDateFormat().format(date));
return this; return this;
} }
public FluentRequest setIfModifiedSince(final Date date) { public Request setIfModifiedSince(final Date date) {
this.request.setHeader(HttpHeader.IF_MODIFIED_SINCE, getDateFormat().format(date)); this.request.setHeader(HttpHeader.IF_MODIFIED_SINCE, getDateFormat().format(date));
return this; return this;
} }
public FluentRequest setIfUnmodifiedSince(final Date date) { public Request setIfUnmodifiedSince(final Date date) {
this.request.setHeader(HttpHeader.IF_UNMODIFIED_SINCE, getDateFormat().format(date)); this.request.setHeader(HttpHeader.IF_UNMODIFIED_SINCE, getDateFormat().format(date));
return this; return this;
} }
//// HTTP config parameter operations //// HTTP config parameter operations
public FluentRequest config(final String param, final Object object) { public Request config(final String param, final Object object) {
this.localParams.setParameter(param, object); this.localParams.setParameter(param, object);
return this; return this;
} }
public FluentRequest removeConfig(final String param) { public Request removeConfig(final String param) {
this.localParams.removeParameter(param); this.localParams.removeParameter(param);
return this; return this;
} }
//// HTTP protocol parameter operations //// HTTP protocol parameter operations
public FluentRequest version(final HttpVersion version) { public Request version(final HttpVersion version) {
return config(CoreProtocolPNames.PROTOCOL_VERSION, version); return config(CoreProtocolPNames.PROTOCOL_VERSION, version);
} }
public FluentRequest elementCharset(final String charset) { public Request elementCharset(final String charset) {
return config(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset); return config(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset);
} }
public FluentRequest useExpectContinue() { public Request useExpectContinue() {
return config(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); return config(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
} }
public FluentRequest userAgent(final String agent) { public Request userAgent(final String agent) {
return config(CoreProtocolPNames.USER_AGENT, agent); return config(CoreProtocolPNames.USER_AGENT, agent);
} }
//// HTTP connection parameter operations //// HTTP connection parameter operations
public FluentRequest socketTimeout(int timeout) { public Request socketTimeout(int timeout) {
return config(CoreConnectionPNames.SO_TIMEOUT, timeout); return config(CoreConnectionPNames.SO_TIMEOUT, timeout);
} }
public FluentRequest connectTimeout(int timeout) { public Request connectTimeout(int timeout) {
return config(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); return config(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
} }
public FluentRequest staleConnectionCheck(boolean b) { public Request staleConnectionCheck(boolean b) {
return config(CoreConnectionPNames.STALE_CONNECTION_CHECK, b); return config(CoreConnectionPNames.STALE_CONNECTION_CHECK, b);
} }
//// HTTP connection route operations //// HTTP connection route operations
public FluentRequest proxy(final HttpHost proxy) { public Request proxy(final HttpHost proxy) {
return config(ConnRoutePNames.DEFAULT_PROXY, proxy); return config(ConnRoutePNames.DEFAULT_PROXY, proxy);
} }
public FluentRequest noProxy() { public Request noProxy() {
return removeConfig(ConnRoutePNames.DEFAULT_PROXY); return removeConfig(ConnRoutePNames.DEFAULT_PROXY);
} }
//// HTTP entity operations //// HTTP entity operations
public FluentRequest body(final HttpEntity entity) { public Request body(final HttpEntity entity) {
if (this.request instanceof HttpEntityEnclosingRequest) { if (this.request instanceof HttpEntityEnclosingRequest) {
((HttpEntityEnclosingRequest) this.request).setEntity(entity); ((HttpEntityEnclosingRequest) this.request).setEntity(entity);
} else { } else {
@ -268,7 +268,7 @@ public class FluentRequest {
return this; return this;
} }
public FluentRequest htmlFormBody(final NameValuePair[] formParams, final String charset) { public Request htmlFormBody(final NameValuePair[] formParams, final String charset) {
try { try {
return body(new UrlEncodedFormEntity(Arrays.asList(formParams))); return body(new UrlEncodedFormEntity(Arrays.asList(formParams)));
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
@ -276,27 +276,27 @@ public class FluentRequest {
} }
} }
public FluentRequest htmlFormBody(final NameValuePair... formParams) { public Request htmlFormBody(final NameValuePair... formParams) {
return htmlFormBody(formParams, HTTP.DEFAULT_CONTENT_CHARSET); return htmlFormBody(formParams, HTTP.DEFAULT_CONTENT_CHARSET);
} }
public FluentRequest stringBody(final String s, final ContentType contentType) { public Request stringBody(final String s, final ContentType contentType) {
return body(StringEntity.create(s, contentType)); return body(StringEntity.create(s, contentType));
} }
public FluentRequest byteArrayBody(final byte[] b) { public Request byteArrayBody(final byte[] b) {
return body(new ByteArrayEntity(b)); return body(new ByteArrayEntity(b));
} }
public FluentRequest byteArrayBody(final byte[] b, int off, int len) { public Request byteArrayBody(final byte[] b, int off, int len) {
return body(new ByteArrayEntity(b, off, len)); return body(new ByteArrayEntity(b, off, len));
} }
public FluentRequest streamBody(final InputStream instream) { public Request streamBody(final InputStream instream) {
return body(new InputStreamEntity(instream, -1)); return body(new InputStreamEntity(instream, -1));
} }
public FluentRequest streamBody(final InputStream instream, final ContentType contentType) { public Request streamBody(final InputStream instream, final ContentType contentType) {
return body(new InputStreamEntity(instream, -1, contentType)); return body(new InputStreamEntity(instream, -1, contentType));
} }

View File

@ -40,12 +40,12 @@ import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
public class FluentResponse { public class Response {
private final HttpResponse response; private final HttpResponse response;
private boolean consumed; private boolean consumed;
FluentResponse(final HttpResponse response) { Response(final HttpResponse response) {
super(); super();
this.response = response; this.response = response;
} }