Javadocs; renamed some methods (no functional changes)
This commit is contained in:
parent
c446639820
commit
37c8006472
|
@ -26,14 +26,11 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http.cache;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Records static constants for various HTTP header names.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
public class HeaderConstants {
|
||||
|
||||
public static final String GET_METHOD = "GET";
|
||||
|
|
|
@ -29,6 +29,8 @@ package org.apache.hc.client5.http.cache;
|
|||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.concurrent.Cancellable;
|
||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
|
||||
|
@ -37,9 +39,13 @@ import org.apache.hc.core5.concurrent.FutureCallback;
|
|||
* storage backend that can then be plugged into the asynchronous
|
||||
* (non-blocking ) request execution
|
||||
* pipeline.
|
||||
* <p>
|
||||
* Implementations of this interface are expected to be threading-safe.
|
||||
* </p>
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE)
|
||||
public interface HttpAsyncCacheStorage {
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,8 @@ import java.util.Collection;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.hc.client5.http.impl.Operations;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.concurrent.Cancellable;
|
||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
@ -40,6 +42,7 @@ import org.apache.hc.core5.util.Args;
|
|||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
|
||||
public final class HttpAsyncCacheStorageAdaptor implements HttpAsyncCacheStorage {
|
||||
|
||||
private final HttpCacheStorage cacheStorage;
|
||||
|
|
|
@ -26,11 +26,15 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http.cache;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Atomic Compare-And-Swap (CAS) cache operation.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface HttpCacheCASOperation {
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,6 +31,9 @@ import org.apache.hc.core5.http.protocol.BasicHttpContext;
|
|||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* Adaptor class that provides convenience type safe setters and getters
|
||||
* for caching {@link HttpContext} attributes.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public class HttpCacheContext extends HttpClientContext {
|
||||
|
|
|
@ -26,11 +26,15 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http.cache;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Serializer / deserializer for {@link HttpCacheStorageEntry} entries.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface HttpCacheEntrySerializer<T> {
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,9 @@ package org.apache.hc.client5.http.cache;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.Internal;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.function.Resolver;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
|
@ -40,6 +42,7 @@ import org.apache.hc.core5.http.HttpResponse;
|
|||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
@Internal
|
||||
public interface HttpCacheInvalidator {
|
||||
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.hc.client5.http.cache;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.EntityDetails;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
public final class HttpCacheResponse implements EntityDetails {
|
||||
|
||||
private final int code;
|
||||
private final String reasonPhrase;
|
||||
private final byte[] body;
|
||||
private final ContentType contentType;
|
||||
|
||||
public static HttpCacheResponse create(
|
||||
final int code,
|
||||
final String reasonPhrase,
|
||||
final byte[] body,
|
||||
final ContentType contentType) {
|
||||
return new HttpCacheResponse(code, reasonPhrase, body, contentType);
|
||||
}
|
||||
|
||||
public static HttpCacheResponse create(
|
||||
final int code,
|
||||
final byte[] body,
|
||||
final ContentType contentType) {
|
||||
return new HttpCacheResponse(code, null, body, contentType);
|
||||
}
|
||||
|
||||
public static HttpCacheResponse create(
|
||||
final int code,
|
||||
final String reasonPhrase) {
|
||||
return new HttpCacheResponse(code, reasonPhrase, null, null);
|
||||
}
|
||||
|
||||
public static HttpCacheResponse create(final int code) {
|
||||
return new HttpCacheResponse(code, null, null, null);
|
||||
}
|
||||
|
||||
public static HttpCacheResponse create(
|
||||
final int code,
|
||||
final String reasonPhrase,
|
||||
final String body,
|
||||
final ContentType contentType) {
|
||||
if (body != null) {
|
||||
final Charset charset = contentType != null ? contentType.getCharset() : null;
|
||||
final byte[] b = body.getBytes(charset != null ? charset : StandardCharsets.US_ASCII);
|
||||
return new HttpCacheResponse(code, reasonPhrase, b, contentType);
|
||||
} else {
|
||||
return create(code, reasonPhrase);
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpCacheResponse create(
|
||||
final int code,
|
||||
final String body,
|
||||
final ContentType contentType) {
|
||||
return create(code, null, body, contentType);
|
||||
}
|
||||
|
||||
private HttpCacheResponse(
|
||||
final int code,
|
||||
final String reasonPhrase,
|
||||
final byte[] body,
|
||||
final ContentType contentType) {
|
||||
this.code = Args.checkRange(code, 200, 599, "HTTP status");
|
||||
this.reasonPhrase = reasonPhrase;
|
||||
this.body = body;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getReasonPhrase() {
|
||||
return reasonPhrase;
|
||||
}
|
||||
|
||||
public byte[] getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getContentLength() {
|
||||
return body != null ? body.length : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return contentType != null ? contentType.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentEncoding() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTrailerNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,13 +29,20 @@ package org.apache.hc.client5.http.cache;
|
|||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* {@literal HttpCacheStorage} represents an abstract HTTP cache
|
||||
* storage backend that can then be plugged into the classic
|
||||
* (blocking) request execution pipeline.
|
||||
* <p>
|
||||
* Implementations of this interface are expected to be threading-safe.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE)
|
||||
public interface HttpCacheStorage {
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,8 +28,16 @@ package org.apache.hc.client5.http.cache;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* This class contains a {@link HttpCacheEntry} along with its key.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
public final class HttpCacheStorageEntry implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -30,12 +30,19 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Represents a disposable system resource used for handling
|
||||
* cached response bodies.
|
||||
* <p>
|
||||
* Implementations of this interface are expected to be threading-safe.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE)
|
||||
public abstract class Resource implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -26,12 +26,16 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http.cache;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Generates {@link Resource} instances for handling cached
|
||||
* HTTP response bodies.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface ResourceFactory {
|
||||
|
||||
/**
|
||||
|
|
32
httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/package-info.java
vendored
Normal file
32
httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/package-info.java
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caching APIs for both the classic and the asynchronous
|
||||
* HTTP transports.
|
||||
*/
|
||||
package org.apache.hc.client5.http.cache;
|
|
@ -1,78 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
====================================================================
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the Apache Software Foundation. For more
|
||||
information on the Apache Software Foundation, please see
|
||||
<http://www.apache.org/>.
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<p>
|
||||
This package consists largely of constants and interfaces that are
|
||||
necessary for building new storage backends for the
|
||||
{@link org.apache.hc.client5.http.impl.client.cache.CachingHttpClient} or for
|
||||
those clients wanting to get a little more behavioral information
|
||||
out of the cache module (for example, whether a particular response
|
||||
was a cache hit or not). Developers that simply want to instantiate
|
||||
and make use of the caching module will be better off looking at
|
||||
the {@code CachingHttpClient} documentation itself.
|
||||
</p>
|
||||
<p>
|
||||
The classes in this package can be divided into two main groups:
|
||||
reference constants and interfaces needed for storage backends. In
|
||||
the former group,
|
||||
{@link org.apache.hc.client5.http.client.cache.HeaderConstants} contains a list
|
||||
of HTTP header names encoded as static fields, and the
|
||||
{@link org.apache.hc.client5.http.client.cache.CacheResponseStatus} enumeration
|
||||
values are set in an {@link org.apache.hc.client5.http.protocol.HttpContext} by
|
||||
the {@code CachingHttpClient} to indicate how the request was
|
||||
processed by the caching module itself.
|
||||
</p>
|
||||
<p>
|
||||
New storage backends will need to implement the
|
||||
{@link org.apache.hc.client5.http.client.cache.HttpCacheStorage}
|
||||
interface; they can then be passed to one of the {@code CachingHttpClient}
|
||||
constructors, which will happily make use of the new storage mechanism.
|
||||
The {@link org.apache.hc.client5.http.client.cache.HttpCacheEntry} class shows the
|
||||
datastructure for a cache entry that must be stored by the
|
||||
{@code HttpCacheStorage}.
|
||||
There is, in addition, the notion of a
|
||||
{@link org.apache.hc.client5.http.client.cache.Resource} and an associated
|
||||
{@link org.apache.hc.client5.http.client.cache.ResourceFactory}, which are used for
|
||||
managing the handling of cached response bodies. The default implementation
|
||||
used by the {@code CachingHttpClient} stores response bodies in memory;
|
||||
alternative implementations might involve storing these in a filesystem. A new
|
||||
{@code ResourceFactory} can be provided along with a {@code HttpCacheStorage}
|
||||
in one of the constructors to the {@code CachingHttpClient}. Finally, some
|
||||
of the additional storage backends we provide, like the
|
||||
{@link org.apache.hc.client5.http.impl.client.cache.ehcache.EhcacheHttpCacheStorage} and
|
||||
{@link org.apache.hc.client5.http.impl.client.cache.memcached.MemcachedHttpCacheStorage},
|
||||
can be provided with different serializers for the cache entry metadata;
|
||||
developers wanting to experiment with different serialization techniques
|
||||
should implement the
|
||||
{@link org.apache.hc.client5.http.client.cache.HttpCacheEntrySerializer} interface.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -88,7 +88,7 @@ import org.apache.hc.core5.util.ByteArrayBuffer;
|
|||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE) // So long as the responseCache implementation is threadsafe
|
||||
public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler {
|
||||
class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler {
|
||||
|
||||
private final HttpAsyncCache responseCache;
|
||||
private final DefaultAsyncCacheRevalidator cacheRevalidator;
|
||||
|
@ -120,7 +120,7 @@ public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainH
|
|||
this.conditionalRequestBuilder = conditionalRequestBuilder;
|
||||
}
|
||||
|
||||
public AsyncCachingExec(
|
||||
AsyncCachingExec(
|
||||
final HttpAsyncCache cache,
|
||||
final ScheduledExecutorService executorService,
|
||||
final SchedulingStrategy schedulingStrategy,
|
||||
|
@ -130,7 +130,7 @@ public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainH
|
|||
config);
|
||||
}
|
||||
|
||||
public AsyncCachingExec(
|
||||
AsyncCachingExec(
|
||||
final ResourceFactory resourceFactory,
|
||||
final HttpAsyncCacheStorage storage,
|
||||
final ScheduledExecutorService executorService,
|
||||
|
@ -144,7 +144,7 @@ public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainH
|
|||
final AsyncExecChain.Scope scope,
|
||||
final AsyncExecCallback asyncExecCallback) {
|
||||
scope.clientContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, cacheResponse);
|
||||
scope.execRuntime.releaseConnection();
|
||||
scope.execRuntime.releaseEndpoint();
|
||||
|
||||
final SimpleBody body = cacheResponse.getBody();
|
||||
final byte[] content = body != null ? body.getBodyBytes() : null;
|
||||
|
|
|
@ -33,13 +33,9 @@ import java.security.SecureRandom;
|
|||
import java.util.Formatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Should produce reasonably unique tokens.
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE)
|
||||
class BasicIdGenerator {
|
||||
|
||||
private final String hostname;
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
|
|||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public final class ByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> {
|
||||
|
||||
public static final ByteArrayCacheEntrySerializer INSTANCE = new ByteArrayCacheEntrySerializer();
|
||||
|
|
|
@ -50,7 +50,7 @@ import org.apache.hc.core5.http.message.MessageSupport;
|
|||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public class CacheKeyGenerator implements Resolver<URI, String> {
|
||||
|
||||
public static final CacheKeyGenerator INSTANCE = new CacheKeyGenerator();
|
||||
|
|
|
@ -37,8 +37,6 @@ import org.apache.hc.client5.http.cache.Resource;
|
|||
import org.apache.hc.client5.http.cache.ResourceFactory;
|
||||
import org.apache.hc.client5.http.cache.ResourceIOException;
|
||||
import org.apache.hc.client5.http.utils.DateUtils;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
|
@ -51,10 +49,7 @@ import org.apache.hc.core5.util.ByteArrayBuffer;
|
|||
/**
|
||||
* Creates new {@link HttpCacheEntry}s and updates existing ones with new or updated information
|
||||
* based on the response from the origin server.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class CacheUpdateHandler {
|
||||
|
||||
private final ResourceFactory resourceFactory;
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.apache.hc.client5.http.cache.HeaderConstants;
|
|||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||
import org.apache.hc.client5.http.cache.Resource;
|
||||
import org.apache.hc.client5.http.utils.DateUtils;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
|
@ -42,10 +40,6 @@ import org.apache.hc.core5.http.HttpRequest;
|
|||
import org.apache.hc.core5.http.MessageHeaders;
|
||||
import org.apache.hc.core5.http.message.MessageSupport;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class CacheValidityPolicy {
|
||||
|
||||
public static final long MAX_AGE = 2147483648L;
|
||||
|
|
|
@ -29,8 +29,6 @@ package org.apache.hc.client5.http.impl.cache;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
|
@ -41,10 +39,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* Determines if an HttpRequest is allowed to be served from the cache.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class CacheableRequestPolicy {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
|
|
@ -34,8 +34,6 @@ import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
|||
import org.apache.hc.client5.http.cache.Resource;
|
||||
import org.apache.hc.client5.http.cache.ResourceIOException;
|
||||
import org.apache.hc.client5.http.utils.DateUtils;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
|
@ -47,10 +45,7 @@ import org.apache.hc.core5.http.message.BasicHeader;
|
|||
|
||||
/**
|
||||
* Rebuilds an {@link HttpResponse} from a {@link HttpCacheEntry}
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class CachedHttpResponseGenerator {
|
||||
|
||||
private final CacheValidityPolicy validityStrategy;
|
||||
|
|
|
@ -32,8 +32,6 @@ import java.util.Iterator;
|
|||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||
import org.apache.hc.client5.http.utils.DateUtils;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
@ -46,10 +44,7 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* Determines whether a given {@link HttpCacheEntry} is suitable to be
|
||||
* used as a response for a given {@link HttpRequest}.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class CachedResponseSuitabilityChecker {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
|
|
@ -49,8 +49,6 @@ import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier;
|
|||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||
import org.apache.hc.client5.http.schedule.SchedulingStrategy;
|
||||
import org.apache.hc.client5.http.utils.DateUtils;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.ClassicHttpRequest;
|
||||
import org.apache.hc.core5.http.ClassicHttpResponse;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
|
@ -100,8 +98,7 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE) // So long as the responseCache implementation is threadsafe
|
||||
public class CachingExec extends CachingExecBase implements ExecChainHandler {
|
||||
class CachingExec extends CachingExecBase implements ExecChainHandler {
|
||||
|
||||
private final HttpCache responseCache;
|
||||
private final DefaultCacheRevalidator cacheRevalidator;
|
||||
|
@ -135,7 +132,7 @@ public class CachingExec extends CachingExecBase implements ExecChainHandler {
|
|||
this.conditionalRequestBuilder = conditionalRequestBuilder;
|
||||
}
|
||||
|
||||
public CachingExec(
|
||||
CachingExec(
|
||||
final HttpCache cache,
|
||||
final ScheduledExecutorService executorService,
|
||||
final SchedulingStrategy schedulingStrategy,
|
||||
|
@ -145,7 +142,7 @@ public class CachingExec extends CachingExecBase implements ExecChainHandler {
|
|||
config);
|
||||
}
|
||||
|
||||
public CachingExec(
|
||||
CachingExec(
|
||||
final ResourceFactory resourceFactory,
|
||||
final HttpCacheStorage storage,
|
||||
final ScheduledExecutorService executorService,
|
||||
|
|
|
@ -30,8 +30,6 @@ package org.apache.hc.client5.http.impl.cache;
|
|||
import java.io.File;
|
||||
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link CloseableHttpAsyncClient} instances
|
||||
|
@ -39,8 +37,7 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
|
|||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
public class CachingHttpAsyncClients {
|
||||
public final class CachingHttpAsyncClients {
|
||||
|
||||
private CachingHttpAsyncClients() {
|
||||
super();
|
||||
|
|
|
@ -30,8 +30,6 @@ package org.apache.hc.client5.http.impl.cache;
|
|||
import java.io.File;
|
||||
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link CloseableHttpClient} instances
|
||||
|
@ -39,8 +37,7 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
|
|||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
public class CachingHttpClients {
|
||||
public final class CachingHttpClients {
|
||||
|
||||
private CachingHttpClients() {
|
||||
super();
|
||||
|
|
|
@ -32,17 +32,11 @@ import java.util.Map;
|
|||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||
import org.apache.hc.client5.http.impl.MessageCopier;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.message.MessageSupport;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class ConditionalRequestBuilder<T extends HttpRequest> {
|
||||
|
||||
private final MessageCopier<T> messageCopier;
|
||||
|
|
|
@ -56,7 +56,7 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
@Internal
|
||||
public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implements HttpAsyncCacheInvalidator {
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
@Internal
|
||||
public class DefaultCacheInvalidator extends CacheInvalidatorBase implements HttpCacheInvalidator {
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.hc.core5.util.Args;
|
|||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public class FileResourceFactory implements ResourceFactory {
|
||||
|
||||
private final File cacheDir;
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.hc.core5.util.Args;
|
|||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public class HeapResourceFactory implements ResourceFactory {
|
||||
|
||||
public static final HeapResourceFactory INSTANCE = new HeapResourceFactory();
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.Date;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||
import org.apache.hc.core5.annotation.Internal;
|
||||
import org.apache.hc.core5.concurrent.Cancellable;
|
||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
@ -38,10 +37,6 @@ import org.apache.hc.core5.http.HttpRequest;
|
|||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.util.ByteArrayBuffer;
|
||||
|
||||
/**
|
||||
* @since 5.0
|
||||
*/
|
||||
@Internal
|
||||
interface HttpAsyncCache {
|
||||
|
||||
String generateKey (HttpHost host, HttpRequest request, HttpCacheEntry cacheEntry);
|
||||
|
|
|
@ -35,9 +35,6 @@ import org.apache.hc.core5.http.HttpRequest;
|
|||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.util.ByteArrayBuffer;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
interface HttpCache {
|
||||
|
||||
String generateKey (HttpHost host, HttpRequest request, HttpCacheEntry cacheEntry);
|
||||
|
|
|
@ -35,9 +35,9 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
|
||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||
import org.apache.hc.client5.http.cache.HttpCacheStorage;
|
||||
import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
|
||||
import org.apache.hc.client5.http.cache.Resource;
|
||||
import org.apache.hc.client5.http.cache.ResourceIOException;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
|
|
|
@ -33,9 +33,12 @@ import org.apache.hc.core5.annotation.Contract;
|
|||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* {@link HttpCacheEntrySerializer} that uses {@link HttpCacheStorageEntry}
|
||||
* as its cache content representation.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public class NoopCacheEntrySerializer implements HttpCacheEntrySerializer<HttpCacheStorageEntry> {
|
||||
|
||||
public static final NoopCacheEntrySerializer INSTANCE = new NoopCacheEntrySerializer();
|
||||
|
|
|
@ -32,8 +32,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
|
@ -41,10 +39,6 @@ import org.apache.hc.core5.http.HttpVersion;
|
|||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.message.MessageSupport;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class RequestProtocolCompliance {
|
||||
private final boolean weakETagOnPutDeleteAllowed;
|
||||
|
||||
|
|
|
@ -26,9 +26,6 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http.impl.cache;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
enum RequestProtocolError {
|
||||
|
||||
UNKNOWN,
|
||||
|
|
|
@ -31,11 +31,8 @@ import java.lang.ref.ReferenceQueue;
|
|||
|
||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||
import org.apache.hc.client5.http.cache.Resource;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class ResourceReference extends PhantomReference<HttpCacheEntry> {
|
||||
|
||||
private final Resource resource;
|
||||
|
|
|
@ -34,8 +34,6 @@ import java.util.Set;
|
|||
|
||||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||
import org.apache.hc.client5.http.utils.DateUtils;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
|
@ -49,12 +47,6 @@ import org.apache.hc.core5.http.message.MessageSupport;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Determines if an HttpResponse can be cached.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class ResponseCachingPolicy {
|
||||
|
||||
private static final String[] AUTH_CACHEABLE_PARAMS = {
|
||||
|
|
|
@ -34,8 +34,6 @@ import java.util.List;
|
|||
import org.apache.hc.client5.http.ClientProtocolException;
|
||||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||
import org.apache.hc.client5.http.utils.DateUtils;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HeaderElements;
|
||||
|
@ -48,10 +46,6 @@ import org.apache.hc.core5.http.ProtocolVersion;
|
|||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.MessageSupport;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
class ResponseProtocolCompliance {
|
||||
|
||||
private static final String UNEXPECTED_100_CONTINUE = "The incoming request did not contain a "
|
||||
|
|
31
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ehcache/package-info.java
vendored
Normal file
31
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ehcache/package-info.java
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <a href="http://ehcache.org/">Ehcache</a> based caching backend implementation.
|
||||
*/
|
||||
package org.apache.hc.client5.http.impl.cache.ehcache;
|
|
@ -1,40 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
====================================================================
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the Apache Software Foundation. For more
|
||||
information on the Apache Software Foundation, please see
|
||||
<http://www.apache.org/>.
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<p>
|
||||
This package contains a storage backend based on
|
||||
<a href="http://ehcache.org/">Ehcache</a>
|
||||
that can be plugged into
|
||||
a {@link org.apache.http.impl.client.cache.CachingHttpClient} and
|
||||
used for storing cache entries.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -58,6 +58,8 @@
|
|||
* keys. Clients can implement this interface to change the way the mapping
|
||||
* is done (for example, to add a prefix to all cache keys to provide a form
|
||||
* of memcached namespacing).
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public interface KeyHashingScheme {
|
||||
|
||||
|
|
|
@ -27,9 +27,11 @@
|
|||
package org.apache.hc.client5.http.impl.cache.memcached;
|
||||
|
||||
/**
|
||||
* Indicates a problem encountered when trying to map a
|
||||
* Signals a problem encountered when trying to map a
|
||||
* logical "storage key" to a "cache key" suitable for use with
|
||||
* memcached.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public class MemcachedKeyHashingException extends RuntimeException {
|
||||
|
||||
|
|
|
@ -29,9 +29,11 @@ package org.apache.hc.client5.http.impl.cache.memcached;
|
|||
import org.apache.hc.client5.http.cache.ResourceIOException;
|
||||
|
||||
/**
|
||||
* Raised when memcached times out on us.
|
||||
* Signals memcached operation timeout.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
class MemcachedOperationTimeoutException extends ResourceIOException {
|
||||
public class MemcachedOperationTimeoutException extends ResourceIOException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ package org.apache.hc.client5.http.impl.cache.memcached;
|
|||
* a known prefix to the results of another {@code KeyHashingScheme}.
|
||||
* Primarily useful for namespacing a shared memcached cluster, for
|
||||
* example.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public final class PrefixKeyHashingScheme implements KeyHashingScheme {
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ import org.slf4j.LoggerFactory;
|
|||
* algorithm. The hashes produced are hex-encoded SHA-256
|
||||
* digests and hence are always 64-character hexadecimal
|
||||
* strings.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public final class SHA256KeyHashingScheme implements KeyHashingScheme {
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <a href="http://memcached.org/">Memcached</a> based caching backend
|
||||
* implementation.
|
||||
*/
|
||||
package org.apache.hc.client5.http.impl.cache.memcached;
|
|
@ -1,40 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
====================================================================
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the Apache Software Foundation. For more
|
||||
information on the Apache Software Foundation, please see
|
||||
<http://www.apache.org/>.
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<p>
|
||||
This package contains a storage backend based on
|
||||
<a href="http://memcached.org/">memcached</a>
|
||||
that can be plugged into
|
||||
a {@link org.apache.http.impl.client.cache.CachingHttpClient} and
|
||||
used for storing cache entries.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
32
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/package-info.java
vendored
Normal file
32
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/package-info.java
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caching API implementation for both the classic and
|
||||
* the asynchronous HTTP transports.
|
||||
*/
|
||||
package org.apache.hc.client5.http.impl.cache;
|
|
@ -1,42 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
====================================================================
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals on behalf of the Apache Software Foundation. For more
|
||||
information on the Apache Software Foundation, please see
|
||||
<http://www.apache.org/>.
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<p>
|
||||
This package contains a cache module that can be used for HTTP/1.1
|
||||
client-side caching. The primary classes in this package are the
|
||||
{@link org.apache.hc.client5.http.impl.client.cache.CachingHttpClient},
|
||||
which is a drop-in replacement for
|
||||
a {@link org.apache.hc.client5.http.impl.client.DefaultHttpClient} that adds
|
||||
caching, and the {@link org.apache.hc.client5.http.impl.client.cache.CacheConfig}
|
||||
class that can be used for configuring it.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -52,9 +52,9 @@ import org.apache.hc.core5.util.TimeValue;
|
|||
* </pre>
|
||||
* The resulting delay won't exceed {@link #getMaxExpiry()}.
|
||||
*
|
||||
* @since 4.3
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public class ExponentialBackOffSchedulingStrategy implements SchedulingStrategy {
|
||||
|
||||
public static final long DEFAULT_BACK_OFF_RATE = 10;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Commons scheduling strategy implementations.
|
||||
*/
|
||||
package org.apache.hc.client5.http.impl.schedule;
|
|
@ -34,6 +34,13 @@ import org.apache.hc.core5.annotation.Contract;
|
|||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* Concurrent map of integer counts.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @param <T> identifier used as a map key
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.SAFE)
|
||||
public final class ConcurrentCountMap<T> {
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http.schedule;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
|
||||
/**
|
||||
|
@ -33,6 +35,7 @@ import org.apache.hc.core5.util.TimeValue;
|
|||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface SchedulingStrategy {
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Scheduling strategies used by HTTP cache implementations.
|
||||
*/
|
||||
package org.apache.hc.client5.http.schedule;
|
|
@ -32,6 +32,11 @@ import org.apache.hc.core5.concurrent.BasicFuture;
|
|||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
|
||||
|
||||
/**
|
||||
* Asynchronous executor for {@link Request}s.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public class Async {
|
||||
|
||||
private Executor executor;
|
||||
|
|
|
@ -35,7 +35,9 @@ import org.apache.hc.core5.http.ContentType;
|
|||
|
||||
/**
|
||||
* This class represents arbitrary content of a specific type that can be consumed
|
||||
* multiple times and requires no explicit deallocation.
|
||||
* multiple times and requires no explicit deallocation used by the fluent facade.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public class Content {
|
||||
|
||||
|
|
|
@ -47,10 +47,12 @@ import org.apache.hc.core5.http.HttpHost;
|
|||
import org.apache.hc.core5.util.TimeValue;
|
||||
|
||||
/**
|
||||
* An Executor for fluent requests.
|
||||
* Executor for {@link Request}s.
|
||||
* <p>
|
||||
* A connection pool with maximum 100 connections per route and
|
||||
* a total maximum of 200 connections is used internally.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public class Executor {
|
||||
|
||||
|
|
|
@ -32,6 +32,11 @@ import java.util.List;
|
|||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair;
|
||||
|
||||
/**
|
||||
* HTTP form used by the fluent facade.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public class Form {
|
||||
|
||||
private final List<NameValuePair> params;
|
||||
|
|
|
@ -63,6 +63,11 @@ import org.apache.hc.core5.http.io.entity.InputStreamEntity;
|
|||
import org.apache.hc.core5.net.URLEncodedUtils;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
/**
|
||||
* HTTP request used by the fluent facade.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public class Request {
|
||||
|
||||
public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
|
||||
|
|
|
@ -43,6 +43,11 @@ import org.apache.hc.core5.http.io.HttpClientResponseHandler;
|
|||
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
|
||||
/**
|
||||
* HTTP response used by the fluent facade.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public class Response {
|
||||
|
||||
private final ClassicHttpResponse response;
|
||||
|
|
|
@ -31,19 +31,18 @@ import org.apache.hc.client5.http.auth.AuthScheme;
|
|||
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
|
||||
import org.apache.hc.client5.http.auth.AuthSchemes;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.Experimental;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* {@link AuthSchemeProvider} implementation that creates and initializes
|
||||
* {@link WindowsNegotiateScheme} using JNA to implement NTLM
|
||||
* <p>
|
||||
* EXPERIMENTAL
|
||||
* </p>
|
||||
*
|
||||
* @since 4.4
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
@Experimental
|
||||
public class WindowsNTLMSchemeFactory implements AuthSchemeProvider {
|
||||
|
||||
private final String servicePrincipalName;
|
||||
|
|
|
@ -32,13 +32,14 @@ import org.apache.commons.codec.binary.Base64;
|
|||
import org.apache.hc.client5.http.RouteInfo;
|
||||
import org.apache.hc.client5.http.auth.AuthChallenge;
|
||||
import org.apache.hc.client5.http.auth.AuthScheme;
|
||||
import org.apache.hc.client5.http.auth.AuthSchemes;
|
||||
import org.apache.hc.client5.http.auth.AuthenticationException;
|
||||
import org.apache.hc.client5.http.auth.BasicUserPrincipal;
|
||||
import org.apache.hc.client5.http.auth.ChallengeType;
|
||||
import org.apache.hc.client5.http.auth.CredentialsProvider;
|
||||
import org.apache.hc.client5.http.auth.MalformedChallengeException;
|
||||
import org.apache.hc.client5.http.auth.AuthSchemes;
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||
import org.apache.hc.core5.annotation.Experimental;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
@ -63,12 +64,10 @@ import com.sun.jna.ptr.IntByReference;
|
|||
* <p>
|
||||
* This will delegate negotiation to the windows machine.
|
||||
* </p>
|
||||
* <p>
|
||||
* EXPERIMENTAL
|
||||
* </p>
|
||||
*
|
||||
* @since 4.4
|
||||
*/
|
||||
@Experimental
|
||||
public class WindowsNegotiateScheme implements AuthScheme {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
|
|
@ -31,19 +31,18 @@ import org.apache.hc.client5.http.auth.AuthScheme;
|
|||
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
|
||||
import org.apache.hc.client5.http.auth.AuthSchemes;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.Experimental;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* {@link AuthSchemeProvider} implementation that creates and initializes
|
||||
* {@link WindowsNegotiateScheme} using JNA to Negotiate credentials
|
||||
* <p>
|
||||
* EXPERIMENTAL
|
||||
* </p>
|
||||
*
|
||||
* @since 4.4
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
@Experimental
|
||||
public class WindowsNegotiateSchemeFactory implements AuthSchemeProvider {
|
||||
|
||||
private final String servicePrincipalName;
|
||||
|
|
|
@ -30,13 +30,13 @@ import java.io.IOException;
|
|||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.FutureRequestExecutionService;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpRequestFutureTask;
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
|
||||
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||
|
@ -70,7 +70,7 @@ public class ClientWithRequestFuture {
|
|||
|
||||
// Simple request ...
|
||||
final HttpGet request1 = new HttpGet("http://httpbin.org/get");
|
||||
final HttpRequestFutureTask<Boolean> futureTask1 = requestExecService.execute(request1,
|
||||
final FutureTask<Boolean> futureTask1 = requestExecService.execute(request1,
|
||||
HttpClientContext.create(), handler);
|
||||
final Boolean wasItOk1 = futureTask1.get();
|
||||
System.out.println("It was ok? " + wasItOk1);
|
||||
|
@ -78,7 +78,7 @@ public class ClientWithRequestFuture {
|
|||
// Cancel a request
|
||||
try {
|
||||
final HttpGet request2 = new HttpGet("http://httpbin.org/get");
|
||||
final HttpRequestFutureTask<Boolean> futureTask2 = requestExecService.execute(request2,
|
||||
final FutureTask<Boolean> futureTask2 = requestExecService.execute(request2,
|
||||
HttpClientContext.create(), handler);
|
||||
futureTask2.cancel(true);
|
||||
final Boolean wasItOk2 = futureTask2.get();
|
||||
|
@ -89,7 +89,7 @@ public class ClientWithRequestFuture {
|
|||
|
||||
// Request with a timeout
|
||||
final HttpGet request3 = new HttpGet("http://httpbin.org/get");
|
||||
final HttpRequestFutureTask<Boolean> futureTask3 = requestExecService.execute(request3,
|
||||
final FutureTask<Boolean> futureTask3 = requestExecService.execute(request3,
|
||||
HttpClientContext.create(), handler);
|
||||
final Boolean wasItOk3 = futureTask3.get(10, TimeUnit.SECONDS);
|
||||
System.out.println("It was ok? " + wasItOk3);
|
||||
|
@ -115,7 +115,7 @@ public class ClientWithRequestFuture {
|
|||
final HttpGet request4 = new HttpGet("http://httpbin.org/get");
|
||||
// using a null HttpContext here since it is optional
|
||||
// the callback will be called when the task completes, fails, or is cancelled
|
||||
final HttpRequestFutureTask<Boolean> futureTask4 = requestExecService.execute(request4,
|
||||
final FutureTask<Boolean> futureTask4 = requestExecService.execute(request4,
|
||||
HttpClientContext.create(), handler, callback);
|
||||
final Boolean wasItOk4 = futureTask4.get(10, TimeUnit.SECONDS);
|
||||
System.out.println("It was ok? " + wasItOk4);
|
||||
|
|
|
@ -33,6 +33,8 @@ import java.util.Map;
|
|||
import org.apache.hc.client5.http.auth.AuthChallenge;
|
||||
import org.apache.hc.client5.http.auth.AuthScheme;
|
||||
import org.apache.hc.client5.http.auth.ChallengeType;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
|
@ -44,6 +46,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface AuthenticationStrategy {
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,7 +29,6 @@ package org.apache.hc.client5.http;
|
|||
/**
|
||||
* Signals a circular redirect
|
||||
*
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CircularRedirectException extends RedirectException {
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.apache.hc.core5.net.NamedEndpoint;
|
|||
* A timeout while connecting to an HTTP server or waiting for an
|
||||
* available connection from an HttpConnectionManager.
|
||||
*
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ConnectTimeoutException extends InterruptedIOException {
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
|
@ -40,6 +42,7 @@ import org.apache.hc.core5.util.TimeValue;
|
|||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface ConnectionKeepAliveStrategy {
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,12 +29,16 @@ package org.apache.hc.client5.http;
|
|||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
|
||||
/**
|
||||
* Users may implement this interface to override the normal DNS lookup offered
|
||||
* by the OS.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface DnsResolver {
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,8 @@ package org.apache.hc.client5.http;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
|
@ -42,6 +44,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface HttpRequestRetryHandler {
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.apache.hc.core5.util.Args;
|
|||
import org.apache.hc.core5.util.LangUtils;
|
||||
|
||||
/**
|
||||
* The route for a request.
|
||||
* Connection route definition for HTTP requests.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.apache.hc.core5.http.ProtocolException;
|
|||
/**
|
||||
* Signals violation of HTTP specification caused by an invalid redirect
|
||||
*
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class RedirectException extends ProtocolException {
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.net.InetAddress;
|
|||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
||||
/**
|
||||
* Read-only interface for route information.
|
||||
* Connection route information.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
||||
/**
|
||||
|
@ -33,6 +35,7 @@ import org.apache.hc.core5.http.HttpHost;
|
|||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface SchemePortResolver {
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
package org.apache.hc.client5.http;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
|
@ -37,6 +39,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface ServiceUnavailableRetryStrategy {
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,11 @@ package org.apache.hc.client5.http;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Common HTTP methods defined by the HTTP spec.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public enum StandardMethods {
|
||||
|
||||
GET(true, true),
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
package org.apache.hc.client5.http;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
|
@ -42,6 +44,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface UserTokenHandler {
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,14 +33,43 @@ import org.apache.hc.core5.http.HttpException;
|
|||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.nio.AsyncDataConsumer;
|
||||
|
||||
/**
|
||||
* AsyncExecCallback methods represent response processing events
|
||||
* in the client side request execution chain.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface AsyncExecCallback {
|
||||
|
||||
/**
|
||||
* Triggered to signal receipt of a response message head sent by the server
|
||||
* in response to the request being executed.
|
||||
*
|
||||
* @param response the response message head.
|
||||
* @param entityDetails the response entity details or {@code null} if the response
|
||||
* does not enclose an entity.
|
||||
* @return the data consumer to be used for processing of incoming response message body.
|
||||
*/
|
||||
AsyncDataConsumer handleResponse(
|
||||
HttpResponse response,
|
||||
EntityDetails entityDetails) throws HttpException, IOException;
|
||||
|
||||
/**
|
||||
* Triggered to signal completion of the message exchange.
|
||||
* <p>
|
||||
* Implementations of this message are expected to perform resource deallocation
|
||||
* allocated in the course of the request execution and response processing.
|
||||
* </p>
|
||||
*/
|
||||
void completed();
|
||||
|
||||
/**
|
||||
* Triggered to signal a failure occurred during the message exchange.
|
||||
* <p>
|
||||
* Implementations of this message are expected to perform resource deallocation
|
||||
* allocated in the course of the request execution and response processing.
|
||||
* </p>
|
||||
*/
|
||||
void failed(Exception cause);
|
||||
|
||||
}
|
||||
|
|
|
@ -30,14 +30,27 @@ import java.io.IOException;
|
|||
|
||||
import org.apache.hc.client5.http.HttpRoute;
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.concurrent.CancellableDependency;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* Represents a single element in the client side asynchronous request execution chain.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface AsyncExecChain {
|
||||
|
||||
/**
|
||||
* Request execution scope that includes the unique message exchange ID,
|
||||
* the connection route, the original request message, the execution
|
||||
* context and the internal execution runtime.
|
||||
*/
|
||||
final class Scope {
|
||||
|
||||
public final String exchangeId;
|
||||
|
@ -64,6 +77,15 @@ public interface AsyncExecChain {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Proceeds to the next element in the request execution chain.
|
||||
*
|
||||
* @param request the actual request.
|
||||
* @param entityProducer the request entity producer or {@code null} if the request
|
||||
* does not enclose an entity.
|
||||
* @param scope the execution scope .
|
||||
* @param asyncExecCallback the execution callback.
|
||||
*/
|
||||
void proceed(
|
||||
HttpRequest request,
|
||||
AsyncEntityProducer entityProducer,
|
||||
|
|
|
@ -28,12 +28,36 @@ package org.apache.hc.client5.http.async;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.hc.core5.annotation.Contract;
|
||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
|
||||
|
||||
/**
|
||||
* Abstract request execution handler in an asynchronous client side request execution
|
||||
* chain. Handlers can either be a decorator around another element that implements
|
||||
* a cross cutting aspect or a self-contained executor capable of producing a response
|
||||
* for the given request.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||
public interface AsyncExecChainHandler {
|
||||
|
||||
/**
|
||||
* Executes the actual HTTP request. The handler can choose to return
|
||||
* a response message immediately inside the call or asynchronously
|
||||
* at some later point or delegate request execution to the next
|
||||
* element in the execution chain.
|
||||
*
|
||||
* @param request the actual request.
|
||||
* @param entityProducer the request entity producer or {@code null} if the request
|
||||
* does not enclose an entity.
|
||||
* @param scope the execution scope .
|
||||
* @param chain the next element in the request execution chain.
|
||||
* @param asyncExecCallback the execution callback.
|
||||
*/
|
||||
void execute(
|
||||
HttpRequest request,
|
||||
AsyncEntityProducer entityProducer,
|
||||
|
|
|
@ -41,45 +41,111 @@ import org.apache.hc.core5.util.TimeValue;
|
|||
* <p>
|
||||
* This interface is considered internal and generally ought not be used or accessed
|
||||
* by custom request exec handlers.
|
||||
* </p>
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Internal
|
||||
public interface AsyncExecRuntime {
|
||||
|
||||
boolean isConnectionAcquired();
|
||||
/**
|
||||
* Determines of a connection endpoint has been acquired.
|
||||
*
|
||||
* @return {@code true} if an endpoint has been acquired, {@code false} otherwise.
|
||||
*/
|
||||
boolean isEndpointAcquired();
|
||||
|
||||
Cancellable acquireConnection(
|
||||
/**
|
||||
* Initiates operation to acquire a connection endpoint. Endpoints can leased from a pool
|
||||
* or unconnected new endpoint can be created.
|
||||
*
|
||||
* @param route the connection route.
|
||||
* @param state the expected connection state. May be {@code null} if connection
|
||||
* can be state-less or its state is irrelevant.
|
||||
* @param context the execution context.
|
||||
* @param callback the result callback.
|
||||
* @return handle that can be used to cancel the operation.
|
||||
*/
|
||||
Cancellable acquireEndpoint(
|
||||
HttpRoute route,
|
||||
Object state,
|
||||
HttpClientContext clientContext,
|
||||
HttpClientContext context,
|
||||
FutureCallback<AsyncExecRuntime> callback);
|
||||
|
||||
void releaseConnection();
|
||||
/**
|
||||
* Releases the acquired endpoint potentially making it available for re-use.
|
||||
*/
|
||||
void releaseEndpoint();
|
||||
|
||||
void discardConnection();
|
||||
/**
|
||||
* Shuts down and discards the acquired endpoint.
|
||||
*/
|
||||
void discardEndpoint();
|
||||
|
||||
boolean validateConnection();
|
||||
/**
|
||||
* Determines of there the endpoint is connected to the initial hop (connection target
|
||||
* in case of a direct route or to the first proxy hop in case of a route via a proxy
|
||||
* or multiple proxies).
|
||||
*
|
||||
* @return {@code true} if the endpoint is connected, {@code false} otherwise.
|
||||
*/
|
||||
boolean isEndpointConnected();
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
Cancellable connect(
|
||||
HttpClientContext clientContext,
|
||||
/**
|
||||
* Initiates operation to connect the local endpoint to the initial hop (connection
|
||||
* target in case of a direct route or to the first proxy hop in case of a route
|
||||
* via a proxy or multiple proxies).
|
||||
*
|
||||
* @param context the execution context.
|
||||
* @param callback the result callback.
|
||||
* @return handle that can be used to cancel the operation.
|
||||
*/
|
||||
Cancellable connectEndpoint(
|
||||
HttpClientContext context,
|
||||
FutureCallback<AsyncExecRuntime> callback);
|
||||
|
||||
/**
|
||||
* Upgrades transport security of the active connection by using the TLS security protocol.
|
||||
*
|
||||
* @param context the execution context.
|
||||
*/
|
||||
void upgradeTls(HttpClientContext context);
|
||||
|
||||
/**
|
||||
* Validates the connection making sure it can be used to execute requests.
|
||||
*
|
||||
* @return {@code true} if the connection is valid, {@code false}.
|
||||
*/
|
||||
boolean validateConnection();
|
||||
|
||||
/**
|
||||
* Initiates a message exchange using the given handler.
|
||||
*
|
||||
* @param exchangeHandler the client message handler.
|
||||
* @param context the execution context.
|
||||
*/
|
||||
Cancellable execute(
|
||||
AsyncClientExchangeHandler exchangeHandler,
|
||||
HttpClientContext context);
|
||||
|
||||
void markConnectionReusable(Object state, TimeValue duration);
|
||||
/**
|
||||
* Marks the connection as potentially re-usable for the given period of time
|
||||
* and also marks it as stateful if the state representation is given.
|
||||
* @param state the connection state representation or {@code null} if stateless.
|
||||
* @param validityTime the period of time this connection is valid for.
|
||||
*/
|
||||
void markConnectionReusable(Object state, TimeValue validityTime);
|
||||
|
||||
/**
|
||||
* Marks the connection as non re-usable.
|
||||
*/
|
||||
void markConnectionNonReusable();
|
||||
|
||||
/**
|
||||
* Forks this runtime for parallel execution.
|
||||
*
|
||||
* @return another runtime with the same configuration.
|
||||
*/
|
||||
AsyncExecRuntime fork();
|
||||
|
||||
}
|
||||
|
|
|
@ -39,8 +39,20 @@ import org.apache.hc.core5.http.nio.AsyncPushConsumer;
|
|||
import org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* Abstract push response consumer that processes response body data as an octet stream.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public abstract class AbstractBinPushConsumer extends AbstractBinDataConsumer implements AsyncPushConsumer {
|
||||
|
||||
/**
|
||||
* Triggered to signal the beginning of response processing.
|
||||
*
|
||||
* @param response the response message head
|
||||
* @param contentType the content type of the response body,
|
||||
* or {@code null} if the response does not enclose a response entity.
|
||||
*/
|
||||
protected abstract void start(HttpRequest promise, HttpResponse response, ContentType contentType) throws HttpException, IOException;
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +68,7 @@ public abstract class AbstractBinPushConsumer extends AbstractBinDataConsumer im
|
|||
} catch (final UnsupportedCharsetException ex) {
|
||||
throw new UnsupportedEncodingException(ex.getMessage());
|
||||
}
|
||||
start(promise, response, contentType);
|
||||
start(promise, response, contentType != null ? contentType : ContentType.DEFAULT_BINARY);
|
||||
} else {
|
||||
start(promise, response, null);
|
||||
completed();
|
||||
|
|
|
@ -39,12 +39,31 @@ import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
|
|||
import org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* Abstract response consumer that processes response body data as an octet stream.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @param <T> response message representation.
|
||||
*/
|
||||
public abstract class AbstractBinResponseConsumer<T> extends AbstractBinDataConsumer implements AsyncResponseConsumer<T> {
|
||||
|
||||
private volatile FutureCallback<T> resultCallback;
|
||||
|
||||
/**
|
||||
* Triggered to signal the beginning of response processing.
|
||||
*
|
||||
* @param response the response message head
|
||||
* @param contentType the content type of the response body,
|
||||
* or {@code null} if the response does not enclose a response entity.
|
||||
*/
|
||||
protected abstract void start(HttpResponse response, ContentType contentType) throws HttpException, IOException;
|
||||
|
||||
/**
|
||||
* Triggered to generate object that represents a result of response message processing.
|
||||
*
|
||||
* @return the result of response processing.
|
||||
*/
|
||||
protected abstract T buildResult();
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +82,7 @@ public abstract class AbstractBinResponseConsumer<T> extends AbstractBinDataCons
|
|||
if (entityDetails != null) {
|
||||
try {
|
||||
final ContentType contentType = ContentType.parse(entityDetails.getContentType());
|
||||
start(response, contentType);
|
||||
start(response, contentType != null ? contentType : ContentType.DEFAULT_BINARY);
|
||||
} catch (final UnsupportedCharsetException ex) {
|
||||
throw new UnsupportedEncodingException(ex.getMessage());
|
||||
}
|
||||
|
|
|
@ -41,8 +41,20 @@ import org.apache.hc.core5.http.nio.AsyncPushConsumer;
|
|||
import org.apache.hc.core5.http.nio.entity.AbstractCharDataConsumer;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* Abstract push response consumer that processes response body data as a character stream.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public abstract class AbstractCharPushConsumer extends AbstractCharDataConsumer implements AsyncPushConsumer {
|
||||
|
||||
/**
|
||||
* Triggered to signal the beginning of data processing.
|
||||
*
|
||||
* @param response the response message head
|
||||
* @param contentType the content type of the response body,
|
||||
* or {@code null} if the response does not enclose a response entity.
|
||||
*/
|
||||
protected abstract void start(HttpRequest promise, HttpResponse response, ContentType contentType) throws HttpException, IOException;
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +75,7 @@ public abstract class AbstractCharPushConsumer extends AbstractCharDataConsumer
|
|||
charset = StandardCharsets.US_ASCII;
|
||||
}
|
||||
setCharset(charset);
|
||||
start(promise, response, contentType);
|
||||
start(promise, response, contentType != null ? contentType : ContentType.DEFAULT_TEXT);
|
||||
} else {
|
||||
start(promise, response, null);
|
||||
completed();
|
||||
|
|
|
@ -41,12 +41,31 @@ import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
|
|||
import org.apache.hc.core5.http.nio.entity.AbstractCharDataConsumer;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* Abstract response consumer that processes response body data as a character stream.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @param <T> response message representation.
|
||||
*/
|
||||
public abstract class AbstractCharResponseConsumer<T> extends AbstractCharDataConsumer implements AsyncResponseConsumer<T> {
|
||||
|
||||
private volatile FutureCallback<T> resultCallback;
|
||||
|
||||
/**
|
||||
* Triggered to signal the beginning of data processing.
|
||||
*
|
||||
* @param response the response message head
|
||||
* @param contentType the content type of the response body,
|
||||
* or {@code null} if the response does not enclose a response entity.
|
||||
*/
|
||||
protected abstract void start(HttpResponse response, ContentType contentType) throws HttpException, IOException;
|
||||
|
||||
/**
|
||||
* Triggered to generate object that represents a result of response message processing.
|
||||
*
|
||||
* @return the result of response processing.
|
||||
*/
|
||||
protected abstract T buildResult() throws IOException;
|
||||
|
||||
@Override
|
||||
|
@ -74,7 +93,7 @@ public abstract class AbstractCharResponseConsumer<T> extends AbstractCharDataCo
|
|||
charset = StandardCharsets.US_ASCII;
|
||||
}
|
||||
setCharset(charset);
|
||||
start(response, contentType);
|
||||
start(response, contentType != null ? contentType : ContentType.DEFAULT_TEXT);
|
||||
} else {
|
||||
start(response, null);
|
||||
completed();
|
||||
|
|
|
@ -63,6 +63,7 @@ import org.apache.hc.core5.util.TextUtils;
|
|||
* {@link #setEntity(AsyncEntityProducer)} or it is not an entity enclosing method
|
||||
* (such as POST or PUT), parameters will be added to the query component of the request URI.
|
||||
* Otherwise, parameters will be added as a URL encoded entity.
|
||||
* </p>
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
|
|
|
@ -34,6 +34,11 @@ import org.apache.hc.client5.http.config.RequestConfig;
|
|||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
|
||||
/**
|
||||
* HTTP request message with a custom configuration.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public class ConfigurableHttpRequest extends BasicHttpRequest implements Configurable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -34,9 +34,9 @@ import org.apache.hc.core5.http.HttpHost;
|
|||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
|
||||
/**
|
||||
* HTTP methods defined in RFC2616.
|
||||
* Common HTTP methods using {@link BasicHttpRequest} as a HTTP request message representation.
|
||||
*
|
||||
* @since 5.0-beta2
|
||||
* @since 5.0
|
||||
*/
|
||||
public enum HttpRequests {
|
||||
|
||||
|
|
|
@ -33,6 +33,11 @@ import java.nio.charset.StandardCharsets;
|
|||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* Message body representation as a simple text string or an array of bytes.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public final class SimpleBody {
|
||||
|
||||
private final byte[] bodyAsBytes;
|
||||
|
|
|
@ -37,6 +37,13 @@ import org.apache.hc.core5.http.HttpHost;
|
|||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* HTTP request that can enclose a body represented as a simple text string or an array of bytes.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @see SimpleBody
|
||||
*/
|
||||
public final class SimpleHttpRequest extends ConfigurableHttpRequest {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -33,9 +33,9 @@ import org.apache.hc.client5.http.StandardMethods;
|
|||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
||||
/**
|
||||
* HTTP methods defined in RFC2616.
|
||||
* Common HTTP methods using {@link SimpleHttpRequest} as a HTTP request message representation.
|
||||
*
|
||||
* @since 5.0-beta2
|
||||
* @since 5.0
|
||||
*/
|
||||
public enum SimpleHttpRequests {
|
||||
|
||||
|
|
|
@ -35,6 +35,13 @@ import org.apache.hc.core5.http.HttpResponse;
|
|||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* HTTP response that can enclose a body represented as a simple text string or an array of bytes.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @see SimpleBody
|
||||
*/
|
||||
public final class SimpleHttpResponse extends BasicHttpResponse {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -32,6 +32,14 @@ import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityProducer;
|
|||
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* HTTP request producer that generates message data stream events based
|
||||
* on content of a {@link SimpleHttpRequest} instance.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @see SimpleBody
|
||||
*/
|
||||
public final class SimpleRequestProducer extends BasicRequestProducer {
|
||||
|
||||
SimpleRequestProducer(final SimpleHttpRequest request, final AsyncEntityProducer entityProducer) {
|
||||
|
|
|
@ -36,6 +36,14 @@ import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityConsumer;
|
|||
import org.apache.hc.core5.http.nio.support.AbstractAsyncResponseConsumer;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* HTTP response consumer that generates a {@link SimpleHttpResponse} instance based on events
|
||||
* of an incoming data stream.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @see SimpleBody
|
||||
*/
|
||||
public final class SimpleResponseConsumer extends AbstractAsyncResponseConsumer<SimpleHttpResponse, byte[]> {
|
||||
|
||||
SimpleResponseConsumer(final AsyncEntityConsumer<byte[]> entityConsumer) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Common HTTP methods and message handlers for the asynchronous I/O model.
|
||||
*/
|
||||
package org.apache.hc.client5.http.async.methods;
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTTP client APIs based on the asynchronous, event driven I/O model.
|
||||
*/
|
||||
package org.apache.hc.client5.http.async;
|
|
@ -29,9 +29,8 @@ package org.apache.hc.client5.http.auth;
|
|||
import org.apache.hc.core5.http.HttpHost;
|
||||
|
||||
/**
|
||||
* Abstract {@link AuthScheme} cache. Initialized {@link AuthScheme} objects
|
||||
* from this cache can be used to preemptively authenticate against known
|
||||
* hosts.
|
||||
* This interface represents an cache of {@link AuthScheme} state information
|
||||
* that can be re-used for preemptive authentication by subsequent requests.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
|
|
|
@ -42,11 +42,14 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
* authentication scheme and they may carry a particular security context and be authorized
|
||||
* for a particular user identity. It is important that such schemes always provide
|
||||
* the user identity they represent through the {@link #getPrincipal()} method.
|
||||
* </p>
|
||||
* <p>
|
||||
* Authentication scheme are expected to transition through a series of standard phases or
|
||||
* states.
|
||||
* </p>
|
||||
* <p>
|
||||
* Authentication scheme starts off its life cycle with no context and no specific state.
|
||||
* </p>
|
||||
* <p>
|
||||
* The {@link #processChallenge(AuthChallenge, HttpContext)} method is called to
|
||||
* process an authentication challenge received either from the target server or a proxy.
|
||||
|
@ -55,6 +58,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
* challenge details. Standard authentication schemes are expected to provide a realm
|
||||
* attribute in the challenge. {@link #getRealm()} can be called to obtain an identifier
|
||||
* of the realm that requires authorization.
|
||||
* </p>
|
||||
* <p>
|
||||
* Once the challenge has been fully processed the {@link #isResponseReady(HttpHost,
|
||||
* CredentialsProvider, HttpContext)} method to determine whether the scheme is capable of
|
||||
|
@ -62,15 +66,18 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
* required to do so. If this method returns {@code false} the authentication is considered
|
||||
* to be in FAILED state and no authorization response. Otherwise the scheme is considered
|
||||
* to be in RESPONSE_READY state.
|
||||
* </p>
|
||||
* <p>
|
||||
* Once the scheme is ready to respond to the challenge the {@link #generateAuthResponse(
|
||||
* HttpHost, HttpRequest, HttpContext)} method to generate a response token, which will
|
||||
* be sent to the opposite endpoint in the subsequent request message.
|
||||
* </p>
|
||||
* <p>
|
||||
* Certain non-standard schemes may involve multiple challenge / response exchanges to
|
||||
* fully establish a shared context and complete the authentication process. Authentication
|
||||
* schemes are required to return {@code true} {@link #isChallengeComplete()} once the
|
||||
* handshake is considered complete.
|
||||
* </p>
|
||||
* <p>
|
||||
* The authentication scheme is considered successfully completed and in SUCCESS state
|
||||
* if the opposite endpoint accepts the request message containing the authorization
|
||||
|
@ -78,6 +85,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
* If the opposite endpoint sends status code 401 or 407 in response to a request message
|
||||
* containing the terminal authorization response, the scheme is considered unsuccessful
|
||||
* and in FAILED state.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue