From 9e8ab71517aace161fc2df646029554b5fd0c34c Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sun, 14 Oct 2018 17:57:10 +0200 Subject: [PATCH] Use HttpUriRequest interface for a better compatibility with HttpClient 4.x --- .../classic/methods/ClassicHttpRequests.java | 28 +++++++++---------- .../http/classic/methods/HttpUriRequest.java | 3 +- .../classic/methods/HttpUriRequestBase.java | 13 +++++++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java index cadaec260..fec640a69 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java @@ -39,78 +39,78 @@ public enum ClassicHttpRequests { DELETE { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpDelete(uri); } }, GET { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpGet(uri); } }, HEAD { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpHead(uri); } }, OPTIONS { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpOptions(uri); } }, PATCH { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpPatch(uri); } }, POST { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpPost(uri); } }, PUT { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpPut(uri); } }, TRACE { @Override - public HttpUriRequestBase create(final URI uri) { + public HttpUriRequest create(final URI uri) { return new HttpTrace(uri); } }; /** - * Creates a request object of the exact subclass of {@link HttpUriRequestBase}. + * Creates a request object of the exact subclass of {@link HttpUriRequest}. * * @param uri * a non-null URI String. - * @return a new subclass of HttpUriRequestBase + * @return a new subclass of HttpUriRequest */ - public HttpUriRequestBase create(final String uri) { + public HttpUriRequest create(final String uri) { return create(URI.create(uri)); } /** - * Creates a request object of the exact subclass of {@link HttpUriRequestBase}. + * Creates a request object of the exact subclass of {@link HttpUriRequest}. * * @param uri * a non-null URI. - * @return a new subclass of HttpUriRequestBase + * @return a new subclass of HttpUriRequest */ - public abstract HttpUriRequestBase create(URI uri); + public abstract HttpUriRequest create(URI uri); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java index 1c3064b5c..ce6ec480f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequest.java @@ -27,6 +27,7 @@ package org.apache.hc.client5.http.classic.methods; +import org.apache.hc.client5.http.config.Configurable; import org.apache.hc.core5.http.ClassicHttpRequest; /** @@ -36,7 +37,7 @@ import org.apache.hc.core5.http.ClassicHttpRequest; * * @since 4.0 */ -public interface HttpUriRequest extends ClassicHttpRequest { +public interface HttpUriRequest extends ClassicHttpRequest, Configurable { /** * Aborts execution of the request. diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java index 7eae81818..d16716a3c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUriRequestBase.java @@ -30,13 +30,12 @@ import java.net.URI; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import org.apache.hc.client5.http.config.Configurable; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.core5.concurrent.Cancellable; import org.apache.hc.core5.concurrent.CancellableDependency; import org.apache.hc.core5.http.message.BasicClassicHttpRequest; -public class HttpUriRequestBase extends BasicClassicHttpRequest implements CancellableDependency, Configurable { +public class HttpUriRequestBase extends BasicClassicHttpRequest implements HttpUriRequest, CancellableDependency { private static final long serialVersionUID = 1L; @@ -90,6 +89,16 @@ public class HttpUriRequestBase extends BasicClassicHttpRequest implements Cance this.cancelled.set(false); } + @Override + public void abort() throws UnsupportedOperationException { + cancel(); + } + + @Override + public boolean isAborted() { + return isCancelled(); + } + public void setConfig(final RequestConfig requestConfig) { this.requestConfig = requestConfig; }