Use HttpUriRequest interface for a better compatibility with HttpClient 4.x
This commit is contained in:
parent
49cdb631f5
commit
9e8ab71517
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue