# HG changeset patch # User chegar # Date 1518123515 0 # Node ID 15dc43936d39f64cbd88e600aa84c6d2d3694560 # Parent 881f0ecb513f91bc5a3f3735198bc0ed079603e7 http-client-branch: javadoc refresh and minor fixes diff -r 881f0ecb513f -r 15dc43936d39 make/common/Modules.gmk --- a/make/common/Modules.gmk Wed Feb 07 22:49:25 2018 +0000 +++ b/make/common/Modules.gmk Thu Feb 08 20:58:35 2018 +0000 @@ -143,7 +143,7 @@ # DOCS_MODULES defines the root modules for javadoc generation. # All of their `require transitive` modules directly and indirectly will be included. DOCS_MODULES += \ - java.net.http\ + java.net.http \ java.se.ee \ java.smartcardio \ jdk.accessibility \ diff -r 881f0ecb513f -r 15dc43936d39 src/java.net.http/share/classes/java/net/http/HttpClient.java --- a/src/java.net.http/share/classes/java/net/http/HttpClient.java Wed Feb 07 22:49:25 2018 +0000 +++ b/src/java.net.http/share/classes/java/net/http/HttpClient.java Thu Feb 08 20:58:35 2018 +0000 @@ -31,6 +31,9 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.ProxySelector; +import java.net.URLPermission; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; @@ -45,37 +48,81 @@ /** * An HTTP Client. * - *
An {@code HttpClient} can be used to send requests and retrieve their - * responses. An {@code HttpClient} is created through a {@link - * HttpClient#newBuilder() builder}. The builder can be used to configure - * per-client state, like: the preferred protocol version ( HTTP/1.1 or HTTP/2 ), - * whether to follow redirects, a proxy, an authenticator, etc. Once built, an - * {@code HttpClient} is immutable, and can be used to send multiple requests. + *
An {@code HttpClient} can be used to send {@linkplain HttpRequest + * requests} and retrieve their {@linkplain HttpResponse responses}. An {@code + * HttpClient} is created through a {@link HttpClient#newBuilder() builder}. The + * builder can be used to configure per-client state, like: the preferred + * protocol version ( HTTP/1.1 or HTTP/2 ), whether to follow redirects, a + * proxy, an authenticator, etc. Once built, an {@code HttpClient} is immutable, + * and can be used to send multiple requests. * *
An {@code HttpClient} provides configuration information, and resource * sharing, for all requests send through it. * - *
For Example: + *
Requests can be made either synchronously or asynchronously: + *
A {@linkplain BodyHandler BodyHandler} must be supplied for each {@code
+ * HttpRequest} sent. The {@code BodyHandler} determines how to handle the
+ * response body, if any. Once an {@linkplain HttpResponse} is received, the
+ * headers, response code, and body (typically) are available. Whether the
+ * response body bytes has been read or not depends on the type {@code Synchronous Example
* Asynchronous Example
+ * See {@link HttpRequest} for further examples of usage of this API.
+ * If a security manager is present then security checks are performed by
+ * the HTTP Client's sending methods. An appropriate {@link URLPermission} is
+ * required to access the destination server, and proxy server if one has
+ * been configured. The form of the {@code URLPermission} required to access a
+ * proxy has a {@code method} parameter of {@code "CONNECT"} (for all kinds of
+ * proxying) and a {@code URL} string of the form {@code "socket://host:port"}
+ * where host and port specify the proxy's address.
+ *
+ * @implNote If an explicit {@linkplain HttpClient.Builder#executor(Executor)
+ * executor} has not been set for an {@code HttpClient}, and a security manager
+ * has been installed, then the default executor will execute asynchronous and
+ * dependent tasks in a context that is granted no permissions. Custom
+ * {@linkplain HttpRequest.BodyPublisher request body publishers}, {@linkplain
+ * HttpResponse.BodyHandler response body handlers}, {@linkplain
+ * HttpResponse.BodySubscriber response body subscribers}, and {@linkplain
+ * WebSocket.Listener WebSocket Listeners}, if executing operations that require
+ * privileges, should do so within an appropriate {@linkplain
+ * AccessController#doPrivileged(PrivilegedAction) privileged context}.
*
* @since 11
*/
@@ -87,7 +134,7 @@
protected HttpClient() {}
/**
- * Returns a new HttpClient with default settings.
+ * Returns a new {@code HttpClient} with default settings.
*
* Equivalent to {@code newBuilder().build()}.
*
@@ -113,14 +160,14 @@
/**
* Creates a new {@code HttpClient} builder.
*
- * @return a {@code HttpClient.Builder}
+ * @return an {@code HttpClient.Builder}
*/
public static Builder newBuilder() {
return new HttpClientBuilderImpl();
}
/**
- * A builder of immutable {@link HttpClient}s.
+ * A builder of {@link HttpClient}s.
*
* Builders are created by invoking {@linkplain HttpClient#newBuilder()
* newBuilder}. Each of the setter methods modifies the state of the builder
@@ -254,20 +301,20 @@
/**
* Sets a {@link java.net.ProxySelector}.
*
- * @apiNote {@link ProxySelector#of(InetSocketAddress)}
+ * @apiNote {@link ProxySelector#of(InetSocketAddress) ProxySelector::of}
* provides a {@code ProxySelector} which uses a single proxy for all
* requests. The system-wide proxy selector can be retrieved by
* {@link ProxySelector#getDefault()}.
*
* @implNote
- * If this method is not invoked prior to {@linkplain #build()
- * building}, then newly built clients will use the {@linkplain
- * ProxySelector#getDefault() default proxy selector}, which
- * is normally adequate for client applications. This default
- * behavior can be turned off by supplying an explicit proxy
- * selector to this method, such as {@link #NO_PROXY} or one
- * returned by {@link ProxySelector#of(InetSocketAddress)},
- * before calling {@link #build()}.
+ * If this method is not invoked prior to {@linkplain #build() building},
+ * then newly built clients will use the {@linkplain
+ * ProxySelector#getDefault() default proxy selector}, which is usually
+ * adequate for client applications. This default behavior can be turned
+ * off by supplying an explicit proxy selector to this method, such as
+ * {@link #NO_PROXY} or one returned by {@linkplain
+ * ProxySelector#of(InetSocketAddress) ProxySelector::of}, before
+ * {@linkplain #build() building}.
*
* @param selector the ProxySelector
* @return this builder
@@ -442,27 +489,27 @@
* handler ).
*
* @param Equivalent to {@code sendAsync(request, responseBodyHandler, null)}.
+ * Equivalent to: {@code sendAsync(request, responseBodyHandler, null)}.
*
* @param Example
- * Finer control over the WebSocket Opening Handshake can be achieved
* by using a custom {@code HttpClient}.
*
* Example
- * A {@code WebSocket.Builder} returned from this method is not safe for
* use by multiple threads without external synchronization.
diff -r 881f0ecb513f -r 15dc43936d39 src/java.net.http/share/classes/java/net/http/HttpRequest.java
--- a/src/java.net.http/share/classes/java/net/http/HttpRequest.java Wed Feb 07 22:49:25 2018 +0000
+++ b/src/java.net.http/share/classes/java/net/http/HttpRequest.java Thu Feb 08 20:58:35 2018 +0000
@@ -52,60 +52,33 @@
/**
* An HTTP request.
*
- * An {@code HttpRequest} instance is built through a {@code HttpRequest}
+ * An {@code HttpRequest} instance is built through an {@code HttpRequest}
* {@linkplain HttpRequest.Builder builder}. An {@code HttpRequest} builder
- * is obtained from one of the {@link HttpRequest#newBuilder(URI) newBuilder}
+ * is obtained from one of the {@linkplain HttpRequest#newBuilder(URI) newBuilder}
* methods. A request's {@linkplain URI}, headers, and body can be set. Request
- * bodies are provided through a {@link BodyPublisher} object supplied to the
- * {@link Builder#DELETE(BodyPublisher) DELETE},
- * {@link Builder#POST(BodyPublisher) POST} or
- * {@link Builder#PUT(BodyPublisher) PUT} methods.
+ * bodies are provided through a {@linkplain BodyPublisher BodyPublisher}
+ * supplied to one of the {@linkplain Builder#DELETE(BodyPublisher) DELETE},
+ * {@linkplain Builder#POST(BodyPublisher) POST} or
+ * {@linkplain Builder#PUT(BodyPublisher) PUT} methods.
* Once all required parameters have been set in the builder, {@link
* Builder#build() build} will return the {@code HttpRequest}. Builders can be
* copied and modified many times in order to build multiple related requests
* that differ in some parameters.
*
- * Example HTTP interactions:
- * Example: GET request that prints the response body as a String
+ * The request is sent and the response obtained by invoking one of the
- * following methods in {@link HttpClient}.
- * Once a {@link HttpResponse} is received, the headers, response code,
- * and body (typically) are available. Whether the response body bytes has been
- * read or not depends on the type {@code Request bodies
+ * Request bodies
*
* Request bodies can be sent using one of the convenience request publisher
- * implementations, provided in {@link BodyPublisher}. Alternatively, a custom
- * Publisher implementation can be used.
+ * implementations, provided in {@linkplain BodyPublisher BodyPublisher}.
* Response bodies
- *
- * Responses bodies are handled at two levels. When sending the request,
- * a response {@linkplain BodyHandler body handler} is specified. This is a
- * function that will be called with the response status code and headers, once
- * they are received. This function must to return a {@link
- * HttpResponse.BodySubscriber}{@code Some of the pre-defined body handlers Blocking/asynchronous behavior and thread usage
- *
- * There are two styles of request sending: synchronous and
- * asynchronous. {@link HttpClient#send(HttpRequest, HttpResponse.BodyHandler) }
- * blocks the calling thread until the request has been sent and the response received.
- *
- * {@link HttpClient#sendAsync(HttpRequest, HttpResponse.BodyHandler)} is
- * asynchronous and returns immediately with a {@link CompletableFuture}<{@link
- * HttpResponse}> and when this object completes (possibly in a different
- * thread) the response has been received.
- *
- * Instances of {@code CompletableFuture} can be combined in different ways
- * to declare the dependencies among several asynchronous tasks, while allowing
- * for the maximum level of parallelism to be utilized.
- *
- * If a security manager is present then security checks are performed by
- * the HTTP Client's sending methods. An appropriate {@link URLPermission} is
- * required to access the destination server, and proxy server if one has
- * been configured. The {@code URLPermission} form used to access proxies uses a
- * method parameter of {@code "CONNECT"} (for all kinds of proxying) and a URL
- * string of the form {@code "socket://host:port"} where host and port specify
- * the proxy's address.
- *
- * In this implementation, if an explicit {@linkplain
- * HttpClient.Builder#executor(Executor) executor} has not been set for an
- * {@code HttpClient}, and a security manager has been installed, then the
- * default executor will execute asynchronous and dependent tasks in a context
- * that is granted no permissions. Custom {@linkplain HttpRequest.BodyPublisher
- * request body publishers}, {@linkplain HttpResponse.BodyHandler response body
- * handlers}, {@linkplain HttpResponse.BodySubscriber response body subscribers},
- * and {@linkplain WebSocket.Listener WebSocket Listeners}, if executing
- * operations that require privileges, should do so within an appropriate
- * {@linkplain AccessController#doPrivileged(PrivilegedAction) privileged context}.
- *
- * Examples
- * Asynchronous Example
- *
- * The above example will work asynchronously, if {@link HttpClient#sendAsync
- * (HttpRequest, HttpResponse.BodyHandler) sendAsync} is used instead of
- * {@link HttpClient#send(HttpRequest,HttpResponse.BodyHandler) send}
- * in which case the returned object is a {@link CompletableFuture}{@code Alternatively, a custom {@code BodyPublisher} implementation can be used.
*
* @since 11
*/
@@ -237,7 +103,7 @@
protected HttpRequest() {}
/**
- * A builder of {@linkplain HttpRequest HTTP Requests}.
+ * A builder of {@linkplain HttpRequest HTTP requests}.
*
* Instances of {@code HttpRequest.Builder} are created by calling {@link
* HttpRequest#newBuilder(URI)} or {@link HttpRequest#newBuilder()}.
@@ -245,16 +111,15 @@
* Each of the setter methods in this class modifies the state of the
* builder and returns this (ie. the same instance). The methods are
* not synchronized and should not be called from multiple threads without
- * external synchronization.
+ * external synchronization. The {@linkplain #build() build} method returns
+ * a new {@code HttpRequest} each time it is invoked. Once built an {@code
+ * HttpRequest} is immutable, and can be sent multiple times.
*
* Note, that not all request headers may be set by user code. Some are
* restricted for security reasons and others such as the headers relating
- * to authentication, redirection and cookie management are managed by
+ * to authentication, redirection and cookie management may be managed by
* specific APIs rather than through directly user set headers.
*
- * The {@linkplain #build() build} method returns a new {@code
- * HttpRequest} each time it is invoked.
- *
* @since 11
*/
public abstract static class Builder {
@@ -447,7 +312,7 @@
}
/**
- * Creates a {@code HttpRequest} builder.
+ * Creates an {@code HttpRequest} builder with the given URI.
*
* @param uri the request URI
* @return a new request builder
@@ -458,7 +323,7 @@
}
/**
- * Creates a {@code HttpRequest} builder.
+ * Creates an {@code HttpRequest} builder.
*
* @return a new request builder
*/
@@ -493,15 +358,15 @@
public abstract Optional The {@code BodyPublisher} class implements {@link Flow.Publisher
- * Flow.Publisher<ByteBuffer>} which means that a {@code BodyPublisher}
+ * The {@code BodyPublisher} interface extends {@link Flow.Publisher
+ * Flow.Publisher<ByteBuffer>}, which means that a {@code BodyPublisher}
* acts as a publisher of {@linkplain ByteBuffer byte buffers}.
*
- * The HTTP client implementation subscribes to the publisher in order
- * to receive the flow of outgoing data buffers. The normal semantics of
- * {@link Flow.Subscriber} and {@link Flow.Publisher} are implemented by the
- * library and are expected from publisher implementations. Each outgoing
- * request results in one {@code Subscriber} subscribing to the {@code
- * BodyPublisher} in order to provide the sequence of byte buffers
- * containing the request body.
- * Instances of {@code ByteBuffer} published by the publisher must be
- * allocated by the publisher, and must not be accessed after being handed
- * over to the library.
- * These subscriptions complete normally when the request is fully sent,
- * and can be canceled or terminated early through error. If a request
- * needs to be resent for any reason, then a new subscription is created
- * which is expected to generate the same data as before.
+ * When sending a request that contains a body, the HTTP Client
+ * subscribes to the request's {@code BodyPublisher} in order to receive the
+ * flow of outgoing request body data. The normal semantics of {@link
+ * Flow.Subscriber} and {@link Flow.Publisher} are implemented by the HTTP
+ * Client and are expected from {@code BodyPublisher} implementations. Each
+ * outgoing request results in one HTTP Client {@code Subscriber}
+ * subscribing to the {@code BodyPublisher} in order to provide the sequence
+ * of byte buffers containing the request body. Instances of {@code
+ * ByteBuffer} published by the publisher must be allocated by the
+ * publisher, and must not be accessed after being published to the HTTP
+ * Client. These subscriptions complete normally when the request body is
+ * fully sent, and can be canceled or terminated early through error. If a
+ * request needs to be resent for any reason, then a new subscription is
+ * created which is expected to generate the same data as before.
*
- * A publisher that reports a {@linkplain #contentLength() content
- * length} of {@code 0} may not be subscribed to by the HTTP client
- * implementation, as it has effectively no data to publish.
+ * A {@code BodyPublisher} that reports a {@linkplain #contentLength()
+ * content length} of {@code 0} may not be subscribed to by the HTTP Client,
+ * as it has effectively no data to publish.
*/
public interface BodyPublisher extends Flow.Publisher A {@code HttpResponse} is available when the response status code and
- * headers have been received, and typically after the response body has also
- * been received. This depends on the response body handler provided when
- * sending the request. In all cases, the response body handler is invoked
- * before the body is read. This gives applications an opportunity to decide
- * how to handle the body.
- *
- * Methods are provided in this class for accessing the response headers,
- * and response body.
- *
- * Response handlers and subscribers
+ * An HTTP response.
*
- * Response bodies are handled at two levels. Application code supplies a
- * response handler ({@link BodyHandler}) which may examine the response status
- * code and headers, and which then returns a {@link BodySubscriber} to actually
- * read (or discard) the body and convert it into some useful Java object type.
- * The handler can return one of the pre-defined subscriber types, or a custom
- * subscriber, or if the body is to be discarded it can call {@link
- * BodySubscriber#discard() discard} and return a subscriber which
- * discards the response body. Static implementations of both handlers and
- * subscribers are provided in {@linkplain BodyHandler BodyHandler} and
- * {@linkplain BodySubscriber BodySubscriber} respectively. In all cases, the
- * handler functions provided are convenience implementations which ignore the
- * supplied status code and headers and return the relevant pre-defined {@code
- * BodySubscriber}.
+ * An {@code HttpResponse} is not created directly, but rather returned as
+ * a result of sending an {@linkplain HttpRequest}. An {@code HttpResponse} is
+ * made available when the response status code and headers have been received,
+ * and typically after the response body has also been completely received.
+ * Whether or not the {@code HttpResponse} is made available before the response
+ * body has been completely received depends on the {@linkplain BodyHandler
+ * BodyHandler} provided when sending the {@code HttpRequest}.
*
- * See {@link BodyHandler} for example usage.
+ * This class provides methods for accessing the response status code,
+ * headers, the response body, and the {@code HttpRequest} corresponding
+ * to this response.
+ **
+ * @param This is a function that takes two parameters: the response status code,
- * and the response headers, and which returns a {@linkplain BodySubscriber}.
- * The function is always called just before the response body is read. Its
- * implementation may examine the status code or headers and must decide,
- * whether to accept the response body or discard it, and if accepting it,
- * exactly how to handle it.
+ * The {@code BodyHandler} interface allows inspection of the response
+ * code and headers, before the actual response body is received, and is
+ * responsible for creating the response {@linkplain BodySubscriber
+ * BodySubscriber}. The {@code BodySubscriber} consumes the actual response
+ * body bytes and converts them into a higher-level Java type.
*
- * Some pre-defined implementations which do not utilize the status code
- * or headers (meaning the body is always accepted) are defined:
+ * A {@code BodyHandler} is a function that takes two parameters: the
+ * response status code and the response headers; and which returns a
+ * {@code BodySubscriber}. The {@code BodyHandler} is invoked when the
+ * response status code and headers are available, but before the response
+ * body bytes are received.
+ *
+ * A number of convenience static factory methods are provided that
+ * return pre-defined implementations that do not examine the status code
+ * (meaning the body is always accepted):
* These implementations return the equivalent {@link BodySubscriber}.
- * Alternatively, the handler can be used to examine the status code
- * or headers and return different body subscribers as appropriate.
+ * These implementations return an equivalently named {@code
+ * BodySubscriber}. Alternatively, a custom handler can be used to examine
+ * the status code or headers, and return different body subscribers as
+ * appropriate.
*
- * Examples of handler usage
+ * Examples:
*
- * The first example uses one of the predefined handler functions which
- * ignores the response headers and status, and always process the response
- * body in the same way.
- * The first example uses one of the predefined handler functions that
+ * always process the response body in the same way.
+ * In the second example, the function returns a different subscriber
* depending on the status code.
- * The response body can be discarded using one of {@linkplain
+ * #discard() discard} or {@linkplain #replace(Object) replace}.
*
* @param statusCode the HTTP status code received
* @param responseHeaders the response headers received
@@ -272,12 +258,10 @@
* BodySubscriber} and {@code Flow.Subscriber}.
*
* For example:
- * For example:
- * For example:
- * For example:
- * The object acts as a {@link Flow.Subscriber}<{@link List}<{@link
* ByteBuffer}>> to the HTTP client implementation, which publishes
@@ -758,27 +737,27 @@
* is a strictly ordered representation of the response body. Both the Lists
* and the ByteBuffers, once passed to the subscriber, are no longer used by
* the HTTP client. The subscriber converts the incoming buffers of data to
- * some user-defined object type {@code T}.
- *
- * The {@link #getBody()} method returns a {@link CompletionStage}{@code
- * The {@link #getBody()} method returns a
+ * {@link CompletionStage}<{@code T}> that provides the response body
+ * object. The {@code CompletionStage} must be obtainable at any time. When
+ * it completes depends on the nature of type {@code T}. In many cases,
+ * when {@code T} represents the entire body after being consumed then
+ * the {@code CompletionStage} completes after the body has been consumed.
+ * If {@code T} is a streaming type, such as {@link java.io.InputStream
+ * InputStream}, then it completes before the body has been read, because
+ * the calling code uses the {@code InputStream} to consume the data.
+ *
+ * @apiNote To ensure that all resources associated with the corresponding
+ * HTTP exchange are properly released, an implementation of {@code
+ * BodySubscriber} should ensure to {@linkplain Flow.Subscription#request
+ * request} more data until one of {@linkplain #onComplete() onComplete} or
+ * {@link #onError(Throwable) onError} are signalled, or {@linkplain
+ * Flow.Subscription#request cancel} its {@linkplain
+ * #onSubscribe(Flow.Subscription) subscription} if unable or unwilling to
+ * do so. Calling {@code cancel} before exhausting the response body data
+ * may cause the underlying HTTP connection to be closed and prevent it
* from being reused for subsequent operations.
*
* @param
- * Example usage
- * The mapping function is executed using the client's {@linkplain
+ * HttpClient#executor()}, and can therefore be used to map any response
+ * body type, including blocking {@linkplain InputStream}, as shown in
+ * the following example which uses a well-known JSON parser to convert
+ * an {@code InputStream} into any annotated Java object type.
+ *
+ * For example:
+ * The API functions asynchronously (using {@link java.util.concurrent.CompletableFuture})
- * and work is done on the threads supplied by the client's {@link java.util.concurrent.Executor}
- * where practical.
- *
- * {@code HttpClient} also provides a simple synchronous mode, where all
- * work may be done on the calling thread.
+ * Asynchronous tasks and dependent actions of returned {@link
+ * java.util.concurrent.CompletableFuture} instances are executed on the threads
+ * supplied by the client's {@link java.util.concurrent.Executor}, where
+ * practical.
*
- * {@code CompletableFuture}s returned by this API will throw {@link java.lang.UnsupportedOperationException}
- * for their {@link java.util.concurrent.CompletableFuture#obtrudeValue(Object) obtrudeValue}
- * and {@link java.util.concurrent.CompletableFuture#obtrudeException(Throwable) obtrudeException}
- * methods. Invoking the {@link java.util.concurrent.CompletableFuture#cancel cancel}
- * method on a {@code CompletableFuture} returned by this API will not interrupt
- * the underlying operation, but may be useful to complete, exceptionally,
- * dependent stages that have not already completed.
+ * {@code CompletableFuture}s returned by this API will throw {@link
+ * java.lang.UnsupportedOperationException} for their {@link
+ * java.util.concurrent.CompletableFuture#obtrudeValue(Object) obtrudeValue}
+ * and {@link java.util.concurrent.CompletableFuture#obtrudeException(Throwable)
+ * obtrudeException} methods. Invoking the {@link
+ * java.util.concurrent.CompletableFuture#cancel cancel} method on a {@code
+ * CompletableFuture} returned by this API will not interrupt the underlying
+ * operation, but may be useful to complete, exceptionally, dependent stages
+ * that have not already completed.
*
* Unless otherwise stated, {@code null} parameter values will cause methods
* of all classes in this package to throw {@code NullPointerException}.
diff -r 881f0ecb513f -r 15dc43936d39 src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java Wed Feb 07 22:49:25 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java Thu Feb 08 20:58:35 2018 +0000
@@ -48,8 +48,6 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executor;
import java.util.concurrent.Flow;
import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.Flow.Subscription;
@@ -475,7 +473,7 @@
public static BodySubscriber{@code HttpClient client = HttpClient.newBuilder()
- * .version(Version.HTTP_2)
+ * .version(Version.HTTP_1)
* .followRedirects(Redirect.SAME_PROTOCOL)
- * .proxy(ProxySelector.of(new InetSocketAddress("proxy.com", 8080)))
+ * .proxy(ProxySelector.of(new InetSocketAddress("proxy.example.com", 80)))
* .authenticator(Authenticator.getDefault())
* .build();
+ * HttpResponse
*
- * HttpRequest request = HttpRequest.newBuilder()
- * .uri(URI.create("http://foo.com/"))
+ * {@code HttpRequest request = HttpRequest.newBuilder()
+ * .uri(URI.create("https://foo.com/"))
* .timeout(Duration.ofMinutes(1))
* .header("Content-Type", "application/json")
* .POST(BodyPublisher.fromFile(Paths.get("file.json")))
* .build();
- *
* client.sendAsync(request, BodyHandler.asString())
* .thenApply(HttpResponse::body)
* .thenAccept(System.out::println)
* .join(); }
*
- * {@code
- * HttpClient client = HttpClient.newHttpClient();
+ *
*
* {@code HttpClient client = HttpClient.newHttpClient();
* CompletableFuture
+ * .buildAsync(URI.create("ws://websocket.example.com"), listener); }{@code
- * InetSocketAddress addr = new InetSocketAddress("proxy.example.com", 80);
+ *
*
* {@code InetSocketAddress addr = new InetSocketAddress("proxy.example.com", 80);
* HttpClient client = HttpClient.newBuilder()
* .proxy(ProxySelector.of(addr))
* .build();
* CompletableFuture
+ * .buildAsync(URI.create("ws://websocket.example.com"), listener); }{@code // GET
- * HttpResponse
- *
- * {@code HttpClient client = HttpClient.newHttpClient();
+ * HttpRequest request = HttpRequest.newBuilder()
+ * .uri(URI.create("http://foo.com/"))
+ * .build();
+ * client.sendAsync(request, BodyHandler.asString())
+ * .thenApply(HttpResponse::body)
+ * .thenAccept(System.out::println)
+ * .join(); }
*
- * // POST
- * HttpResponse
- *
- *
*
*
- *
- *
- *
- *
- * {@code HttpClient client = HttpClient.newHttpClient();
- *
- * HttpRequest request = HttpRequest
- * .newBuilder(URI.create("http://www.foo.com/"))
- * .POST(BodyPublisher.fromString("Hello world"))
- * .build();
- *
- * HttpResponse
- *
- * {@code // fetch a list of target URIs asynchronously and store them in Files.
- *
- * List
+ *
*
- *
- * {@code
- * HttpResponse
- * Note, that even though these pre-defined handlers ignore the status code
- * and headers, this information is still accessible from the
- * {@code HttpResponse} when it is returned.
+ * {@code HttpRequest request = HttpRequest.newBuilder()
+ * .uri(URI.create("http://www.foo.com/"))
+ * .build();
+ * client.sendAsync(request, BodyHandler.asFile(Paths.get("/tmp/f")))
+ * .thenApply(HttpResponse::body)
+ * .thenAccept(System.out::println) }
+ * Note, that even though these pre-defined handlers do not examine the
+ * response code, the response code and headers are always retrievable from
+ * the {@linkplain HttpResponse}, when it is returned.
*
*
- * {@code
- * HttpResponse
*
* @param {@code HttpRequest request = HttpRequest.newBuilder()
+ * .uri(URI.create("http://www.foo.com/"))
+ * .build();
+ * BodyHandler bodyHandler = (status, headers) -> status == 200
* ? BodySubscriber.asFile(Paths.get("/tmp/f"))
* : BodySubscriber.replace(Paths.get("/NULL")));
- * }
- *
+ * client.sendAsync(request, bodyHandler))
+ * .thenApply(HttpResponse::body)
+ * .thenAccept(System.out::println) } {@code
- * TextSubscriber subscriber = new TextSubscriber();
+ *
*
* @param subscriber the subscriber
* @return a response body handler
@@ -304,12 +288,10 @@
* BodySubscriber} and {@code Flow.Subscriber}.
*
* {@code TextSubscriber subscriber = new TextSubscriber();
* HttpResponse
+ * System.out.println(response.statusCode()); } {@code
- * TextSubscriber subscriber = ...; // accumulates bytes and transforms them into a String
- * HttpResponse
+ * {@code TextSubscriber subscriber = ...; // accumulates bytes and transforms them into a String
+ * HttpResponse
*
* @param the type of the Subscriber
* @param {@code
- * TextSubscriber subscriber = new TextSubscriber();
+ *
*
* @param subscriber the subscriber
* @return a response body handler
@@ -381,12 +361,10 @@
* BodySubscriber} and {@code Flow.Subscriber}.
*
* {@code TextSubscriber subscriber = new TextSubscriber();
* HttpResponse
+ * System.out.println(response.statusCode()); } {@code
- * TextSubscriber subscriber = ...; // accumulates bytes and transforms them into a String
- * HttpResponse
+ * {@code TextSubscriber subscriber = ...; // accumulates bytes and transforms them into a String
+ * HttpResponse
*
* @param the type of the Subscriber
* @param {@code
- * public static
*
- * @param {@code public static
+ * } }