--- a/src/java.net.http/share/classes/java/net/http/HttpClient.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/java/net/http/HttpClient.java Sat Feb 24 11:27:11 2018 +0000
@@ -87,7 +87,7 @@
* .proxy(ProxySelector.of(new InetSocketAddress("proxy.example.com", 80)))
* .authenticator(Authenticator.getDefault())
* .build();
- * HttpResponse<String> response = client.send(request, BodyHandler.asString());
+ * HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
* System.out.println(response.statusCode());
* System.out.println(response.body()); }</pre>
*
@@ -96,9 +96,9 @@
* .uri(URI.create("https://foo.com/"))
* .timeout(Duration.ofMinutes(1))
* .header("Content-Type", "application/json")
- * .POST(BodyPublisher.fromFile(Paths.get("file.json")))
+ * .POST(BodyPublishers.ofFile(Paths.get("file.json")))
* .build();
- * client.sendAsync(request, BodyHandler.asString())
+ * client.sendAsync(request, BodyHandlers.ofString())
* .thenApply(HttpResponse::body)
* .thenAccept(System.out::println); }</pre>
*
--- a/src/java.net.http/share/classes/java/net/http/HttpHeaders.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/java/net/http/HttpHeaders.java Sat Feb 24 11:27:11 2018 +0000
@@ -36,11 +36,16 @@
/**
* A read-only view of a set of HTTP headers.
*
+ * <p> An {@code HttpHeaders} is not created directly, but rather returned from
+ * an {@link HttpResponse HttpResponse}. Specific HTTP headers can be set for
+ * {@linkplain HttpRequest requests} through the one of the request builder's
+ * {@link HttpRequest.Builder#header(String, String) headers} methods.
+ *
* <p> The methods of this class ( that accept a String header name ), and the
* Map returned by the {@link #map() map} method, operate without regard to
* case when retrieving the header value.
*
- * <p> HttpHeaders instances are immutable.
+ * <p> {@code HttpHeaders} instances are immutable.
*
* @since 11
*/
--- a/src/java.net.http/share/classes/java/net/http/HttpRequest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/java/net/http/HttpRequest.java Sat Feb 24 11:27:11 2018 +0000
@@ -65,33 +65,21 @@
* copied and modified many times in order to build multiple related requests
* that differ in some parameters.
*
- * <p><b>Example:</b> GET request that prints the response body as a String
+ * <p> The following is an example of a GET request that prints the response
+ * body as a String:
+ *
* <pre>{@code HttpClient client = HttpClient.newHttpClient();
* HttpRequest request = HttpRequest.newBuilder()
* .uri(URI.create("http://foo.com/"))
* .build();
- * client.sendAsync(request, BodyHandler.asString())
+ * client.sendAsync(request, BodyHandlers.ofString())
* .thenApply(HttpResponse::body)
* .thenAccept(System.out::println)
* .join(); }</pre>
*
- * <p><b>Request bodies</b>
- *
- * <p> Request bodies can be sent using one of the convenience request publisher
- * implementations, provided in {@link BodyPublisher BodyPublisher}.
- * <ul>
- * <li>{@link BodyPublisher#fromByteArray(byte[]) fromByteArray(byte[])} from byte array</li>
- * <li>{@link BodyPublisher#fromByteArrays(Iterable) fromByteArrays(Iterable)}
- * from an Iterable of byte arrays</li>
- * <li>{@link BodyPublisher#fromFile(java.nio.file.Path) fromFile(Path)} from the file located
- * at the given Path</li>
- * <li>{@link BodyPublisher#fromString(java.lang.String) fromString(String)} from a String </li>
- * <li>{@link BodyPublisher#fromInputStream(Supplier) fromInputStream}({@link Supplier}<
- * {@link InputStream}>) from an InputStream obtained from a Supplier</li>
- * <li>{@link BodyPublisher#noBody() noBody()} no request body is sent</li>
- * </ul>
- *
- * <p> Alternatively, a custom {@code BodyPublisher} implementation can be used.
+ * <p>The class {@link BodyPublishers BodyPublishers} provides implementations
+ * of many common publishers. Alternatively, a custom {@code BodyPublisher}
+ * implementation can be used.
*
* @since 11
*/
@@ -275,7 +263,7 @@
* Sets the request method and request body of this builder to the
* given values.
*
- * @apiNote The {@link BodyPublisher#noBody() noBody} request
+ * @apiNote The {@link BodyPublishers#noBody() noBody} request
* body publisher can be used where no request body is required or
* appropriate. Whether a method is restricted, or not, is
* implementation specific. For example, some implementations may choose
@@ -432,7 +420,9 @@
/**
* A {@code BodyPublisher} converts high-level Java objects into a flow of
- * byte buffers suitable for sending as a request body.
+ * byte buffers suitable for sending as a request body. The class
+ * {@link BodyPublishers BodyPublishers} provides implementations of many
+ * common publishers.
*
* <p> The {@code BodyPublisher} interface extends {@link Flow.Publisher
* Flow.Publisher<ByteBuffer>}, which means that a {@code BodyPublisher}
@@ -456,10 +446,62 @@
* <p> 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.
+ *
+ * @see BodyPublishers
+ * @since 11
*/
public interface BodyPublisher extends Flow.Publisher<ByteBuffer> {
/**
+ * Returns the content length for this request body. May be zero
+ * if no request body being sent, greater than zero for a fixed
+ * length content, or less than zero for an unknown content length.
+ *
+ * <p> This method may be invoked before the publisher is subscribed to.
+ * This method may be invoked more than once by the HTTP client
+ * implementation, and MUST return the same constant value each time.
+ *
+ * @return the content length for this request body, if known
+ */
+ long contentLength();
+ }
+
+ /**
+ * Implementations of {@link BodyPublisher BodyPublisher} that implement
+ * various useful publishers, such as publishing the request body from a
+ * string, or from a file.
+ *
+ * <p> The following are examples of using the predefined body publishers to
+ * convert common high-level Java objects into a flow of data suitable for
+ * sending as a request body:
+ *
+ * <pre>{@code // Request body from a String
+ * HttpRequest request = HttpRequest.newBuilder()
+ * .uri(URI.create("https://foo.com/"))
+ * .header("Content-Type", "text/plain; charset=UTF-8")
+ * .POST(BodyPublishers.ofString("some body text"))
+ * .build();
+ *
+ * // Request body from a File
+ * HttpRequest request = HttpRequest.newBuilder()
+ * .uri(URI.create("https://foo.com/"))
+ * .header("Content-Type", "application/json")
+ * .POST(BodyPublishers.ofFile(Paths.get("file.json")))
+ * .build();
+ *
+ * // Request body from a byte array
+ * HttpRequest request = HttpRequest.newBuilder()
+ * .uri(URI.create("https://foo.com/"))
+ * .POST(BodyPublishers.ofByteArray(new byte[] { ... }))
+ * .build(); }</pre>
+ *
+ * @since 11
+ */
+ public static class BodyPublishers {
+
+ private BodyPublishers() { }
+
+ /**
* Returns a request body publisher whose body is retrieved from the
* given {@code Flow.Publisher}. The returned request body publisher
* has an unknown content length.
@@ -471,7 +513,8 @@
* @param publisher the publisher responsible for publishing the body
* @return a BodyPublisher
*/
- static BodyPublisher fromPublisher(Flow.Publisher<? extends ByteBuffer> publisher) {
+ public static BodyPublisher
+ fromPublisher(Flow.Publisher<? extends ByteBuffer> publisher) {
return new RequestPublishers.PublisherAdapter(publisher, -1L);
}
@@ -495,10 +538,12 @@
* non-positive
* @return a BodyPublisher
*/
- static BodyPublisher fromPublisher(Flow.Publisher<? extends ByteBuffer> publisher,
- long contentLength) {
+ public static BodyPublisher
+ fromPublisher(Flow.Publisher<? extends ByteBuffer> publisher,
+ long contentLength) {
if (contentLength < 1)
- throw new IllegalArgumentException("non-positive contentLength: " + contentLength);
+ throw new IllegalArgumentException("non-positive contentLength: "
+ + contentLength);
return new RequestPublishers.PublisherAdapter(publisher, contentLength);
}
@@ -510,8 +555,8 @@
* @param body the String containing the body
* @return a BodyPublisher
*/
- static BodyPublisher fromString(String body) {
- return fromString(body, UTF_8);
+ public static BodyPublisher ofString(String body) {
+ return ofString(body, UTF_8);
}
/**
@@ -522,7 +567,7 @@
* @param charset the character set to convert the string to bytes
* @return a BodyPublisher
*/
- static BodyPublisher fromString(String s, Charset charset) {
+ public static BodyPublisher ofString(String s, Charset charset) {
return new RequestPublishers.StringPublisher(s, charset);
}
@@ -537,7 +582,7 @@
* @return a BodyPublisher
*/
// TODO (spec): specify that the stream will be closed
- static BodyPublisher fromInputStream(Supplier<? extends InputStream> streamSupplier) {
+ public static BodyPublisher ofInputStream(Supplier<? extends InputStream> streamSupplier) {
return new RequestPublishers.InputStreamPublisher(streamSupplier);
}
@@ -547,7 +592,7 @@
* @param buf the byte array containing the body
* @return a BodyPublisher
*/
- static BodyPublisher fromByteArray(byte[] buf) {
+ public static BodyPublisher ofByteArray(byte[] buf) {
return new RequestPublishers.ByteArrayPublisher(buf);
}
@@ -563,7 +608,7 @@
* @throws IndexOutOfBoundsException if the sub-range is defined to be
* out-of-bounds
*/
- static BodyPublisher fromByteArray(byte[] buf, int offset, int length) {
+ public static BodyPublisher ofByteArray(byte[] buf, int offset, int length) {
Objects.checkFromIndexSize(offset, length, buf.length);
return new RequestPublishers.ByteArrayPublisher(buf, offset, length);
}
@@ -586,7 +631,7 @@
* and it denies {@link SecurityManager#checkRead(String)
* read access} to the given file
*/
- static BodyPublisher fromFile(Path path) throws FileNotFoundException {
+ public static BodyPublisher ofFile(Path path) throws FileNotFoundException {
Objects.requireNonNull(path);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
@@ -605,7 +650,7 @@
* @param iter an Iterable of byte arrays
* @return a BodyPublisher
*/
- static BodyPublisher fromByteArrays(Iterable<byte[]> iter) {
+ public static BodyPublisher ofByteArrays(Iterable<byte[]> iter) {
return new RequestPublishers.IterablePublisher(iter);
}
@@ -615,21 +660,8 @@
* @return a BodyPublisher which completes immediately and sends
* no request body.
*/
- static BodyPublisher noBody() {
+ public static BodyPublisher noBody() {
return new RequestPublishers.EmptyPublisher();
}
-
- /**
- * Returns the content length for this request body. May be zero
- * if no request body being sent, greater than zero for a fixed
- * length content, or less than zero for an unknown content length.
- *
- * This method may be invoked before the publisher is subscribed to.
- * This method may be invoked more than once by the HTTP client
- * implementation, and MUST return the same constant value each time.
- *
- * @return the content length for this request body, if known
- */
- long contentLength();
}
}
--- a/src/java.net.http/share/classes/java/net/http/HttpResponse.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/java/net/http/HttpResponse.java Sat Feb 24 11:27:11 2018 +0000
@@ -73,8 +73,16 @@
* headers, the response body, and the {@code HttpRequest} corresponding
* to this response.
*
+ * <p> The following is an example of retrieving a response as a String:
+ *
+ * <pre>{@code HttpResponse<String> response = client
+ * .send(request, BodyHandlers.ofString()); }</pre>
+ *
+ * <p> The class {@link BodyHandlers BodyHandlers} provides implementations
+ * of many common response handlers. Alternatively, a custom {@code BodyHandler}
+ * implementation can be used.
+ *
* @param <T> the response body type
- *
* @since 11
*/
public interface HttpResponse<T> {
@@ -161,13 +169,14 @@
/**
- * A handler for response bodies.
+ * A handler for response bodies. The class {@link BodyHandlers BodyHandlers}
+ * provides implementations of many common body handlers.
*
* <p> 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 {@link BodySubscriber
* BodySubscriber}. The {@code BodySubscriber} consumes the actual response
- * body bytes and converts them into a higher-level Java type.
+ * body bytes and, typically, converts them into a higher-level Java type.
*
* <p> A {@code BodyHandler} is a function that takes two parameters: the
* response status code and the response headers; and which returns a
@@ -175,38 +184,18 @@
* response status code and headers are available, but before the response
* body bytes are received.
*
- * <p> 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):
- * <ul><li>{@link #asByteArray() }</li>
- * <li>{@link #asByteArrayConsumer(java.util.function.Consumer)
- * asByteArrayConsumer(Consumer)}</li>
- * <li>{@link #asString(java.nio.charset.Charset) asString(Charset)}</li>
- * <li>{@link #asFile(Path, OpenOption...) asFile(Path,OpenOption...)}</li>
- * <li>{@link #asFileDownload(java.nio.file.Path,OpenOption...)
- * asFileDownload(Path,OpenOption...)}</li>
- * <li>{@link #asInputStream() asInputStream()}</li>
- * <li>{@link #discard() }</li>
- * <li>{@link #replace(Object) }</li>
- * <li>{@link #buffering(BodyHandler, int) buffering(BodyHandler,int)}</li>
- * </ul>
+ * <p> The following example uses one of the {@linkplain BodyHandlers
+ * predefined body handlers} that always process the response body in the
+ * same way ( streams the response body to a file ).
*
- * <p> 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.
- *
- * <p><b>Examples:</b>
- *
- * <p> The first example uses one of the predefined handler functions that
- * always process the response body in the same way.
* <pre>{@code HttpRequest request = HttpRequest.newBuilder()
* .uri(URI.create("http://www.foo.com/"))
* .build();
- * client.sendAsync(request, BodyHandler.asFile(Paths.get("/tmp/f")))
+ * client.sendAsync(request, BodyHandlers.ofFile(Paths.get("/tmp/f")))
* .thenApply(HttpResponse::body)
* .thenAccept(System.out::println) }</pre>
- * Note, that even though these pre-defined handlers do not examine the
+ *
+ * Note, that even though the pre-defined handlers do not examine the
* response code, the response code and headers are always retrievable from
* the {@link HttpResponse}, when it is returned.
*
@@ -216,35 +205,77 @@
* .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")));
+ * ? BodySubscribers.ofFile(Paths.get("/tmp/f"))
+ * : BodySubscribers.replacing(Paths.get("/NULL")));
* client.sendAsync(request, bodyHandler))
* .thenApply(HttpResponse::body)
* .thenAccept(System.out::println) }</pre>
*
* @param <T> the response body type
+ * @see BodyHandlers
+ * @since 11
*/
@FunctionalInterface
public interface BodyHandler<T> {
+
/**
* Returns a {@link BodySubscriber BodySubscriber} considering the
* given response status code and headers. This method is invoked before
* the actual response body bytes are read and its implementation must
- * return a {@code BodySubscriber} to consume the response body bytes.
+ * return a {@link BodySubscriber BodySubscriber} to consume the response
+ * body bytes.
*
* <p> The response body can be discarded using one of {@link
- * #discard() discard} or {@link #replace(Object) replace}.
+ * BodyHandlers#discarding() discarding} or {@link
+ * BodyHandlers#replacing(Object) replacing}.
*
* @param statusCode the HTTP status code received
* @param responseHeaders the response headers received
* @return a body subscriber
*/
public BodySubscriber<T> apply(int statusCode, HttpHeaders responseHeaders);
+ }
+
+ /**
+ * Implementations of {@link BodyHandler BodyHandler} that implement various
+ * useful handlers, such as handling the response body as a String, or
+ * streaming the response body to a file.
+ *
+ * <p> These implementations do not examine the status code, meaning the
+ * body is always accepted. They typically return an equivalently named
+ * {@code BodySubscriber}. Alternatively, a custom handler can be used to
+ * examine the status code and headers, and return a different body
+ * subscriber, of the same type, as appropriate.
+ *
+ * <p>The following are examples of using the predefined body handlers to
+ * convert a flow of response body data into common high-level Java objects:
+ *
+ * <pre>{@code // Receives the response body as a String
+ * HttpResponse<String> response = client
+ * .send(request, BodyHandlers.ofString());
+ *
+ * // Receives the response body as a file
+ * HttpResponse<Path> response = client
+ * .send(request, BodyHandlers.ofFile(Paths.get("example.html")));
+ *
+ * // Receives the response body as an InputStream
+ * HttpResponse<InputStream> response = client
+ * .send(request, BodyHandlers.ofInputStream());
+ *
+ * // Discards the response body
+ * HttpResponse<Void> response = client
+ * .send(request, BodyHandlers.discarding()); }</pre>
+ *
+ * @since 11
+ */
+ public static class BodyHandlers {
+
+ private BodyHandlers() { }
/**
* Returns a response body handler that returns a {@link BodySubscriber
* BodySubscriber}{@code <Void>} obtained from {@link
- * BodySubscriber#fromSubscriber(Subscriber)}, with the given
+ * BodySubscribers#fromSubscriber(Subscriber)}, with the given
* {@code subscriber}.
*
* <p> The response body is not available through this, or the {@code
@@ -259,7 +290,7 @@
* <p> For example:
* <pre> {@code TextSubscriber subscriber = new TextSubscriber();
* HttpResponse<Void> response = client.sendAsync(request,
- * BodyHandler.fromSubscriber(subscriber)).join();
+ * BodyHandlers.fromSubscriber(subscriber)).join();
* System.out.println(response.statusCode()); }</pre>
*
* @param subscriber the subscriber
@@ -268,14 +299,14 @@
public static BodyHandler<Void>
fromSubscriber(Subscriber<? super List<ByteBuffer>> subscriber) {
Objects.requireNonNull(subscriber);
- return (status, headers) -> BodySubscriber.fromSubscriber(subscriber,
- s -> null);
+ return (status, headers) -> BodySubscribers.fromSubscriber(subscriber,
+ s -> null);
}
/**
* Returns a response body handler that returns a {@link BodySubscriber
* BodySubscriber}{@code <T>} obtained from {@link
- * BodySubscriber#fromSubscriber(Subscriber, Function)}, with the
+ * BodySubscribers#fromSubscriber(Subscriber, Function)}, with the
* given {@code subscriber} and {@code finisher} function.
*
* <p> The given {@code finisher} function is applied after the given
@@ -289,7 +320,7 @@
* <p> For example:
* <pre> {@code TextSubscriber subscriber = ...; // accumulates bytes and transforms them into a String
* HttpResponse<String> response = client.sendAsync(request,
- * BodyHandler.fromSubscriber(subscriber, TextSubscriber::getTextResult)).join();
+ * BodyHandlers.fromSubscriber(subscriber, TextSubscriber::getTextResult)).join();
* String text = response.body(); }</pre>
*
* @param <S> the type of the Subscriber
@@ -302,18 +333,18 @@
fromSubscriber(S subscriber, Function<? super S,? extends T> finisher) {
Objects.requireNonNull(subscriber);
Objects.requireNonNull(finisher);
- return (status, headers) -> BodySubscriber.fromSubscriber(subscriber,
+ return (status, headers) -> BodySubscribers.fromSubscriber(subscriber,
finisher);
}
/**
* Returns a response body handler that returns a {@link BodySubscriber
* BodySubscriber}{@code <Void>} obtained from {@link
- * BodySubscriber#fromLineSubscriber(Subscriber, Function, Charset, String)
- * BodySubscriber.fromLineSubscriber(subscriber, s -> null, charset, null)},
+ * BodySubscribers#fromLineSubscriber(Subscriber, Function, Charset, String)
+ * BodySubscribers.fromLineSubscriber(subscriber, s -> null, charset, null)},
* with the given {@code subscriber}.
* The {@link Charset charset} used to decode the response body bytes is
- * obtained from the HTTP response headers as specified by {@link #asString()},
+ * obtained from the HTTP response headers as specified by {@link #ofString()},
* and lines are delimited in the manner of {@link BufferedReader#readLine()}.
*
* <p> The response body is not available through this, or the {@code
@@ -330,7 +361,7 @@
* <pre> {@code // A PrintSubscriber that implements Flow.Subscriber<String>
* // and print lines received by onNext() on System.out
* PrintSubscriber subscriber = new PrintSubscriber(System.out);
- * client.sendAsync(request, BodyHandler.fromLineSubscriber(subscriber))
+ * client.sendAsync(request, BodyHandlers.fromLineSubscriber(subscriber))
* .thenApply(HttpResponse::statusCode)
* .thenAccept((status) -> {
* if (status != 200) {
@@ -344,19 +375,21 @@
public static BodyHandler<Void>
fromLineSubscriber(Subscriber<? super String> subscriber) {
Objects.requireNonNull(subscriber);
- return (status, headers)
- -> BodySubscriber.fromLineSubscriber(subscriber, s -> null,
- charsetFrom(headers), null);
+ return (status, headers) ->
+ BodySubscribers.fromLineSubscriber(subscriber,
+ s -> null,
+ charsetFrom(headers),
+ null);
}
/**
* Returns a response body handler that returns a {@link BodySubscriber
* BodySubscriber}{@code <T>} obtained from {@link
- * BodySubscriber#fromLineSubscriber(Subscriber, Function, Charset, String)
- * BodySubscriber.fromLineSubscriber(subscriber, finisher, charset, lineSeparator)},
+ * BodySubscribers#fromLineSubscriber(Subscriber, Function, Charset, String)
+ * BodySubscribers.fromLineSubscriber(subscriber, finisher, charset, lineSeparator)},
* with the given {@code subscriber}, {@code finisher} function, and line separator.
* The {@link Charset charset} used to decode the response body bytes is
- * obtained from the HTTP response headers as specified by {@link #asString()}.
+ * obtained from the HTTP response headers as specified by {@link #ofString()}.
*
* <p> The given {@code finisher} function is applied after the given
* subscriber's {@code onComplete} has been invoked. The {@code finisher}
@@ -373,7 +406,7 @@
* Pattern pattern = ...;
* LineParserSubscriber subscriber = new LineParserSubscriber(pattern);
* HttpResponse<List<String>> response = client.send(request,
- * BodyHandler.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n"));
+ * BodyHandlers.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n"));
* if (response.statusCode() != 200) {
* System.err.printf("ERROR: %d status received%n", response.statusCode());
* } }</pre>
@@ -400,50 +433,52 @@
if (lineSeparator != null && lineSeparator.isEmpty())
throw new IllegalArgumentException("empty line separator");
return (status, headers) ->
- BodySubscriber.fromLineSubscriber(subscriber, finisher,
- charsetFrom(headers), lineSeparator);
+ BodySubscribers.fromLineSubscriber(subscriber,
+ finisher,
+ charsetFrom(headers),
+ lineSeparator);
}
/**
- * Returns a response body handler which discards the response body.
+ * Returns a response body handler that discards the response body.
*
* @return a response body handler
*/
- public static BodyHandler<Void> discard() {
- return (status, headers) -> BodySubscriber.discard();
+ public static BodyHandler<Void> discarding() {
+ return (status, headers) -> BodySubscribers.discarding();
}
/**
- * Returns a response body handler which discards the response body and
- * uses the given value as a replacement for it.
+ * Returns a response body handler that returns the given replacement
+ * value, after discarding the response body.
*
* @param <U> the response body type
* @param value the value of U to return as the body, may be {@code null}
* @return a response body handler
*/
- public static <U> BodyHandler<U> replace(U value) {
- return (status, headers) -> BodySubscriber.replace(value);
+ public static <U> BodyHandler<U> replacing(U value) {
+ return (status, headers) -> BodySubscribers.replacing(value);
}
/**
* Returns a {@code BodyHandler<String>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <String>} obtained from
- * {@link BodySubscriber#asString(Charset) BodySubscriber.asString(Charset)}.
+ * {@link BodySubscribers#ofString(Charset) BodySubscribers.ofString(Charset)}.
* The body is decoded using the given character set.
*
* @param charset the character set to convert the body with
* @return a response body handler
*/
- public static BodyHandler<String> asString(Charset charset) {
+ public static BodyHandler<String> ofString(Charset charset) {
Objects.requireNonNull(charset);
- return (status, headers) -> BodySubscriber.asString(charset);
+ return (status, headers) -> BodySubscribers.ofString(charset);
}
/**
* Returns a {@code BodyHandler<Path>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <Path>} obtained from
- * {@link BodySubscriber#asFile(Path, OpenOption...)
- * BodySubscriber.asFile(Path,OpenOption...)}.
+ * {@link BodySubscribers#ofFile(Path, OpenOption...)
+ * BodySubscribers.ofFile(Path,OpenOption...)}.
*
* <p> When the {@code HttpResponse} object is returned, the body has
* been completely written to the file, and {@link #body()} returns a
@@ -462,7 +497,7 @@
* and it denies {@link SecurityManager#checkWrite(String)
* write access} to the file.
*/
- public static BodyHandler<Path> asFile(Path file, OpenOption... openOptions) {
+ public static BodyHandler<Path> ofFile(Path file, OpenOption... openOptions) {
Objects.requireNonNull(file);
List<OpenOption> opts = List.of(openOptions);
if (opts.contains(DELETE_ON_CLOSE) || opts.contains(READ)) {
@@ -482,7 +517,7 @@
* Returns a {@code BodyHandler<Path>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <Path>}.
*
- * <p> Equivalent to: {@code asFile(file, CREATE, WRITE)}
+ * <p> Equivalent to: {@code ofFile(file, CREATE, WRITE)}
*
* <p> Security manager permission checks are performed in this factory
* method, when the {@code BodyHandler} is created. Care must be taken
@@ -494,8 +529,8 @@
* and it denies {@link SecurityManager#checkWrite(String)
* write access} to the file.
*/
- public static BodyHandler<Path> asFile(Path file) {
- return BodyHandler.asFile(file, CREATE, WRITE);
+ public static BodyHandler<Path> ofFile(Path file) {
+ return BodyHandlers.ofFile(file, CREATE, WRITE);
}
/**
@@ -530,7 +565,7 @@
* read access} or {@linkplain SecurityManager#checkWrite(String)
* write access} to the directory.
*/
- public static BodyHandler<Path> asFileDownload(Path directory,
+ public static BodyHandler<Path> ofFileDownload(Path directory,
OpenOption... openOptions) {
Objects.requireNonNull(directory);
List<OpenOption> opts = List.of(openOptions);
@@ -557,29 +592,29 @@
/**
* Returns a {@code BodyHandler<InputStream>} that returns a
- * {@link BodySubscriber BodySubscriber}{@code <InputStream>} obtained
- * from {@link BodySubscriber#asInputStream() BodySubscriber.asInputStream}.
+ * {@link BodySubscriber BodySubscriber}{@code <InputStream>} obtained from
+ * {@link BodySubscribers#ofInputStream() BodySubscribers.ofInputStream}.
*
* <p> When the {@code HttpResponse} object is returned, the response
* headers will have been completely read, but the body may not have
* been fully received yet. The {@link #body()} method returns an
* {@link InputStream} from which the body can be read as it is received.
*
- * @apiNote See {@link BodySubscriber#asInputStream()} for more information.
+ * @apiNote See {@link BodySubscribers#ofInputStream()} for more
+ * information.
*
* @return a response body handler
*/
- public static BodyHandler<InputStream> asInputStream() {
- return (status, headers) -> BodySubscriber.asInputStream();
+ public static BodyHandler<InputStream> ofInputStream() {
+ return (status, headers) -> BodySubscribers.ofInputStream();
}
/**
* Returns a {@code BodyHandler<Stream<String>>} that returns a
- * {@link BodySubscriber BodySubscriber}{@code <Stream<String>>} obtained from
- * {@link BodySubscriber#asLines(Charset)
- * BodySubscriber.asLines(charset)}.
+ * {@link BodySubscriber BodySubscriber}{@code <Stream<String>>} obtained
+ * from {@link BodySubscribers#ofLines(Charset) BodySubscribers.ofLines(charset)}.
* The {@link Charset charset} used to decode the response body bytes is
- * obtained from the HTTP response headers as specified by {@link #asString()},
+ * obtained from the HTTP response headers as specified by {@link #ofString()},
* and lines are delimited in the manner of {@link BufferedReader#readLine()}.
*
* <p> When the {@code HttpResponse} object is returned, the body may
@@ -587,19 +622,20 @@
*
* @return a response body handler
*/
- public static BodyHandler<Stream<String>> asLines() {
+ public static BodyHandler<Stream<String>> ofLines() {
return (status, headers) ->
- BodySubscriber.asLines(charsetFrom(headers));
+ BodySubscribers.ofLines(charsetFrom(headers));
}
/**
* Returns a {@code BodyHandler<Void>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <Void>} obtained from
- * {@link BodySubscriber#asByteArrayConsumer(Consumer)
- * BodySubscriber.asByteArrayConsumer(Consumer)}.
+ * {@link BodySubscribers#ofByteArrayConsumer(Consumer)
+ * BodySubscribers.ofByteArrayConsumer(Consumer)}.
*
* <p> When the {@code HttpResponse} object is returned, the body has
* been completely written to the consumer.
+ *
* @apiNote
* The subscriber returned by this handler is not flow controlled.
* Therefore, the supplied consumer must be able to process whatever
@@ -608,57 +644,57 @@
* @param consumer a Consumer to accept the response body
* @return a response body handler
*/
- public static BodyHandler<Void> asByteArrayConsumer(Consumer<Optional<byte[]>> consumer) {
+ public static BodyHandler<Void>
+ ofByteArrayConsumer(Consumer<Optional<byte[]>> consumer) {
Objects.requireNonNull(consumer);
- return (status, headers) -> BodySubscriber.asByteArrayConsumer(consumer);
+ return (status, headers) -> BodySubscribers.ofByteArrayConsumer(consumer);
}
/**
* Returns a {@code BodyHandler<byte[]>} that returns a
* {@link BodySubscriber BodySubscriber}<{@code byte[]}> obtained
- * from {@link BodySubscriber#asByteArray() BodySubscriber.asByteArray()}.
+ * from {@link BodySubscribers#ofByteArray() BodySubscribers.ofByteArray()}.
*
* <p> When the {@code HttpResponse} object is returned, the body has
* been completely written to the byte array.
*
* @return a response body handler
*/
- public static BodyHandler<byte[]> asByteArray() {
- return (status, headers) -> BodySubscriber.asByteArray();
+ public static BodyHandler<byte[]> ofByteArray() {
+ return (status, headers) -> BodySubscribers.ofByteArray();
}
/**
* Returns a {@code BodyHandler<String>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <String>} obtained from
- * {@link BodySubscriber#asString(java.nio.charset.Charset)
- * BodySubscriber.asString(Charset)}. The body is
- * decoded using the character set specified in
- * the {@code Content-type} response header. If there is no such
+ * {@link BodySubscribers#ofString(Charset) BodySubscribers.ofString(Charset)}.
+ * The body is decoded using the character set specified in
+ * the {@code Content-Type} response header. If there is no such
* header, or the character set is not supported, then
- * {@link java.nio.charset.StandardCharsets#UTF_8 UTF_8} is used.
+ * {@link StandardCharsets#UTF_8 UTF_8} is used.
*
* <p> When the {@code HttpResponse} object is returned, the body has
* been completely written to the string.
*
* @return a response body handler
*/
- public static BodyHandler<String> asString() {
- return (status, headers) -> BodySubscriber.asString(charsetFrom(headers));
+ public static BodyHandler<String> ofString() {
+ return (status, headers) -> BodySubscribers.ofString(charsetFrom(headers));
}
/**
* Returns a {@code BodyHandler} which, when invoked, returns a {@linkplain
- * BodySubscriber#buffering(BodySubscriber,int) buffering BodySubscriber}
+ * BodySubscribers#buffering(BodySubscriber,int) buffering BodySubscriber}
* that buffers data before delivering it to the downstream subscriber.
* These {@code BodySubscriber} instances are created by calling
- * {@link BodySubscriber#buffering(BodySubscriber,int)
- * BodySubscriber.buffering} with a subscriber obtained from the given
+ * {@link BodySubscribers#buffering(BodySubscriber,int)
+ * BodySubscribers.buffering} with a subscriber obtained from the given
* downstream handler and the {@code bufferSize} parameter.
*
* @param <T> the response body type
* @param downstreamHandler the downstream handler
* @param bufferSize the buffer size parameter passed to {@link
- * BodySubscriber#buffering(BodySubscriber,int) BodySubscriber.buffering}
+ * BodySubscribers#buffering(BodySubscriber,int) BodySubscribers.buffering}
* @return a body handler
* @throws IllegalArgumentException if {@code bufferSize <= 0}
*/
@@ -667,7 +703,7 @@
Objects.requireNonNull(downstreamHandler);
if (bufferSize <= 0)
throw new IllegalArgumentException("must be greater than 0");
- return (status, headers) -> BodySubscriber
+ return (status, headers) -> BodySubscribers
.buffering(downstreamHandler.apply(status, headers),
bufferSize);
}
@@ -690,8 +726,10 @@
* client-sent request.
*
* @param <T> the push promise response body type
+ * @since 11
*/
public interface PushPromiseHandler<T> {
+
/**
* Notification of an incoming push promise.
*
@@ -762,7 +800,8 @@
/**
* A {@code BodySubscriber} consumes response body bytes and converts them
- * into a higher-level Java type.
+ * into a higher-level Java type. The class {@link BodySubscribers
+ * BodySubscriber} provides implementations of many common body subscribers.
*
* <p> The object acts as a {@link Flow.Subscriber}<{@link List}<{@link
* ByteBuffer}>> to the HTTP client implementation, which publishes
@@ -795,6 +834,8 @@
* from being reused for subsequent operations.
*
* @param <T> the response body type
+ * @see BodySubscribers
+ * @since 11
*/
public interface BodySubscriber<T>
extends Flow.Subscriber<List<ByteBuffer>> {
@@ -808,13 +849,47 @@
* @return a CompletionStage for the response body
*/
public CompletionStage<T> getBody();
+ }
+
+ /**
+ * Implementations of {@link BodySubscriber BodySubscriber} that implement
+ * various useful subscribers, such as converting the response body bytes
+ * into a String, or streaming the bytes to a file.
+ *
+ * <p>The following are examples of using the predefined body subscribers
+ * to convert a flow of response body data into common high-level Java
+ * objects:
+ *
+ * <pre>{@code // Streams the response body to a File
+ * HttpResponse<byte[]> response = client
+ * .send(request, (statusCode, responseHeaders) -> BodySubscribers.ofByteArray());
+ *
+ * // Accumulates the response body and returns it as a byte[]
+ * HttpResponse<byte[]> response = client
+ * .send(request, (statusCode, responseHeaders) -> BodySubscribers.ofByteArray());
+ *
+ * // Discards the response body
+ * HttpResponse<Void> response = client
+ * .send(request, (statusCode, responseHeaders) -> BodySubscribers.discarding());
+ *
+ * // Accumulates the response body as a String then maps it to its bytes
+ * HttpResponse<byte[]> response = client
+ * .send(request, (sc, hdrs) ->
+ * BodySubscribers.mapping(BodySubscribers.ofString(), String::getBytes));
+ * }</pre>
+ *
+ * @since 11
+ */
+ public static class BodySubscribers {
+
+ private BodySubscribers() { }
/**
* Returns a body subscriber that forwards all response body to the
- * given {@code Flow.Subscriber}. The {@linkplain #getBody() completion
- * stage} of the returned body subscriber completes after one of the
- * given subscribers {@code onComplete} or {@code onError} has been
- * invoked.
+ * given {@code Flow.Subscriber}. The {@linkplain BodySubscriber#getBody()
+ * completion stage} of the returned body subscriber completes after one
+ * of the given subscribers {@code onComplete} or {@code onError} has
+ * been invoked.
*
* @apiNote This method can be used as an adapter between {@code
* BodySubscriber} and {@code Flow.Subscriber}.
@@ -829,10 +904,10 @@
/**
* Returns a body subscriber that forwards all response body to the
- * given {@code Flow.Subscriber}. The {@linkplain #getBody() completion
- * stage} of the returned body subscriber completes after one of the
- * given subscribers {@code onComplete} or {@code onError} has been
- * invoked.
+ * given {@code Flow.Subscriber}. The {@linkplain BodySubscriber#getBody()
+ * completion stage} of the returned body subscriber completes after one
+ * of the given subscribers {@code onComplete} or {@code onError} has
+ * been invoked.
*
* <p> The given {@code finisher} function is applied after the given
* subscriber's {@code onComplete} has been invoked. The {@code finisher}
@@ -858,7 +933,7 @@
/**
* Returns a body subscriber that forwards all response body to the
* given {@code Flow.Subscriber}, line by line.
- * The {@linkplain #getBody() completion
+ * The {@linkplain BodySubscriber#getBody() completion
* stage} of the returned body subscriber completes after one of the
* given subscribers {@code onComplete} or {@code onError} has been
* invoked.
@@ -884,10 +959,10 @@
/**
* Returns a body subscriber that forwards all response body to the
- * given {@code Flow.Subscriber}, line by line. The {@linkplain #getBody()
- * completion stage} of the returned body subscriber completes after
- * one of the given subscribers {@code onComplete} or {@code onError}
- * has been invoked.
+ * given {@code Flow.Subscriber}, line by line. The {@linkplain
+ * BodySubscriber#getBody() completion stage} of the returned body
+ * subscriber completes after one of the given subscribers
+ * {@code onComplete} or {@code onError} has been invoked.
*
* <p> The given {@code finisher} function is applied after the given
* subscriber's {@code onComplete} has been invoked. The {@code finisher}
@@ -929,7 +1004,7 @@
* @param charset the character set to convert the String with
* @return a body subscriber
*/
- public static BodySubscriber<String> asString(Charset charset) {
+ public static BodySubscriber<String> ofString(Charset charset) {
Objects.requireNonNull(charset);
return new ResponseSubscribers.ByteArraySubscriber<>(
bytes -> new String(bytes, charset)
@@ -945,7 +1020,7 @@
*
* @return a body subscriber
*/
- public static BodySubscriber<byte[]> asByteArray() {
+ public static BodySubscriber<byte[]> ofByteArray() {
return new ResponseSubscribers.ByteArraySubscriber<>(
Function.identity() // no conversion
);
@@ -976,7 +1051,7 @@
* and it denies {@link SecurityManager#checkWrite(String)
* write access} to the file
*/
- public static BodySubscriber<Path> asFile(Path file, OpenOption... openOptions) {
+ public static BodySubscriber<Path> ofFile(Path file, OpenOption... openOptions) {
Objects.requireNonNull(file);
List<OpenOption> opts = List.of(openOptions);
if (opts.contains(DELETE_ON_CLOSE) || opts.contains(READ)) {
@@ -996,7 +1071,7 @@
* Returns a {@code BodySubscriber} which stores the response body in a
* file opened with the given name.
*
- * <p> Equivalent to: {@code asFile(file, CREATE, WRITE)}
+ * <p> Equivalent to: {@code ofFile(file, CREATE, WRITE)}
*
* <p> Security manager permission checks are performed in this factory
* method, when the {@code BodySubscriber} is created. Care must be taken
@@ -1008,8 +1083,8 @@
* and it denies {@link SecurityManager#checkWrite(String)
* write access} to the file
*/
- public static BodySubscriber<Path> asFile(Path file) {
- return asFile(file, CREATE, WRITE);
+ public static BodySubscriber<Path> ofFile(Path file) {
+ return ofFile(file, CREATE, WRITE);
}
/**
@@ -1031,7 +1106,8 @@
* @param consumer a Consumer of byte arrays
* @return a BodySubscriber
*/
- public static BodySubscriber<Void> asByteArrayConsumer(Consumer<Optional<byte[]>> consumer) {
+ public static BodySubscriber<Void>
+ ofByteArrayConsumer(Consumer<Optional<byte[]>> consumer) {
return new ResponseSubscribers.ConsumerSubscriber(consumer);
}
@@ -1055,7 +1131,7 @@
* @return a body subscriber that streams the response body as an
* {@link InputStream}.
*/
- public static BodySubscriber<InputStream> asInputStream() {
+ public static BodySubscriber<InputStream> ofInputStream() {
return new ResponseSubscribers.HttpResponseInputStream();
}
@@ -1083,7 +1159,7 @@
*
* @see BufferedReader#lines()
*/
- public static BodySubscriber<Stream<String>> asLines(Charset charset) {
+ public static BodySubscriber<Stream<String>> ofLines(Charset charset) {
return ResponseSubscribers.createLineStream(charset);
}
@@ -1096,7 +1172,7 @@
* @param value the value to return from HttpResponse.body(), may be {@code null}
* @return a {@code BodySubscriber}
*/
- public static <U> BodySubscriber<U> replace(U value) {
+ public static <U> BodySubscriber<U> replacing(U value) {
return new ResponseSubscribers.NullSubscriber<>(Optional.ofNullable(value));
}
@@ -1105,7 +1181,7 @@
*
* @return a response body subscriber
*/
- public static BodySubscriber<Void> discard() {
+ public static BodySubscriber<Void> discarding() {
return new ResponseSubscribers.NullSubscriber<>(Optional.ofNullable(null));
}
@@ -1113,13 +1189,14 @@
* Returns a {@code BodySubscriber} which buffers data before delivering
* it to the given downstream subscriber. The subscriber guarantees to
* deliver {@code buffersize} bytes of data to each invocation of the
- * downstream's {@link #onNext(Object) onNext} method, except for
- * the final invocation, just before {@link #onComplete() onComplete}
- * is invoked. The final invocation of {@code onNext} may contain fewer
- * than {@code bufferSize} bytes.
+ * downstream's {@link BodySubscriber#onNext(Object) onNext} method,
+ * except for the final invocation, just before
+ * {@link BodySubscriber#onComplete() onComplete} is invoked. The final
+ * invocation of {@code onNext} may contain fewer than {@code bufferSize}
+ * bytes.
*
- * <p> The returned subscriber delegates its {@link #getBody()} method
- * to the downstream subscriber.
+ * <p> The returned subscriber delegates its {@link BodySubscriber#getBody()
+ * getBody()} method to the downstream subscriber.
*
* @param <T> the type of the response body
* @param downstream the downstream subscriber
@@ -1147,9 +1224,9 @@
*
* <p>For example:
* <pre> {@code public static <W> BodySubscriber<W> asJSON(Class<W> targetType) {
- * BodySubscriber<InputStream> upstream = BodySubscriber.asInputStream();
+ * BodySubscriber<InputStream> upstream = BodySubscribers.ofInputStream();
*
- * BodySubscriber<W> downstream = mapping(
+ * BodySubscriber<W> downstream = BodySubscribers.mapping(
* upstream,
* (InputStream is) -> {
* try (InputStream stream = is) {
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Exchange.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Exchange.java Sat Feb 24 11:27:11 2018 +0000
@@ -409,7 +409,7 @@
}
HttpResponse.BodySubscriber<T> ignoreBody(int status, HttpHeaders hdrs) {
- return HttpResponse.BodySubscriber.replace(null);
+ return HttpResponse.BodySubscribers.replacing(null);
}
// if this response was received in reply to an upgrade
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http1Response.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http1Response.java Sat Feb 24 11:27:11 2018 +0000
@@ -40,6 +40,7 @@
import jdk.internal.net.http.common.MinimalFuture;
import jdk.internal.net.http.common.Utils;
import static java.net.http.HttpClient.Version.HTTP_1_1;
+import static java.net.http.HttpResponse.BodySubscribers.discarding;
/**
* Handles a HTTP/1.1 response (headers + body).
@@ -203,7 +204,7 @@
connection.close();
return MinimalFuture.completedFuture(null); // not treating as error
} else {
- return readBody(HttpResponse.BodySubscriber.discard(), true, executor);
+ return readBody(discarding(), true, executor);
}
}
--- a/src/java.net.http/share/classes/jdk/internal/net/http/PlainTunnelingConnection.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/PlainTunnelingConnection.java Sat Feb 24 11:27:11 2018 +0000
@@ -35,7 +35,7 @@
import java.net.http.HttpHeaders;
import jdk.internal.net.http.common.FlowTube;
import jdk.internal.net.http.common.MinimalFuture;
-import static java.net.http.HttpResponse.BodyHandler.discard;
+import static java.net.http.HttpResponse.BodyHandlers.discarding;
/**
* A plain text socket tunnel through a proxy. Uses "CONNECT" but does not
@@ -69,7 +69,7 @@
assert client != null;
HttpRequestImpl req = new HttpRequestImpl("CONNECT", address, proxyHeaders);
MultiExchange<Void> mulEx = new MultiExchange<>(null, req,
- client, discard(), null, null);
+ client, discarding(), null, null);
Exchange<Void> connectExchange = new Exchange<>(req, mulEx);
return connectExchange
--- a/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java Fri Feb 23 16:25:32 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java Sat Feb 24 11:27:11 2018 +0000
@@ -30,7 +30,7 @@
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.WebSocketHandshakeException;
import jdk.internal.net.http.common.MinimalFuture;
import jdk.internal.net.http.common.Pair;
@@ -186,7 +186,7 @@
public CompletableFuture<Result> send() {
PrivilegedAction<CompletableFuture<Result>> pa = () ->
- client.sendAsync(this.request, BodyHandler.discard())
+ client.sendAsync(this.request, BodyHandlers.discarding())
.thenCompose(this::resultFrom);
return AccessController.doPrivileged(pa);
}
--- a/test/jdk/java/net/httpclient/AsFileDownloadTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/AsFileDownloadTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -50,6 +50,11 @@
import java.io.UncheckedIOException;
import java.net.InetSocketAddress;
import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandler;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -57,10 +62,6 @@
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLContext;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodyHandler;
import jdk.testlibrary.SimpleSSLContext;
import jdk.test.lib.util.FileUtils;
import org.testng.annotations.AfterTest;
@@ -68,8 +69,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static java.lang.System.out;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asFileDownload;
+import static java.net.http.HttpResponse.BodyHandlers.ofFileDownload;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.*;
import static org.testng.Assert.assertEquals;
@@ -165,10 +165,10 @@
URI uri = URI.create(uriString);
HttpRequest request = HttpRequest.newBuilder(uri)
- .POST(fromString("May the luck of the Irish be with you!"))
+ .POST(BodyPublishers.ofString("May the luck of the Irish be with you!"))
.build();
- BodyHandler bh = asFileDownload(tempDir.resolve(uri.getPath().substring(1)),
+ BodyHandler bh = ofFileDownload(tempDir.resolve(uri.getPath().substring(1)),
CREATE, TRUNCATE_EXISTING, WRITE);
HttpResponse<Path> response = client.send(request, bh);
@@ -234,10 +234,10 @@
URI uri = URI.create(uriString);
HttpRequest request = HttpRequest.newBuilder(uri)
- .POST(fromString("Does not matter"))
+ .POST(BodyPublishers.ofString("Does not matter"))
.build();
- BodyHandler bh = asFileDownload(tempDir, CREATE, TRUNCATE_EXISTING, WRITE);
+ BodyHandler bh = ofFileDownload(tempDir, CREATE, TRUNCATE_EXISTING, WRITE);
try {
HttpResponse<Path> response = client.send(request, bh);
fail("UNEXPECTED response: " + response + ", path:" + response.body());
--- a/test/jdk/java/net/httpclient/BasicAuthTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/BasicAuthTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,12 +41,14 @@
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.URI;
-import java.net.http.*;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static java.nio.charset.StandardCharsets.US_ASCII;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
public class BasicAuthTest {
@@ -75,7 +77,7 @@
URI uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/test/foo");
HttpRequest req = HttpRequest.newBuilder(uri).GET().build();
- HttpResponse resp = client.send(req, asString());
+ HttpResponse resp = client.send(req, BodyHandlers.ofString());
ok = resp.statusCode() == 200 && resp.body().equals(RESPONSE);
if (!ok || ca.count != 1)
@@ -83,7 +85,7 @@
// repeat same request, should succeed but no additional authenticator calls
- resp = client.send(req, asString());
+ resp = client.send(req, BodyHandlers.ofString());
ok = resp.statusCode() == 200 && resp.body().equals(RESPONSE);
if (!ok || ca.count != 1)
@@ -92,9 +94,9 @@
// try a POST
req = HttpRequest.newBuilder(uri)
- .POST(fromString(POST_BODY))
+ .POST(BodyPublishers.ofString(POST_BODY))
.build();
- resp = client.send(req, asString());
+ resp = client.send(req, BodyHandlers.ofString());
ok = resp.statusCode() == 200;
if (!ok || ca.count != 1)
@@ -156,6 +158,5 @@
ok = true;
}
}
-
}
}
--- a/test/jdk/java/net/httpclient/BodyProcessorInputStreamTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/BodyProcessorInputStreamTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,6 @@
* questions.
*/
-import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -30,18 +29,11 @@
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-import java.nio.ByteBuffer;
+import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
import java.util.Optional;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.Flow;
import java.util.stream.Stream;
import static java.lang.System.err;
@@ -95,14 +87,14 @@
// This example shows how to return an InputStream that can be used to
// start reading the response body before the response is fully received.
// In comparison, the snipet below (which uses
- // HttpResponse.BodyHandler.asString()) obviously will not return before the
+ // HttpResponse.BodyHandlers.ofString()) obviously will not return before the
// response body is fully read:
//
// System.out.println(
- // client.sendAsync(request, HttpResponse.BodyHandler.asString()).get().body());
+ // client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).get().body());
CompletableFuture<HttpResponse<InputStream>> handle =
- client.sendAsync(request, HttpResponse.BodyHandler.asInputStream());
+ client.sendAsync(request, BodyHandlers.ofInputStream());
if (DEBUG) err.println("Request sent");
HttpResponse<InputStream> pending = handle.get();
--- a/test/jdk/java/net/httpclient/BufferingSubscriberCancelTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/BufferingSubscriberCancelTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -39,7 +39,7 @@
import static java.lang.System.out;
import static java.nio.ByteBuffer.wrap;
import static java.util.concurrent.TimeUnit.SECONDS;
-import static java.net.http.HttpResponse.BodySubscriber.buffering;
+import static java.net.http.HttpResponse.BodySubscribers.buffering;
import static org.testng.Assert.*;
/*
--- a/test/jdk/java/net/httpclient/BufferingSubscriberErrorCompleteTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/BufferingSubscriberErrorCompleteTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,24 +25,19 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletionStage;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Flow.Subscription;
import java.util.concurrent.Phaser;
import java.util.concurrent.SubmissionPublisher;
-import java.util.function.IntSupplier;
import java.util.stream.IntStream;
import java.net.http.HttpResponse.BodySubscriber;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static java.lang.Long.MAX_VALUE;
import static java.lang.Long.MIN_VALUE;
-import static java.lang.System.out;
import static java.nio.ByteBuffer.wrap;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static java.net.http.HttpResponse.BodySubscriber.buffering;
+import static java.net.http.HttpResponse.BodySubscribers.buffering;
import static org.testng.Assert.*;
/*
--- a/test/jdk/java/net/httpclient/BufferingSubscriberTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/BufferingSubscriberTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,9 @@
import java.util.concurrent.SubmissionPublisher;
import java.util.function.BiConsumer;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import jdk.test.lib.RandomFactory;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -87,8 +89,8 @@
public void subscriberThrowsIAE(int bufferSize) {
printStamp(START, "subscriberThrowsIAE(%d)", bufferSize);
try {
- BodySubscriber<?> bp = BodySubscriber.asByteArray();
- BodySubscriber.buffering(bp, bufferSize);
+ BodySubscriber<?> bp = BodySubscribers.ofByteArray();
+ BodySubscribers.buffering(bp, bufferSize);
} finally {
printStamp(END, "subscriberThrowsIAE(%d)", bufferSize);
}
@@ -98,8 +100,8 @@
public void handlerThrowsIAE(int bufferSize) {
printStamp(START, "handlerThrowsIAE(%d)", bufferSize);
try {
- BodyHandler<?> bp = BodyHandler.asByteArray();
- BodyHandler.buffering(bp, bufferSize);
+ BodyHandler<?> bp = BodyHandlers.ofByteArray();
+ BodyHandlers.buffering(bp, bufferSize);
} finally {
printStamp(END, "handlerThrowsIAE(%d)", bufferSize);
}
@@ -242,7 +244,7 @@
delay,
expectedTotalSize,
requestAmount);
- return BodySubscriber.buffering(s, bufferSize);
+ return BodySubscribers.buffering(s, bufferSize);
}
private void requestMore() {
--- a/test/jdk/java/net/httpclient/CancelledResponse.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/CancelledResponse.java Sat Feb 24 11:27:11 2018 +0000
@@ -160,11 +160,11 @@
try {
if (async) {
out.println("send async: " + request);
- cf1 = client.sendAsync(request, asString(body, cancelled));
+ cf1 = client.sendAsync(request, ofString(body, cancelled));
r = cf1.get();
} else { // sync
out.println("send sync: " + request);
- r = client.send(request, asString(body, cancelled));
+ r = client.send(request, ofString(body, cancelled));
}
} catch (CancelException c1) {
System.out.println("Got expected exception: " + c1);
@@ -294,7 +294,7 @@
}
}
- BodyHandler<String> asString(String expected, AtomicBoolean cancelled) {
+ BodyHandler<String> ofString(String expected, AtomicBoolean cancelled) {
return new CancellingHandler(expected, cancelled);
}
--- a/test/jdk/java/net/httpclient/ConcurrentResponses.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ConcurrentResponses.java Sat Feb 24 11:27:11 2018 +0000
@@ -61,15 +61,16 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import jdk.testlibrary.SimpleSSLContext;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpResponse.BodyHandler.asString;
-import static java.net.http.HttpResponse.BodyHandler.discard;
+import static java.net.http.HttpResponse.BodyHandlers.discarding;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.fail;
@@ -144,7 +145,7 @@
}
- // The asString implementation accumulates data, below a certain threshold
+ // The ofString implementation accumulates data, below a certain threshold
// into the byte buffers it is given.
@Test(dataProvider = "uris")
void testAsString(String uri) throws Exception {
@@ -158,11 +159,11 @@
}
// initial connection to seed the cache so next parallel connections reuse it
- client.sendAsync(HttpRequest.newBuilder(URI.create(uri)).build(), discard()).join();
+ client.sendAsync(HttpRequest.newBuilder(URI.create(uri)).build(), discarding()).join();
// will reuse connection cached from the previous request ( when HTTP/2 )
CompletableFuture.allOf(requests.keySet().parallelStream()
- .map(request -> client.sendAsync(request, asString()))
+ .map(request -> client.sendAsync(request, BodyHandlers.ofString()))
.map(cf -> cf.thenCompose(ConcurrentResponses::assert200ResponseCode))
.map(cf -> cf.thenCompose(response -> assertbody(response, requests.get(response.request()))))
.toArray(CompletableFuture<?>[]::new))
@@ -183,7 +184,7 @@
}
// initial connection to seed the cache so next parallel connections reuse it
- client.sendAsync(HttpRequest.newBuilder(URI.create(uri)).build(), discard()).join();
+ client.sendAsync(HttpRequest.newBuilder(URI.create(uri)).build(), discarding()).join();
// will reuse connection cached from the previous request ( when HTTP/2 )
CompletableFuture.allOf(requests.keySet().parallelStream()
@@ -195,21 +196,21 @@
}
/**
- * A subscriber that wraps asString, but mucks with any data between limit
+ * A subscriber that wraps ofString, but mucks with any data between limit
* and capacity, if the client mistakenly passes it any that is should not.
*/
static class CustomSubscriber implements BodySubscriber<String> {
static final BodyHandler<String> handler = (r,h) -> new CustomSubscriber();
- private final BodySubscriber<String> asString = BodySubscriber.asString(UTF_8);
+ private final BodySubscriber<String> ofString = BodySubscribers.ofString(UTF_8);
@Override
public CompletionStage<String> getBody() {
- return asString.getBody();
+ return ofString.getBody();
}
@Override
public void onSubscribe(Flow.Subscription subscription) {
- asString.onSubscribe(subscription);
+ ofString.onSubscribe(subscription);
}
@Override
@@ -231,19 +232,19 @@
buffer.limit(limit); // restore original limit
}
}
- asString.onNext(buffers);
+ ofString.onNext(buffers);
}
@Override
public void onError(Throwable throwable) {
- asString.onError(throwable);
+ ofString.onError(throwable);
throwable.printStackTrace();
fail("UNEXPECTED:" + throwable);
}
@Override
public void onComplete() {
- asString.onComplete();
+ ofString.onComplete();
}
}
--- a/test/jdk/java/net/httpclient/CustomRequestPublisher.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/CustomRequestPublisher.java Sat Feb 24 11:27:11 2018 +0000
@@ -70,7 +70,7 @@
import static java.net.http.HttpClient.Version.HTTP_1_1;
import static java.net.http.HttpClient.Version.HTTP_2;
import static java.nio.charset.StandardCharsets.US_ASCII;
-import static java.net.http.HttpResponse.BodyHandler.asString;
+import static java.net.http.HttpResponse.BodyHandlers.ofString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -151,7 +151,7 @@
.POST(bodyPublisher)
.build();
- HttpResponse<String> resp = client.send(request, asString());
+ HttpResponse<String> resp = client.send(request, ofString());
out.println("Got response: " + resp);
out.println("Got body: " + resp.body());
@@ -177,7 +177,7 @@
.POST(bodyPublisher)
.build();
- CompletableFuture<HttpResponse<String>> cf = client.sendAsync(request, asString());
+ CompletableFuture<HttpResponse<String>> cf = client.sendAsync(request, ofString());
HttpResponse<String> resp = cf.get();
out.println("Got response: " + resp);
--- a/test/jdk/java/net/httpclient/CustomResponseSubscriber.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/CustomResponseSubscriber.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -53,7 +53,8 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
-import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import javax.net.ssl.SSLContext;
import jdk.testlibrary.SimpleSSLContext;
import org.testng.annotations.AfterTest;
@@ -62,7 +63,6 @@
import org.testng.annotations.Test;
import static java.lang.System.out;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpResponse.BodySubscriber.asString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -141,40 +141,40 @@
}
static class CRSBodySubscriber implements BodySubscriber<String> {
- private final BodySubscriber<String> asString = asString(UTF_8);
+ private final BodySubscriber<String> ofString = BodySubscribers.ofString(UTF_8);
volatile boolean onSubscribeCalled;
@Override
public void onSubscribe(Flow.Subscription subscription) {
//out.println("onSubscribe ");
onSubscribeCalled = true;
- asString.onSubscribe(subscription);
+ ofString.onSubscribe(subscription);
}
@Override
public void onNext(List<ByteBuffer> item) {
// out.println("onNext " + item);
assertTrue(onSubscribeCalled);
- asString.onNext(item);
+ ofString.onNext(item);
}
@Override
public void onError(Throwable throwable) {
//out.println("onError");
assertTrue(onSubscribeCalled);
- asString.onError(throwable);
+ ofString.onError(throwable);
}
@Override
public void onComplete() {
//out.println("onComplete");
assertTrue(onSubscribeCalled, "onComplete called before onSubscribe");
- asString.onComplete();
+ ofString.onComplete();
}
@Override
public CompletionStage<String> getBody() {
- return asString.getBody();
+ return ofString.getBody();
}
}
--- a/test/jdk/java/net/httpclient/DigestEchoClient.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/DigestEchoClient.java Sat Feb 24 11:27:11 2018 +0000
@@ -26,6 +26,14 @@
import java.math.BigInteger;
import java.net.ProxySelector;
import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpClient.Version;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublisher;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -43,16 +51,11 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.net.ssl.SSLContext;
-import java.net.http.HttpClient;
-import java.net.http.HttpClient.Version;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
import jdk.testlibrary.SimpleSSLContext;
import sun.net.NetProperties;
import sun.net.www.HeaderParser;
import static java.lang.System.out;
import static java.lang.String.format;
-import static java.net.http.HttpResponse.BodyHandler.asLines;
/**
* @test
@@ -382,7 +385,7 @@
List<String> lines = List.of(Arrays.copyOfRange(data, 0, i+1));
assert lines.size() == i + 1;
String body = lines.stream().collect(Collectors.joining("\r\n"));
- HttpRequest.BodyPublisher reqBody = HttpRequest.BodyPublisher.fromString(body);
+ BodyPublisher reqBody = BodyPublishers.ofString(body);
HttpRequest.Builder builder = HttpRequest.newBuilder(uri).version(clientVersion)
.POST(reqBody).expectContinue(expectContinue);
boolean isTunnel = isProxy(authType) && useSSL;
@@ -415,9 +418,9 @@
HttpResponse<Stream<String>> resp;
try {
if (async) {
- resp = client.sendAsync(request, asLines()).join();
+ resp = client.sendAsync(request, BodyHandlers.ofLines()).join();
} else {
- resp = client.send(request, asLines());
+ resp = client.send(request, BodyHandlers.ofLines());
}
} catch (Throwable t) {
long stop = System.nanoTime();
@@ -445,9 +448,9 @@
request = HttpRequest.newBuilder(uri).version(clientVersion)
.POST(reqBody).header(authorizationKey(authType), auth).build();
if (async) {
- resp = client.sendAsync(request, asLines()).join();
+ resp = client.sendAsync(request, BodyHandlers.ofLines()).join();
} else {
- resp = client.send(request, asLines());
+ resp = client.send(request, BodyHandlers.ofLines());
}
}
final List<String> respLines;
@@ -525,7 +528,7 @@
List<String> lines = List.of(Arrays.copyOfRange(data, 0, i+1));
assert lines.size() == i + 1;
String body = lines.stream().collect(Collectors.joining("\r\n"));
- HttpRequest.BodyPublisher reqBody = HttpRequest.BodyPublisher.fromString(body);
+ HttpRequest.BodyPublisher reqBody = HttpRequest.BodyPublishers.ofString(body);
HttpRequest.Builder reqBuilder = HttpRequest
.newBuilder(uri).version(clientVersion).POST(reqBody)
.expectContinue(expectContinue);
@@ -550,9 +553,9 @@
HttpRequest request = reqBuilder.build();
HttpResponse<Stream<String>> resp;
if (async) {
- resp = client.sendAsync(request, asLines()).join();
+ resp = client.sendAsync(request, BodyHandlers.ofLines()).join();
} else {
- resp = client.send(request, asLines());
+ resp = client.send(request, BodyHandlers.ofLines());
}
System.out.println(resp);
assert challenge != null || resp.statusCode() == 401 || resp.statusCode() == 407
@@ -589,9 +592,9 @@
}
if (async) {
- resp = client.sendAsync(request, asLines()).join();
+ resp = client.sendAsync(request, BodyHandlers.ofLines()).join();
} else {
- resp = client.send(request, asLines());
+ resp = client.send(request, BodyHandlers.ofLines());
}
System.out.println(resp);
}
--- a/test/jdk/java/net/httpclient/FlowAdapterPublisherTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/FlowAdapterPublisherTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -50,8 +50,8 @@
import javax.net.ssl.SSLContext;
import static java.util.stream.Collectors.joining;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpRequest.BodyPublisher.fromPublisher;
-import static java.net.http.HttpResponse.BodyHandler.asString;
+import static java.net.http.HttpRequest.BodyPublishers.fromPublisher;
+import static java.net.http.HttpResponse.BodyHandlers.ofString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;
@@ -119,7 +119,7 @@
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.POST(fromPublisher(new BBPublisher(body))).build();
- HttpResponse<String> response = client.sendAsync(request, asString(UTF_8)).join();
+ HttpResponse<String> response = client.sendAsync(request, ofString(UTF_8)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -135,7 +135,7 @@
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.POST(fromPublisher(new BBPublisher(body), cl)).build();
- HttpResponse<String> response = client.sendAsync(request, asString(UTF_8)).join();
+ HttpResponse<String> response = client.sendAsync(request, ofString(UTF_8)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -152,7 +152,7 @@
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.POST(fromPublisher(new MBBPublisher(body))).build();
- HttpResponse<String> response = client.sendAsync(request, asString(UTF_8)).join();
+ HttpResponse<String> response = client.sendAsync(request, ofString(UTF_8)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -168,7 +168,7 @@
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.POST(fromPublisher(new MBBPublisher(body), cl)).build();
- HttpResponse<String> response = client.sendAsync(request, asString(UTF_8)).join();
+ HttpResponse<String> response = client.sendAsync(request, ofString(UTF_8)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -189,7 +189,7 @@
.POST(fromPublisher(new BBPublisher(body), cl)).build();
try {
- HttpResponse<String> response = client.send(request, asString(UTF_8));
+ HttpResponse<String> response = client.send(request, ofString(UTF_8));
fail("Unexpected response: " + response);
} catch (IOException expected) {
assertMessage(expected, "Too few bytes returned");
@@ -206,7 +206,7 @@
.POST(fromPublisher(new BBPublisher(body), cl)).build();
try {
- HttpResponse<String> response = client.send(request, asString(UTF_8));
+ HttpResponse<String> response = client.send(request, ofString(UTF_8));
fail("Unexpected response: " + response);
} catch (IOException expected) {
assertMessage(expected, "Too many bytes in request body");
--- a/test/jdk/java/net/httpclient/FlowAdapterSubscriberTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/FlowAdapterSubscriberTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -43,9 +43,10 @@
import com.sun.net.httpserver.HttpsServer;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodyHandler;
-import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodyHandlers;
+import java.net.http.HttpResponse.BodySubscribers;
import jdk.testlibrary.SimpleSSLContext;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
@@ -53,9 +54,6 @@
import org.testng.annotations.Test;
import javax.net.ssl.SSLContext;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodySubscriber.asByteArray;
-import static java.net.http.HttpResponse.BodySubscriber.asInputStream;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;
@@ -110,17 +108,17 @@
@Test
public void testNull() {
System.out.printf(now() + "testNull() starting%n");
- assertThrows(NPE, () -> BodyHandler.fromSubscriber(null));
- assertThrows(NPE, () -> BodyHandler.fromSubscriber(null, Function.identity()));
- assertThrows(NPE, () -> BodyHandler.fromSubscriber(new ListSubscriber(), null));
- assertThrows(NPE, () -> BodyHandler.fromSubscriber(null, null));
+ assertThrows(NPE, () -> BodyHandlers.fromSubscriber(null));
+ assertThrows(NPE, () -> BodyHandlers.fromSubscriber(null, Function.identity()));
+ assertThrows(NPE, () -> BodyHandlers.fromSubscriber(new ListSubscriber(), null));
+ assertThrows(NPE, () -> BodyHandlers.fromSubscriber(null, null));
- assertThrows(NPE, () -> BodySubscriber.fromSubscriber(null));
- assertThrows(NPE, () -> BodySubscriber.fromSubscriber(null, Function.identity()));
- assertThrows(NPE, () -> BodySubscriber.fromSubscriber(new ListSubscriber(), null));
- assertThrows(NPE, () -> BodySubscriber.fromSubscriber(null, null));
+ assertThrows(NPE, () -> BodySubscribers.fromSubscriber(null));
+ assertThrows(NPE, () -> BodySubscribers.fromSubscriber(null, Function.identity()));
+ assertThrows(NPE, () -> BodySubscribers.fromSubscriber(new ListSubscriber(), null));
+ assertThrows(NPE, () -> BodySubscribers.fromSubscriber(null, null));
- Subscriber subscriber = BodySubscriber.fromSubscriber(new ListSubscriber());
+ Subscriber subscriber = BodySubscribers.fromSubscriber(new ListSubscriber());
assertThrows(NPE, () -> subscriber.onSubscribe(null));
assertThrows(NPE, () -> subscriber.onNext(null));
assertThrows(NPE, () -> subscriber.onError(null));
@@ -133,11 +131,11 @@
System.out.printf(now() + "testListWithFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the luck of the Irish be with you!")).build();
+ .POST(BodyPublishers.ofString("May the luck of the Irish be with you!")).build();
ListSubscriber subscriber = new ListSubscriber();
HttpResponse<String> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber, Supplier::get)).join();
+ BodyHandlers.fromSubscriber(subscriber, Supplier::get)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -149,11 +147,11 @@
System.out.printf(now() + "testListWithoutFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the luck of the Irish be with you!")).build();
+ .POST(BodyPublishers.ofString("May the luck of the Irish be with you!")).build();
ListSubscriber subscriber = new ListSubscriber();
HttpResponse<Void> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber)).join();
+ BodyHandlers.fromSubscriber(subscriber)).join();
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -165,11 +163,11 @@
System.out.printf(now() + "testListWithFinisherBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the luck of the Irish be with you!")).build();
+ .POST(BodyPublishers.ofString("May the luck of the Irish be with you!")).build();
ListSubscriber subscriber = new ListSubscriber();
HttpResponse<String> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber, Supplier::get));
+ BodyHandlers.fromSubscriber(subscriber, Supplier::get));
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -181,11 +179,11 @@
System.out.printf(now() + "testListWithoutFinisherBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the luck of the Irish be with you!")).build();
+ .POST(BodyPublishers.ofString("May the luck of the Irish be with you!")).build();
ListSubscriber subscriber = new ListSubscriber();
HttpResponse<Void> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber));
+ BodyHandlers.fromSubscriber(subscriber));
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -199,11 +197,11 @@
System.out.printf(now() + "testCollectionWithFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("What's the craic?")).build();
+ .POST(BodyPublishers.ofString("What's the craic?")).build();
CollectionSubscriber subscriber = new CollectionSubscriber();
HttpResponse<String> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber, CollectionSubscriber::get)).join();
+ BodyHandlers.fromSubscriber(subscriber, CollectionSubscriber::get)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -215,11 +213,11 @@
System.out.printf(now() + "testCollectionWithoutFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("What's the craic?")).build();
+ .POST(BodyPublishers.ofString("What's the craic?")).build();
CollectionSubscriber subscriber = new CollectionSubscriber();
HttpResponse<Void> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber)).join();
+ BodyHandlers.fromSubscriber(subscriber)).join();
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -231,11 +229,11 @@
System.out.printf(now() + "testCollectionWithFinisherBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("What's the craic?")).build();
+ .POST(BodyPublishers.ofString("What's the craic?")).build();
CollectionSubscriber subscriber = new CollectionSubscriber();
HttpResponse<String> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber, CollectionSubscriber::get));
+ BodyHandlers.fromSubscriber(subscriber, CollectionSubscriber::get));
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -247,11 +245,11 @@
System.out.printf(now() + "testCollectionWithoutFinisheBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("What's the craic?")).build();
+ .POST(BodyPublishers.ofString("What's the craic?")).build();
CollectionSubscriber subscriber = new CollectionSubscriber();
HttpResponse<Void> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber));
+ BodyHandlers.fromSubscriber(subscriber));
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -265,11 +263,11 @@
System.out.printf(now() + "testIterableWithFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("We're sucking diesel now!")).build();
+ .POST(BodyPublishers.ofString("We're sucking diesel now!")).build();
IterableSubscriber subscriber = new IterableSubscriber();
HttpResponse<String> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber, Supplier::get)).join();
+ BodyHandlers.fromSubscriber(subscriber, Supplier::get)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -281,11 +279,11 @@
System.out.printf(now() + "testIterableWithoutFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("We're sucking diesel now!")).build();
+ .POST(BodyPublishers.ofString("We're sucking diesel now!")).build();
IterableSubscriber subscriber = new IterableSubscriber();
HttpResponse<Void> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber)).join();
+ BodyHandlers.fromSubscriber(subscriber)).join();
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -297,11 +295,11 @@
System.out.printf(now() + "testIterableWithFinisherBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("We're sucking diesel now!")).build();
+ .POST(BodyPublishers.ofString("We're sucking diesel now!")).build();
IterableSubscriber subscriber = new IterableSubscriber();
HttpResponse<String> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber, Supplier::get));
+ BodyHandlers.fromSubscriber(subscriber, Supplier::get));
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -313,11 +311,11 @@
System.out.printf(now() + "testIterableWithoutFinisherBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("We're sucking diesel now!")).build();
+ .POST(BodyPublishers.ofString("We're sucking diesel now!")).build();
IterableSubscriber subscriber = new IterableSubscriber();
HttpResponse<Void> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber));
+ BodyHandlers.fromSubscriber(subscriber));
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -331,11 +329,11 @@
System.out.printf(now() + "testObjectWithFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the wind always be at your back.")).build();
+ .POST(BodyPublishers.ofString("May the wind always be at your back.")).build();
ObjectSubscriber subscriber = new ObjectSubscriber();
HttpResponse<String> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber, ObjectSubscriber::get)).join();
+ BodyHandlers.fromSubscriber(subscriber, ObjectSubscriber::get)).join();
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -347,11 +345,11 @@
System.out.printf(now() + "testObjectWithoutFinisher(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the wind always be at your back.")).build();
+ .POST(BodyPublishers.ofString("May the wind always be at your back.")).build();
ObjectSubscriber subscriber = new ObjectSubscriber();
HttpResponse<Void> response = client.sendAsync(request,
- BodyHandler.fromSubscriber(subscriber)).join();
+ BodyHandlers.fromSubscriber(subscriber)).join();
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -363,11 +361,11 @@
System.out.printf(now() + "testObjectWithFinisherBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the wind always be at your back.")).build();
+ .POST(BodyPublishers.ofString("May the wind always be at your back.")).build();
ObjectSubscriber subscriber = new ObjectSubscriber();
HttpResponse<String> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber, ObjectSubscriber::get));
+ BodyHandlers.fromSubscriber(subscriber, ObjectSubscriber::get));
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -379,11 +377,11 @@
System.out.printf(now() + "testObjectWithoutFinisherBlocking(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the wind always be at your back.")).build();
+ .POST(BodyPublishers.ofString("May the wind always be at your back.")).build();
ObjectSubscriber subscriber = new ObjectSubscriber();
HttpResponse<Void> response = client.send(request,
- BodyHandler.fromSubscriber(subscriber));
+ BodyHandlers.fromSubscriber(subscriber));
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -398,9 +396,9 @@
System.out.printf(now() + "mappingFromByteArray(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("We're sucking diesel now!")).build();
+ .POST(BodyPublishers.ofString("We're sucking diesel now!")).build();
- client.sendAsync(request, BodyHandler.fromSubscriber(asByteArray(),
+ client.sendAsync(request, BodyHandlers.fromSubscriber(BodySubscribers.ofByteArray(),
bas -> new String(bas.getBody().toCompletableFuture().join(), UTF_8)))
.thenApply(FlowAdapterSubscriberTest::assert200ResponseCode)
.thenApply(HttpResponse::body)
@@ -413,9 +411,9 @@
System.out.printf(now() + "mappingFromInputStream(%s) starting%n", url);
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString("May the wind always be at your back.")).build();
+ .POST(BodyPublishers.ofString("May the wind always be at your back.")).build();
- client.sendAsync(request, BodyHandler.fromSubscriber(asInputStream(),
+ client.sendAsync(request, BodyHandlers.fromSubscriber(BodySubscribers.ofInputStream(),
ins -> {
InputStream is = ins.getBody().toCompletableFuture().join();
return new String(uncheckedReadAllBytes(is), UTF_8); } ))
--- a/test/jdk/java/net/httpclient/FlowAdaptersCompileOnly.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/FlowAdaptersCompileOnly.java Sat Feb 24 11:27:11 2018 +0000
@@ -30,9 +30,11 @@
import java.util.List;
import java.util.concurrent.Flow;
import java.util.function.Function;
-import java.net.http.HttpRequest.BodyPublisher;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
/*
* @test
@@ -43,31 +45,31 @@
public class FlowAdaptersCompileOnly {
static void makesSureDifferentGenericSignaturesCompile() {
- BodyPublisher.fromPublisher(new BBPublisher());
- BodyPublisher.fromPublisher(new MBBPublisher());
+ BodyPublishers.fromPublisher(new BBPublisher());
+ BodyPublishers.fromPublisher(new MBBPublisher());
- BodyHandler.fromSubscriber(new ListSubscriber());
- BodyHandler.fromSubscriber(new CollectionSubscriber());
- BodyHandler.fromSubscriber(new IterableSubscriber());
- BodyHandler.fromSubscriber(new ObjectSubscriber());
+ BodyHandlers.fromSubscriber(new ListSubscriber());
+ BodyHandlers.fromSubscriber(new CollectionSubscriber());
+ BodyHandlers.fromSubscriber(new IterableSubscriber());
+ BodyHandlers.fromSubscriber(new ObjectSubscriber());
- BodySubscriber.fromSubscriber(new ListSubscriber());
- BodySubscriber.fromSubscriber(new CollectionSubscriber());
- BodySubscriber.fromSubscriber(new IterableSubscriber());
- BodySubscriber.fromSubscriber(new ObjectSubscriber());
+ BodySubscribers.fromSubscriber(new ListSubscriber());
+ BodySubscribers.fromSubscriber(new CollectionSubscriber());
+ BodySubscribers.fromSubscriber(new IterableSubscriber());
+ BodySubscribers.fromSubscriber(new ObjectSubscriber());
- BodyPublisher.fromPublisher(new BBPublisher(), 1);
- BodyPublisher.fromPublisher(new MBBPublisher(), 1);
+ BodyPublishers.fromPublisher(new BBPublisher(), 1);
+ BodyPublishers.fromPublisher(new MBBPublisher(), 1);
- BodyHandler.fromSubscriber(new ListSubscriber(), Function.identity());
- BodyHandler.fromSubscriber(new CollectionSubscriber(), Function.identity());
- BodyHandler.fromSubscriber(new IterableSubscriber(), Function.identity());
- BodyHandler.fromSubscriber(new ObjectSubscriber(), Function.identity());
+ BodyHandlers.fromSubscriber(new ListSubscriber(), Function.identity());
+ BodyHandlers.fromSubscriber(new CollectionSubscriber(), Function.identity());
+ BodyHandlers.fromSubscriber(new IterableSubscriber(), Function.identity());
+ BodyHandlers.fromSubscriber(new ObjectSubscriber(), Function.identity());
- BodySubscriber.fromSubscriber(new ListSubscriber(), Function.identity());
- BodySubscriber.fromSubscriber(new CollectionSubscriber(), Function.identity());
- BodySubscriber.fromSubscriber(new IterableSubscriber(), Function.identity());
- BodySubscriber.fromSubscriber(new ObjectSubscriber(), Function.identity());
+ BodySubscribers.fromSubscriber(new ListSubscriber(), Function.identity());
+ BodySubscribers.fromSubscriber(new CollectionSubscriber(), Function.identity());
+ BodySubscribers.fromSubscriber(new IterableSubscriber(), Function.identity());
+ BodySubscribers.fromSubscriber(new ObjectSubscriber(), Function.identity());
}
static class BBPublisher implements Flow.Publisher<ByteBuffer> {
@@ -120,33 +122,33 @@
}
static void makesSureDifferentGenericFunctionSignaturesCompile() {
- BodyHandler<Integer> bh01 = BodyHandler.fromSubscriber(new ListSubscriber(), s -> 6);
- BodyHandler<Number> bh02 = BodyHandler.fromSubscriber(new ListSubscriber(), s -> 7);
- BodyHandler<Integer> bh03 = BodyHandler.fromSubscriber(new ListSubscriber(), f1);
- BodyHandler<Number> bh04 = BodyHandler.fromSubscriber(new ListSubscriber(), f1);
- BodyHandler<Number> bh05 = BodyHandler.fromSubscriber(new ListSubscriber(), f2);
- BodyHandler<Integer> bh06 = BodyHandler.fromSubscriber(new ListSubscriberX(), f1);
- BodyHandler<Number> bh07 = BodyHandler.fromSubscriber(new ListSubscriberX(), f1);
- BodyHandler<Number> bh08 = BodyHandler.fromSubscriber(new ListSubscriberX(), f2);
- BodyHandler<Integer> bh09 = BodyHandler.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
- BodyHandler<Number> bh10 = BodyHandler.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
- BodyHandler<Integer> bh11 = BodyHandler.fromSubscriber(new ListSubscriberX(), f3);
- BodyHandler<Number> bh12 = BodyHandler.fromSubscriber(new ListSubscriberX(), f3);
- BodyHandler<Number> bh13 = BodyHandler.fromSubscriber(new ListSubscriberX(), f4);
+ BodyHandler<Integer> bh01 = BodyHandlers.fromSubscriber(new ListSubscriber(), s -> 6);
+ BodyHandler<Number> bh02 = BodyHandlers.fromSubscriber(new ListSubscriber(), s -> 7);
+ BodyHandler<Integer> bh03 = BodyHandlers.fromSubscriber(new ListSubscriber(), f1);
+ BodyHandler<Number> bh04 = BodyHandlers.fromSubscriber(new ListSubscriber(), f1);
+ BodyHandler<Number> bh05 = BodyHandlers.fromSubscriber(new ListSubscriber(), f2);
+ BodyHandler<Integer> bh06 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f1);
+ BodyHandler<Number> bh07 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f1);
+ BodyHandler<Number> bh08 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f2);
+ BodyHandler<Integer> bh09 = BodyHandlers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
+ BodyHandler<Number> bh10 = BodyHandlers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
+ BodyHandler<Integer> bh11 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f3);
+ BodyHandler<Number> bh12 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f3);
+ BodyHandler<Number> bh13 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f4);
- BodySubscriber<Integer> bs01 = BodySubscriber.fromSubscriber(new ListSubscriber(), s -> 6);
- BodySubscriber<Number> bs02 = BodySubscriber.fromSubscriber(new ListSubscriber(), s -> 7);
- BodySubscriber<Integer> bs03 = BodySubscriber.fromSubscriber(new ListSubscriber(), f1);
- BodySubscriber<Number> bs04 = BodySubscriber.fromSubscriber(new ListSubscriber(), f1);
- BodySubscriber<Number> bs05 = BodySubscriber.fromSubscriber(new ListSubscriber(), f2);
- BodySubscriber<Integer> bs06 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f1);
- BodySubscriber<Number> bs07 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f1);
- BodySubscriber<Number> bs08 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f2);
- BodySubscriber<Integer> bs09 = BodySubscriber.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
- BodySubscriber<Number> bs10 = BodySubscriber.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
- BodySubscriber<Integer> bs11 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f3);
- BodySubscriber<Number> bs12 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f3);
- BodySubscriber<Number> bs13 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f4);
+ BodySubscriber<Integer> bs01 = BodySubscribers.fromSubscriber(new ListSubscriber(), s -> 6);
+ BodySubscriber<Number> bs02 = BodySubscribers.fromSubscriber(new ListSubscriber(), s -> 7);
+ BodySubscriber<Integer> bs03 = BodySubscribers.fromSubscriber(new ListSubscriber(), f1);
+ BodySubscriber<Number> bs04 = BodySubscribers.fromSubscriber(new ListSubscriber(), f1);
+ BodySubscriber<Number> bs05 = BodySubscribers.fromSubscriber(new ListSubscriber(), f2);
+ BodySubscriber<Integer> bs06 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f1);
+ BodySubscriber<Number> bs07 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f1);
+ BodySubscriber<Number> bs08 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f2);
+ BodySubscriber<Integer> bs09 = BodySubscribers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
+ BodySubscriber<Number> bs10 = BodySubscribers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX);
+ BodySubscriber<Integer> bs11 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f3);
+ BodySubscriber<Number> bs12 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f3);
+ BodySubscriber<Number> bs13 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f4);
}
// ---
@@ -186,16 +188,16 @@
HttpRequest request = null;
IntegerSubscriber sub1 = new IntegerSubscriber();
- HttpResponse<Integer> r1 = client.send(request, BodyHandler.fromSubscriber(sub1, IntegerSubscriber::getInteger));
- HttpResponse<Number> r2 = client.send(request, BodyHandler.fromSubscriber(sub1, IntegerSubscriber::getInteger));
- HttpResponse<Number> r3 = client.send(request, BodyHandler.fromSubscriber(sub1, NumberSubscriber::getNumber));
- HttpResponse<Integer> r4 = client.send(request, BodyHandler.fromSubscriber(sub1, intMapper));
- HttpResponse<Number> r5 = client.send(request, BodyHandler.fromSubscriber(sub1, intMapper));
- HttpResponse<Number> r6 = client.send(request, BodyHandler.fromSubscriber(sub1, numMapper));
+ HttpResponse<Integer> r1 = client.send(request, BodyHandlers.fromSubscriber(sub1, IntegerSubscriber::getInteger));
+ HttpResponse<Number> r2 = client.send(request, BodyHandlers.fromSubscriber(sub1, IntegerSubscriber::getInteger));
+ HttpResponse<Number> r3 = client.send(request, BodyHandlers.fromSubscriber(sub1, NumberSubscriber::getNumber));
+ HttpResponse<Integer> r4 = client.send(request, BodyHandlers.fromSubscriber(sub1, intMapper));
+ HttpResponse<Number> r5 = client.send(request, BodyHandlers.fromSubscriber(sub1, intMapper));
+ HttpResponse<Number> r6 = client.send(request, BodyHandlers.fromSubscriber(sub1, numMapper));
// compiles but makes little sense. Just what you get with any usage of `? super`
final Function<Object,Number> objectMapper = sub -> 1;
- client.sendAsync(request, BodyHandler.fromSubscriber(sub1, objectMapper));
+ client.sendAsync(request, BodyHandlers.fromSubscriber(sub1, objectMapper));
// does not compile, as expected ( uncomment to see )
//HttpResponse<Number> r7 = client.send(request, BodyHandler.fromSubscriber(sub1, longMapper));
--- a/test/jdk/java/net/httpclient/HandshakeFailureTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/HandshakeFailureTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -39,7 +39,7 @@
import java.net.http.HttpResponse;
import java.net.http.HttpRequest;
import static java.lang.System.out;
-import static java.net.http.HttpResponse.BodyHandler.discard;
+import static java.net.http.HttpResponse.BodyHandlers.discarding;
/**
* @test
@@ -87,7 +87,7 @@
.version(version)
.build();
try {
- HttpResponse<Void> response = client.send(request, discard());
+ HttpResponse<Void> response = client.send(request, discarding());
String msg = String.format("UNEXPECTED response=%s%n", response);
throw new RuntimeException(msg);
} catch (SSLHandshakeException expected) {
@@ -106,7 +106,7 @@
.version(version)
.build();
try {
- HttpResponse<Void> response = client.send(request, discard());
+ HttpResponse<Void> response = client.send(request, discarding());
String msg = String.format("UNEXPECTED response=%s%n", response);
throw new RuntimeException(msg);
} catch (SSLHandshakeException expected) {
@@ -124,7 +124,7 @@
.version(version)
.build();
CompletableFuture<HttpResponse<Void>> response =
- client.sendAsync(request, discard());
+ client.sendAsync(request, discarding());
try {
response.join();
String msg = String.format("UNEXPECTED response=%s%n", response);
@@ -150,7 +150,7 @@
.version(version)
.build();
CompletableFuture<HttpResponse<Void>> response =
- client.sendAsync(request, discard());
+ client.sendAsync(request, discarding());
try {
response.join();
String msg = String.format("UNEXPECTED response=%s%n", response);
--- a/test/jdk/java/net/httpclient/HeadersTest1.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/HeadersTest1.java Sat Feb 24 11:27:11 2018 +0000
@@ -48,7 +48,7 @@
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import org.testng.annotations.Test;
-import static java.net.http.HttpResponse.BodyHandler.asString;
+import static java.net.http.HttpResponse.BodyHandlers.ofString;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -82,7 +82,7 @@
.GET()
.build();
- HttpResponse<?> resp = client.send(req, asString());
+ HttpResponse<?> resp = client.send(req, ofString());
if (resp.statusCode() != 200) {
throw new RuntimeException("Expected 200, got: " + resp.statusCode());
}
--- a/test/jdk/java/net/httpclient/HttpInputStreamTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/HttpInputStreamTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -293,11 +293,11 @@
// This example shows how to return an InputStream that can be used to
// start reading the response body before the response is fully received.
// In comparison, the snipet below (which uses
- // HttpResponse.BodyHandler.asString()) obviously will not return before the
+ // HttpResponse.BodyHandlers.ofString()) obviously will not return before the
// response body is fully read:
//
// System.out.println(
- // client.sendAsync(request, HttpResponse.BodyHandler.asString()).get().body());
+ // client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).get().body());
CompletableFuture<HttpResponse<InputStream>> handle =
client.sendAsync(request, new HttpInputStreamHandler(3));
--- a/test/jdk/java/net/httpclient/HttpRequestBuilderTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/HttpRequestBuilderTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -31,8 +31,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.net.http.HttpRequest;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpRequest.BodyPublisher.noBody;
+import static java.net.http.HttpRequest.BodyPublishers.ofString;
+import static java.net.http.HttpRequest.BodyPublishers.noBody;
/**
* @test
@@ -204,12 +204,12 @@
NullPointerException.class);
builder = test2("method", builder, builder::method, null,
- fromString("foo"),
+ ofString("foo"),
NullPointerException.class);
// see JDK-8170093
//
// builder = test2("method", builder, builder::method, "foo",
-// HttpRequest.BodyProcessor.fromString("foo"),
+// HttpRequest.BodyProcessor.ofString("foo"),
// IllegalArgumentException.class);
//
// builder.build();
@@ -223,40 +223,40 @@
() -> HttpRequest.newBuilder(TEST_URI).GET(),
"GET");
- method("newBuilder(TEST_URI).POST(fromString(\"\")).GET().build().method() == GET",
- () -> HttpRequest.newBuilder(TEST_URI).POST(fromString("")).GET(),
+ method("newBuilder(TEST_URI).POST(ofString(\"\")).GET().build().method() == GET",
+ () -> HttpRequest.newBuilder(TEST_URI).POST(ofString("")).GET(),
"GET");
- method("newBuilder(TEST_URI).PUT(fromString(\"\")).GET().build().method() == GET",
- () -> HttpRequest.newBuilder(TEST_URI).PUT(fromString("")).GET(),
+ method("newBuilder(TEST_URI).PUT(ofString(\"\")).GET().build().method() == GET",
+ () -> HttpRequest.newBuilder(TEST_URI).PUT(ofString("")).GET(),
"GET");
- method("newBuilder(TEST_URI).DELETE(fromString(\"\")).GET().build().method() == GET",
- () -> HttpRequest.newBuilder(TEST_URI).DELETE(fromString("")).GET(),
+ method("newBuilder(TEST_URI).DELETE(ofString(\"\")).GET().build().method() == GET",
+ () -> HttpRequest.newBuilder(TEST_URI).DELETE(ofString("")).GET(),
"GET");
- method("newBuilder(TEST_URI).POST(fromString(\"\")).build().method() == POST",
- () -> HttpRequest.newBuilder(TEST_URI).POST(fromString("")),
+ method("newBuilder(TEST_URI).POST(ofString(\"\")).build().method() == POST",
+ () -> HttpRequest.newBuilder(TEST_URI).POST(ofString("")),
"POST");
- method("newBuilder(TEST_URI).PUT(fromString(\"\")).build().method() == PUT",
- () -> HttpRequest.newBuilder(TEST_URI).PUT(fromString("")),
+ method("newBuilder(TEST_URI).PUT(ofString(\"\")).build().method() == PUT",
+ () -> HttpRequest.newBuilder(TEST_URI).PUT(ofString("")),
"PUT");
- method("newBuilder(TEST_URI).DELETE(fromString(\"\")).build().method() == DELETE",
- () -> HttpRequest.newBuilder(TEST_URI).DELETE(fromString("")),
+ method("newBuilder(TEST_URI).DELETE(ofString(\"\")).build().method() == DELETE",
+ () -> HttpRequest.newBuilder(TEST_URI).DELETE(ofString("")),
"DELETE");
- method("newBuilder(TEST_URI).GET().POST(fromString(\"\")).build().method() == POST",
- () -> HttpRequest.newBuilder(TEST_URI).GET().POST(fromString("")),
+ method("newBuilder(TEST_URI).GET().POST(ofString(\"\")).build().method() == POST",
+ () -> HttpRequest.newBuilder(TEST_URI).GET().POST(ofString("")),
"POST");
- method("newBuilder(TEST_URI).GET().PUT(fromString(\"\")).build().method() == PUT",
- () -> HttpRequest.newBuilder(TEST_URI).GET().PUT(fromString("")),
+ method("newBuilder(TEST_URI).GET().PUT(ofString(\"\")).build().method() == PUT",
+ () -> HttpRequest.newBuilder(TEST_URI).GET().PUT(ofString("")),
"PUT");
- method("newBuilder(TEST_URI).GET().DELETE(fromString(\"\")).build().method() == DELETE",
- () -> HttpRequest.newBuilder(TEST_URI).GET().DELETE(fromString("")),
+ method("newBuilder(TEST_URI).GET().DELETE(ofString(\"\")).build().method() == DELETE",
+ () -> HttpRequest.newBuilder(TEST_URI).GET().DELETE(ofString("")),
"DELETE");
--- a/test/jdk/java/net/httpclient/HttpResponseInputStreamTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/HttpResponseInputStreamTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -21,12 +21,12 @@
* questions.
*/
-import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodySubscriber;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -63,7 +63,7 @@
@Test
public static void testOnError() throws InterruptedException, ExecutionException {
CountDownLatch latch = new CountDownLatch(1);
- BodySubscriber<InputStream> isb = BodySubscriber.asInputStream();
+ BodySubscriber<InputStream> isb = BodySubscribers.ofInputStream();
ErrorTestSubscription s = new ErrorTestSubscription(isb);
CompletionStage<Throwable> cs =
isb.getBody().thenApplyAsync((is) -> s.accept(latch, is));
@@ -158,7 +158,7 @@
public static void testCloseAndSubscribe()
throws InterruptedException, ExecutionException
{
- BodySubscriber<InputStream> isb = BodySubscriber.asInputStream();
+ BodySubscriber<InputStream> isb = BodySubscribers.ofInputStream();
TestCancelOnCloseSubscription s = new TestCancelOnCloseSubscription();
InputStream is = isb.getBody()
.thenApply(HttpResponseInputStreamTest::close)
@@ -187,7 +187,7 @@
public static void testSubscribeAndClose()
throws InterruptedException, ExecutionException
{
- BodySubscriber<InputStream> isb = BodySubscriber.asInputStream();
+ BodySubscriber<InputStream> isb = BodySubscribers.ofInputStream();
TestCancelOnCloseSubscription s = new TestCancelOnCloseSubscription();
InputStream is = isb.getBody().toCompletableFuture().get();
isb.onSubscribe(s);
--- a/test/jdk/java/net/httpclient/HttpsTunnelTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/HttpsTunnelTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -32,14 +32,13 @@
import java.net.http.HttpClient.Version;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
import static java.lang.String.format;
import static java.lang.System.out;
-import static java.net.http.HttpResponse.BodyHandler.asLines;
/**
* @test
@@ -125,14 +124,14 @@
List<String> lines = List.of(Arrays.copyOfRange(data, 0, data.length));
assert lines.size() == data.length;
String body = lines.stream().collect(Collectors.joining("\r\n"));
- HttpRequest.BodyPublisher reqBody = HttpRequest.BodyPublisher.fromString(body);
+ HttpRequest.BodyPublisher reqBody = HttpRequest.BodyPublishers.ofString(body);
HttpRequest req1 = HttpRequest
.newBuilder(uri1)
.version(Version.HTTP_2)
.POST(reqBody)
.build();
out.println("\nPosting to HTTP/1.1 server at: " + req1);
- HttpResponse<Stream<String>> response = client.send(req1, asLines());
+ HttpResponse<Stream<String>> response = client.send(req1, BodyHandlers.ofLines());
out.println("Checking response...");
if (response.statusCode() != 200) {
throw new RuntimeException("Unexpected status code: " + response);
@@ -145,14 +144,14 @@
if (!lines.equals(respLines)) {
throw new RuntimeException("Unexpected response 1: " + respLines);
}
- HttpRequest.BodyPublisher reqBody2 = HttpRequest.BodyPublisher.fromString(body);
+ HttpRequest.BodyPublisher reqBody2 = HttpRequest.BodyPublishers.ofString(body);
HttpRequest req2 = HttpRequest
.newBuilder(uri2)
.version(Version.HTTP_2)
.POST(reqBody2)
.build();
out.println("\nPosting to HTTP/2 server at: " + req2);
- response = client.send(req2, asLines());
+ response = client.send(req2, BodyHandlers.ofLines());
out.println("Checking response...");
if (response.statusCode() != 200) {
throw new RuntimeException("Unexpected status code: " + response);
--- a/test/jdk/java/net/httpclient/ImmutableFlowItems.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ImmutableFlowItems.java Sat Feb 24 11:27:11 2018 +0000
@@ -53,7 +53,8 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
-import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import javax.net.ssl.SSLContext;
import jdk.testlibrary.SimpleSSLContext;
import org.testng.annotations.AfterTest;
@@ -62,7 +63,6 @@
import org.testng.annotations.Test;
import static java.lang.System.out;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpResponse.BodySubscriber.asString;
import static org.testng.Assert.*;
public class ImmutableFlowItems {
@@ -126,11 +126,11 @@
}
static class CRSBodySubscriber implements BodySubscriber<String> {
- private final BodySubscriber<String> asString = asString(UTF_8);
+ private final BodySubscriber<String> ofString = BodySubscribers.ofString(UTF_8);
@Override
public void onSubscribe(Flow.Subscription subscription) {
- asString.onSubscribe(subscription);
+ ofString.onSubscribe(subscription);
}
@Override
@@ -138,22 +138,22 @@
assertUnmodifiableList(item);
long c = item.stream().filter(ByteBuffer::isReadOnly).count();
assertEquals(c, item.size(), "Unexpected writable buffer in: " +item);
- asString.onNext(item);
+ ofString.onNext(item);
}
@Override
public void onError(Throwable throwable) {
- asString.onError(throwable);
+ ofString.onError(throwable);
}
@Override
public void onComplete() {
- asString.onComplete();
+ ofString.onComplete();
}
@Override
public CompletionStage<String> getBody() {
- return asString.getBody();
+ return ofString.getBody();
}
}
--- a/test/jdk/java/net/httpclient/ImmutableHeaders.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ImmutableHeaders.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,12 +39,15 @@
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.URI;
-import java.net.http.*;
+import java.net.http.HttpClient;
+import java.net.http.HttpHeaders;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.List;
import static java.nio.charset.StandardCharsets.US_ASCII;
-import static java.net.http.HttpResponse.BodyHandler.discard;
public class ImmutableHeaders {
@@ -81,7 +84,7 @@
throw new RuntimeException("Test failed");
} catch (UnsupportedOperationException ex) {
}
- HttpResponse resp = client.send(req, discard());
+ HttpResponse resp = client.send(req, BodyHandlers.discarding());
try {
HttpHeaders hd = resp.headers();
List<String> v = hd.allValues("X-Foo-Response");
--- a/test/jdk/java/net/httpclient/InterruptedBlockingSend.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/InterruptedBlockingSend.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,8 @@
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpResponse.BodyHandlers;
import static java.lang.System.out;
-import static java.net.http.HttpResponse.BodyHandler.discard;
/**
* @test
@@ -48,7 +48,7 @@
Thread t = new Thread(() -> {
try {
- client.send(request, discard());
+ client.send(request, BodyHandlers.discarding());
} catch (InterruptedException e) {
throwable = e;
} catch (Throwable th) {
--- a/test/jdk/java/net/httpclient/InvalidSSLContextTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/InvalidSSLContextTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -44,7 +44,7 @@
import java.net.http.HttpClient.Version;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import jdk.testlibrary.SimpleSSLContext;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
@@ -81,7 +81,7 @@
.build();
try {
- HttpResponse<?> response = client.send(request, BodyHandler.discard());
+ HttpResponse<?> response = client.send(request, BodyHandlers.discarding());
Assert.fail("UNEXPECTED response" + response);
} catch (SSLException sslex) {
System.out.println("Caught expected: " + sslex);
@@ -100,7 +100,7 @@
.build();
assertExceptionally(SSLException.class,
- client.sendAsync(request, BodyHandler.discard()));
+ client.sendAsync(request, BodyHandlers.discarding()));
}
static void assertExceptionally(Class<? extends Throwable> clazz,
--- a/test/jdk/java/net/httpclient/LineAdaptersCompileOnly.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/LineAdaptersCompileOnly.java Sat Feb 24 11:27:11 2018 +0000
@@ -24,7 +24,9 @@
import java.util.concurrent.Flow;
import java.util.function.Function;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import static java.util.function.Function.identity;
import static java.nio.charset.StandardCharsets.*;
@@ -41,27 +43,27 @@
}
static void makesSureDifferentGenericSignaturesCompile() {
- BodyHandler.fromLineSubscriber(new StringSubscriber());
- BodyHandler.fromLineSubscriber(new CharSequenceSubscriber());
- BodyHandler.fromLineSubscriber(new ObjectSubscriber());
+ BodyHandlers.fromLineSubscriber(new StringSubscriber());
+ BodyHandlers.fromLineSubscriber(new CharSequenceSubscriber());
+ BodyHandlers.fromLineSubscriber(new ObjectSubscriber());
- BodySubscriber.fromLineSubscriber(new StringSubscriber());
- BodySubscriber.fromLineSubscriber(new CharSequenceSubscriber());
- BodySubscriber.fromLineSubscriber(new ObjectSubscriber());
+ BodySubscribers.fromLineSubscriber(new StringSubscriber());
+ BodySubscribers.fromLineSubscriber(new CharSequenceSubscriber());
+ BodySubscribers.fromLineSubscriber(new ObjectSubscriber());
- BodyHandler.fromLineSubscriber(new StringSubscriber(), identity(), "\n");
- BodyHandler.fromLineSubscriber(new CharSequenceSubscriber(), identity(), "\r\n");
- BodyHandler.fromLineSubscriber(new ObjectSubscriber(), identity(), "\n");
- BodyHandler.fromLineSubscriber(new StringSubscriber(), identity(), null);
- BodyHandler.fromLineSubscriber(new CharSequenceSubscriber(), identity(), null);
- BodyHandler.fromLineSubscriber(new ObjectSubscriber(), identity(), null);
+ BodyHandlers.fromLineSubscriber(new StringSubscriber(), identity(), "\n");
+ BodyHandlers.fromLineSubscriber(new CharSequenceSubscriber(), identity(), "\r\n");
+ BodyHandlers.fromLineSubscriber(new ObjectSubscriber(), identity(), "\n");
+ BodyHandlers.fromLineSubscriber(new StringSubscriber(), identity(), null);
+ BodyHandlers.fromLineSubscriber(new CharSequenceSubscriber(), identity(), null);
+ BodyHandlers.fromLineSubscriber(new ObjectSubscriber(), identity(), null);
- BodySubscriber.fromLineSubscriber(new StringSubscriber(), identity(), UTF_8, "\n");
- BodySubscriber.fromLineSubscriber(new CharSequenceSubscriber(), identity(), UTF_16, "\r\n");
- BodySubscriber.fromLineSubscriber(new ObjectSubscriber(), identity(), US_ASCII, "\n");
- BodySubscriber.fromLineSubscriber(new StringSubscriber(), identity(), UTF_8, null);
- BodySubscriber.fromLineSubscriber(new CharSequenceSubscriber(), identity(), UTF_16, null);
- BodySubscriber.fromLineSubscriber(new ObjectSubscriber(), identity(), US_ASCII, null);
+ BodySubscribers.fromLineSubscriber(new StringSubscriber(), identity(), UTF_8, "\n");
+ BodySubscribers.fromLineSubscriber(new CharSequenceSubscriber(), identity(), UTF_16, "\r\n");
+ BodySubscribers.fromLineSubscriber(new ObjectSubscriber(), identity(), US_ASCII, "\n");
+ BodySubscribers.fromLineSubscriber(new StringSubscriber(), identity(), UTF_8, null);
+ BodySubscribers.fromLineSubscriber(new CharSequenceSubscriber(), identity(), UTF_16, null);
+ BodySubscribers.fromLineSubscriber(new ObjectSubscriber(), identity(), US_ASCII, null);
}
static class StringSubscriber implements Flow.Subscriber<String> {
@@ -97,32 +99,32 @@
}
static void makesSureDifferentGenericFunctionSignaturesCompile() {
- BodyHandler<Integer> bh01 = BodyHandler.fromLineSubscriber(new StringSubscriber(), s -> 6, "\n");
- BodyHandler<Number> bh02 = BodyHandler.fromLineSubscriber(new StringSubscriber(), s -> 7, "\n");
- BodyHandler<Integer> bh03 = BodyHandler.fromLineSubscriber(new StringSubscriber(), f1, "\n");
- BodyHandler<Number> bh04 = BodyHandler.fromLineSubscriber(new StringSubscriber(), f1, "\n");
- BodyHandler<Number> bh05 = BodyHandler.fromLineSubscriber(new StringSubscriber(), f2, "\n");
- BodyHandler<Integer> bh06 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), f1, "\n");
- BodyHandler<Number> bh07 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), f1, "\n");
- BodyHandler<Number> bh08 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), f2, "\n");
- BodyHandler<Integer> bh09 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, "\n");
- BodyHandler<Number> bh10 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, "\n");
- BodyHandler<Integer> bh11 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), f3, "\n");
- BodyHandler<Number> bh12 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), f3, "\n");
- BodyHandler<Number> bh13 = BodyHandler.fromLineSubscriber(new StringSubscriberX(), f4, "\n");
+ BodyHandler<Integer> bh01 = BodyHandlers.fromLineSubscriber(new StringSubscriber(), s -> 6, "\n");
+ BodyHandler<Number> bh02 = BodyHandlers.fromLineSubscriber(new StringSubscriber(), s -> 7, "\n");
+ BodyHandler<Integer> bh03 = BodyHandlers.fromLineSubscriber(new StringSubscriber(), f1, "\n");
+ BodyHandler<Number> bh04 = BodyHandlers.fromLineSubscriber(new StringSubscriber(), f1, "\n");
+ BodyHandler<Number> bh05 = BodyHandlers.fromLineSubscriber(new StringSubscriber(), f2, "\n");
+ BodyHandler<Integer> bh06 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), f1, "\n");
+ BodyHandler<Number> bh07 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), f1, "\n");
+ BodyHandler<Number> bh08 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), f2, "\n");
+ BodyHandler<Integer> bh09 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, "\n");
+ BodyHandler<Number> bh10 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, "\n");
+ BodyHandler<Integer> bh11 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), f3, "\n");
+ BodyHandler<Number> bh12 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), f3, "\n");
+ BodyHandler<Number> bh13 = BodyHandlers.fromLineSubscriber(new StringSubscriberX(), f4, "\n");
- BodySubscriber<Integer> bs01 = BodySubscriber.fromLineSubscriber(new StringSubscriber(), s -> 6, UTF_8, "\n");
- BodySubscriber<Number> bs02 = BodySubscriber.fromLineSubscriber(new StringSubscriber(), s -> 7, UTF_8, "\n");
- BodySubscriber<Integer> bs03 = BodySubscriber.fromLineSubscriber(new StringSubscriber(), f1, UTF_8, "\n");
- BodySubscriber<Number> bs04 = BodySubscriber.fromLineSubscriber(new StringSubscriber(), f1, UTF_8, "\n");
- BodySubscriber<Number> bs05 = BodySubscriber.fromLineSubscriber(new StringSubscriber(), f2, UTF_8, "\n");
- BodySubscriber<Integer> bs06 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), f1, UTF_8, "\n");
- BodySubscriber<Number> bs07 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), f1, UTF_8, "\n");
- BodySubscriber<Number> bs08 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), f2, UTF_8, "\n");
- BodySubscriber<Integer> bs09 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, UTF_8, "\n");
- BodySubscriber<Number> bs10 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, UTF_8, "\n");
- BodySubscriber<Integer> bs11 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), f3, UTF_8, "\n");
- BodySubscriber<Number> bs12 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), f3, UTF_8, "\n");
- BodySubscriber<Number> bs13 = BodySubscriber.fromLineSubscriber(new StringSubscriberX(), f4, UTF_8, "\n");
+ BodySubscriber<Integer> bs01 = BodySubscribers.fromLineSubscriber(new StringSubscriber(), s -> 6, UTF_8, "\n");
+ BodySubscriber<Number> bs02 = BodySubscribers.fromLineSubscriber(new StringSubscriber(), s -> 7, UTF_8, "\n");
+ BodySubscriber<Integer> bs03 = BodySubscribers.fromLineSubscriber(new StringSubscriber(), f1, UTF_8, "\n");
+ BodySubscriber<Number> bs04 = BodySubscribers.fromLineSubscriber(new StringSubscriber(), f1, UTF_8, "\n");
+ BodySubscriber<Number> bs05 = BodySubscribers.fromLineSubscriber(new StringSubscriber(), f2, UTF_8, "\n");
+ BodySubscriber<Integer> bs06 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), f1, UTF_8, "\n");
+ BodySubscriber<Number> bs07 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), f1, UTF_8, "\n");
+ BodySubscriber<Number> bs08 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), f2, UTF_8, "\n");
+ BodySubscriber<Integer> bs09 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, UTF_8, "\n");
+ BodySubscriber<Number> bs10 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), StringSubscriberX::getIntegerX, UTF_8, "\n");
+ BodySubscriber<Integer> bs11 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), f3, UTF_8, "\n");
+ BodySubscriber<Number> bs12 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), f3, UTF_8, "\n");
+ BodySubscriber<Number> bs13 = BodySubscribers.fromLineSubscriber(new StringSubscriberX(), f4, UTF_8, "\n");
}
}
--- a/test/jdk/java/net/httpclient/LineBodyHandlerTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/LineBodyHandlerTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -21,34 +21,21 @@
* questions.
*/
-import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import com.sun.net.httpserver.HttpServer;
-import com.sun.net.httpserver.HttpsConfigurator;
-import com.sun.net.httpserver.HttpsServer;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodyHandler;
-import java.net.http.HttpResponse.BodySubscriber;
-import jdk.testlibrary.SimpleSSLContext;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-import javax.net.ssl.SSLContext;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.io.PrintStream;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
+import java.net.http.HttpResponse.BodySubscribers;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -60,10 +47,19 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.net.ssl.SSLContext;
+import com.sun.net.httpserver.HttpServer;
+import com.sun.net.httpserver.HttpsConfigurator;
+import com.sun.net.httpserver.HttpsServer;
+import jdk.testlibrary.SimpleSSLContext;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.UTF_16;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
+import static java.net.http.HttpRequest.BodyPublishers.ofString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertThrows;
@@ -113,56 +109,56 @@
@Test
public void testNull() {
- assertThrows(NPE, () -> BodyHandler.fromLineSubscriber(null));
- assertNotNull(BodyHandler.fromLineSubscriber(new StringSubscriber()));
- assertThrows(NPE, () -> BodyHandler.fromLineSubscriber(null, Function.identity(), "\n"));
- assertThrows(NPE, () -> BodyHandler.fromLineSubscriber(new StringSubscriber(), null, "\n"));
- assertNotNull(BodyHandler.fromLineSubscriber(new StringSubscriber(), Function.identity(), null));
- assertThrows(NPE, () -> BodyHandler.fromLineSubscriber(null, null, "\n"));
- assertThrows(NPE, () -> BodyHandler.fromLineSubscriber(null, Function.identity(), null));
- assertThrows(NPE, () -> BodyHandler.fromLineSubscriber(new StringSubscriber(), null, null));
+ assertThrows(NPE, () -> BodyHandlers.fromLineSubscriber(null));
+ assertNotNull(BodyHandlers.fromLineSubscriber(new StringSubscriber()));
+ assertThrows(NPE, () -> BodyHandlers.fromLineSubscriber(null, Function.identity(), "\n"));
+ assertThrows(NPE, () -> BodyHandlers.fromLineSubscriber(new StringSubscriber(), null, "\n"));
+ assertNotNull(BodyHandlers.fromLineSubscriber(new StringSubscriber(), Function.identity(), null));
+ assertThrows(NPE, () -> BodyHandlers.fromLineSubscriber(null, null, "\n"));
+ assertThrows(NPE, () -> BodyHandlers.fromLineSubscriber(null, Function.identity(), null));
+ assertThrows(NPE, () -> BodyHandlers.fromLineSubscriber(new StringSubscriber(), null, null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, Function.identity(),
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null));
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, Function.identity(),
Charset.defaultCharset(), System.lineSeparator()));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(new StringSubscriber(), null,
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(new StringSubscriber(), null,
Charset.defaultCharset(), System.lineSeparator()));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(new StringSubscriber(), Function.identity(),
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(new StringSubscriber(), Function.identity(),
null, System.lineSeparator()));
- assertNotNull(BodySubscriber.fromLineSubscriber(new StringSubscriber(), Function.identity(),
+ assertNotNull(BodySubscribers.fromLineSubscriber(new StringSubscriber(), Function.identity(),
Charset.defaultCharset(), null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, null,
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, null,
Charset.defaultCharset(), System.lineSeparator()));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, Function.identity(),
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, Function.identity(),
null, System.lineSeparator()));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, Function.identity(),
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, Function.identity(),
Charset.defaultCharset(), null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(new StringSubscriber(), null,
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(new StringSubscriber(), null,
null, System.lineSeparator()));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(new StringSubscriber(), null,
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(new StringSubscriber(), null,
Charset.defaultCharset(), null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(new StringSubscriber(), Function.identity(),
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(new StringSubscriber(), Function.identity(),
null, null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(new StringSubscriber(), null, null, null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, Function.identity(),
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(new StringSubscriber(), null, null, null));
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, Function.identity(),
null, null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, null,
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, null,
Charset.defaultCharset(), null));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, null,
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, null,
null, System.lineSeparator()));
- assertThrows(NPE, () -> BodySubscriber.fromLineSubscriber(null, null, null, null));
+ assertThrows(NPE, () -> BodySubscribers.fromLineSubscriber(null, null, null, null));
}
@Test
public void testIAE() {
- assertThrows(IAE, () -> BodyHandler.fromLineSubscriber(new StringSubscriber(), Function.identity(),""));
- assertThrows(IAE, () -> BodyHandler.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),""));
- assertThrows(IAE, () -> BodyHandler.fromLineSubscriber(new ObjectSubscriber(), Function.identity(), ""));
- assertThrows(IAE, () -> BodySubscriber.fromLineSubscriber(new StringSubscriber(), Function.identity(),
+ assertThrows(IAE, () -> BodyHandlers.fromLineSubscriber(new StringSubscriber(), Function.identity(),""));
+ assertThrows(IAE, () -> BodyHandlers.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),""));
+ assertThrows(IAE, () -> BodyHandlers.fromLineSubscriber(new ObjectSubscriber(), Function.identity(), ""));
+ assertThrows(IAE, () -> BodySubscribers.fromLineSubscriber(new StringSubscriber(), Function.identity(),
StandardCharsets.UTF_8, ""));
- assertThrows(IAE, () -> BodySubscriber.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),
+ assertThrows(IAE, () -> BodySubscribers.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),
StandardCharsets.UTF_16, ""));
- assertThrows(IAE, () -> BodySubscriber.fromLineSubscriber(new ObjectSubscriber(), Function.identity(),
+ assertThrows(IAE, () -> BodySubscribers.fromLineSubscriber(new ObjectSubscriber(), Function.identity(),
StandardCharsets.US_ASCII, ""));
}
@@ -191,12 +187,12 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext)
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
StringSubscriber subscriber = new StringSubscriber();
CompletableFuture<HttpResponse<String>> cf
- = client.sendAsync(request, BodyHandler.fromLineSubscriber(
+ = client.sendAsync(request, BodyHandlers.fromLineSubscriber(
subscriber, Supplier::get, "\n"));
assertNoObtrusion(cf);
HttpResponse<String> response = cf.join();
@@ -213,11 +209,11 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext)
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
CompletableFuture<HttpResponse<Stream<String>>> cf
- = client.sendAsync(request, BodyHandler.asLines());
+ = client.sendAsync(request, BodyHandlers.ofLines());
assertNoObtrusion(cf);
HttpResponse<Stream<String>> response = cf.join();
Stream<String> stream = response.body();
@@ -235,13 +231,13 @@
String body = "May the luck\r\n\r\n of the Irish be with you!";
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
StringSubscriber subscriber = new StringSubscriber();
CompletableFuture<HttpResponse<Void>> cf
= client.sendAsync(request,
- BodyHandler.fromLineSubscriber(subscriber));
+ BodyHandlers.fromLineSubscriber(subscriber));
assertNoObtrusion(cf);
HttpResponse<Void> response = cf.join();
String text = subscriber.get();
@@ -256,11 +252,11 @@
String body = "May the luck\r\n\r\n of the Irish be with you!";
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
CompletableFuture<HttpResponse<Stream<String>>> cf
- = client.sendAsync(request, BodyHandler.asLines());
+ = client.sendAsync(request, BodyHandlers.ofLines());
assertNoObtrusion(cf);
HttpResponse<Stream<String>> response = cf.join();
Stream<String> stream = response.body();
@@ -280,11 +276,11 @@
String body = "May the luck of the Irish be with you!";
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body)).build();
+ .POST(BodyPublishers.ofString(body)).build();
StringSubscriber subscriber = new StringSubscriber();
HttpResponse<String> response = client.send(request,
- BodyHandler.fromLineSubscriber(subscriber, Supplier::get, "\n"));
+ BodyHandlers.fromLineSubscriber(subscriber, Supplier::get, "\n"));
String text = response.body();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -297,11 +293,11 @@
String body = "May the luck of the Irish be with you!";
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body)).build();
+ .POST(BodyPublishers.ofString(body)).build();
StringSubscriber subscriber = new StringSubscriber();
HttpResponse<Void> response = client.send(request,
- BodyHandler.fromLineSubscriber(subscriber));
+ BodyHandlers.fromLineSubscriber(subscriber));
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -316,11 +312,11 @@
String body = "May\r\n the wind\r\n always be\rat your back.\r\r";
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
CompletableFuture<HttpResponse<Stream<String>>> cf
- = client.sendAsync(request, BodyHandler.asLines());
+ = client.sendAsync(request, BodyHandlers.ofLines());
assertNoObtrusion(cf);
HttpResponse<Stream<String>> response = cf.join();
Stream<String> stream = response.body();
@@ -344,10 +340,10 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Content-type", "text/text; charset=UTF-8")
- .POST(fromString(body, UTF_8)).build();
+ .POST(BodyPublishers.ofString(body, UTF_8)).build();
CompletableFuture<HttpResponse<Stream<String>>> cf
- = client.sendAsync(request, BodyHandler.asLines());
+ = client.sendAsync(request, BodyHandlers.ofLines());
assertNoObtrusion(cf);
HttpResponse<Stream<String>> response = cf.join();
Stream<String> stream = response.body();
@@ -370,10 +366,10 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Content-type", "text/text; charset=UTF-16")
- .POST(fromString(body, UTF_16)).build();
+ .POST(BodyPublishers.ofString(body, UTF_16)).build();
CompletableFuture<HttpResponse<Stream<String>>> cf
- = client.sendAsync(request, BodyHandler.asLines());
+ = client.sendAsync(request, BodyHandlers.ofLines());
assertNoObtrusion(cf);
HttpResponse<Stream<String>> response = cf.join();
Stream<String> stream = response.body();
@@ -396,12 +392,12 @@
String body = "May\r\n the wind\r\n always be\rat your back.";
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
ObjectSubscriber subscriber = new ObjectSubscriber();
CompletableFuture<HttpResponse<String>> cf
- = client.sendAsync(request, BodyHandler.fromLineSubscriber(
+ = client.sendAsync(request, BodyHandlers.fromLineSubscriber(
subscriber, ObjectSubscriber::get, "\r\n"));
assertNoObtrusion(cf);
HttpResponse<String> response = cf.join();
@@ -422,10 +418,10 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Content-type", "text/text; charset=UTF-16")
- .POST(fromString(body, UTF_16)).build();
+ .POST(BodyPublishers.ofString(body, UTF_16)).build();
ObjectSubscriber subscriber = new ObjectSubscriber();
CompletableFuture<HttpResponse<String>> cf
- = client.sendAsync(request, BodyHandler.fromLineSubscriber(
+ = client.sendAsync(request, BodyHandlers.fromLineSubscriber(
subscriber, ObjectSubscriber::get, null));
assertNoObtrusion(cf);
HttpResponse<String> response = cf.join();
@@ -448,13 +444,13 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext)
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
ObjectSubscriber subscriber = new ObjectSubscriber();
CompletableFuture<HttpResponse<Void>> cf
= client.sendAsync(request,
- BodyHandler.fromLineSubscriber(subscriber));
+ BodyHandlers.fromLineSubscriber(subscriber));
assertNoObtrusion(cf);
HttpResponse<Void> response = cf.join();
String text = subscriber.get();
@@ -475,12 +471,12 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext)
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
ObjectSubscriber subscriber = new ObjectSubscriber();
HttpResponse<String> response = client.send(request,
- BodyHandler.fromLineSubscriber(subscriber,
+ BodyHandlers.fromLineSubscriber(subscriber,
ObjectSubscriber::get,
"\r\n"));
String text = response.body();
@@ -500,12 +496,12 @@
HttpClient client = HttpClient.newBuilder().sslContext(sslContext)
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
ObjectSubscriber subscriber = new ObjectSubscriber();
HttpResponse<Void> response = client.send(request,
- BodyHandler.fromLineSubscriber(subscriber));
+ BodyHandlers.fromLineSubscriber(subscriber));
String text = subscriber.get();
System.out.println(text);
assertEquals(response.statusCode(), 200);
@@ -536,12 +532,12 @@
.build();
String bigtext = bigtext();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(bigtext))
+ .POST(BodyPublishers.ofString(bigtext))
.build();
StringSubscriber subscriber = new StringSubscriber();
CompletableFuture<HttpResponse<String>> cf
- = client.sendAsync(request, BodyHandler.fromLineSubscriber(
+ = client.sendAsync(request, BodyHandlers.fromLineSubscriber(
subscriber, Supplier::get, "\r\n"));
assertNoObtrusion(cf);
HttpResponse<String> response = cf.join();
@@ -558,11 +554,11 @@
.build();
String bigtext = bigtext();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
- .POST(fromString(bigtext))
+ .POST(BodyPublishers.ofString(bigtext))
.build();
CompletableFuture<HttpResponse<Stream<String>>> cf
- = client.sendAsync(request, BodyHandler.asLines());
+ = client.sendAsync(request, BodyHandlers.ofLines());
assertNoObtrusion(cf);
HttpResponse<Stream<String>> response = cf.join();
Stream<String> stream = response.body();
--- a/test/jdk/java/net/httpclient/LineStreamsAndSurrogatesTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/LineStreamsAndSurrogatesTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -21,14 +21,12 @@
* questions.
*/
-import java.net.http.HttpResponse.BodySubscriber;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
+import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.MalformedInputException;
@@ -39,12 +37,10 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
+import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_16;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertThrows;
-import static org.testng.Assert.assertTrue;
/*
* @test
@@ -71,8 +67,7 @@
" fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres\ud801\udc00";
Charset charset = UTF_8;
- BodySubscriber<Stream<String>> bodySubscriber =
- BodySubscriber.asLines(charset);
+ BodySubscriber<Stream<String>> bodySubscriber = BodySubscribers.ofLines(charset);
AtomicReference<Throwable> errorRef = new AtomicReference<>();
Runnable run = () -> {
try {
@@ -132,8 +127,7 @@
" fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres";
Charset charset = UTF_8;
- BodySubscriber<Stream<String>> bodySubscriber =
- BodySubscriber.asLines(charset);
+ BodySubscriber<Stream<String>> bodySubscriber = BodySubscribers.ofLines(charset);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(charset);
AtomicReference<Throwable> errorRef = new AtomicReference<>();
@@ -181,7 +175,7 @@
" les fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres\r\r";
Charset charset = UTF_8;
- BodySubscriber<Stream<String>> bodySubscriber = BodySubscriber.asLines(charset);
+ BodySubscriber<Stream<String>> bodySubscriber = BodySubscribers.ofLines(charset);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(charset);
AtomicReference<Throwable> errorRef = new AtomicReference<>();
@@ -228,8 +222,7 @@
" les\n\n fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres";
Charset charset = UTF_16;
- BodySubscriber<Stream<String>> bodySubscriber =
- BodySubscriber.asLines(charset);
+ BodySubscriber<Stream<String>> bodySubscriber = BodySubscribers.ofLines(charset);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(charset);
AtomicReference<Throwable> errorRef = new AtomicReference<>();
@@ -275,8 +268,7 @@
" les fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres\r\r";
Charset charset = UTF_16;
- BodySubscriber<Stream<String>> bodySubscriber =
- BodySubscriber.asLines(charset);
+ BodySubscriber<Stream<String>> bodySubscriber = BodySubscribers.ofLines(charset);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(charset);
AtomicReference<Throwable> errorRef = new AtomicReference<>();
--- a/test/jdk/java/net/httpclient/LineSubscribersAndSurrogatesTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/LineSubscribersAndSurrogatesTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -21,10 +21,6 @@
* questions.
*/
-import java.net.http.HttpResponse.BodySubscriber;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -32,9 +28,10 @@
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.UncheckedIOException;
+import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import java.nio.ByteBuffer;
import java.nio.charset.MalformedInputException;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -45,12 +42,10 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
+import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_16;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertThrows;
-import static org.testng.Assert.assertTrue;
/*
* @test
@@ -91,7 +86,7 @@
String text = "Bient\u00f4t\r\n nous plongerons\r\n dans\r" +
" les\n\n fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres\ud801\udc00";
ObjectSubscriber subscriber = new ObjectSubscriber();
- BodySubscriber<String> bodySubscriber = BodySubscriber.fromLineSubscriber(
+ BodySubscriber<String> bodySubscriber = BodySubscribers.fromLineSubscriber(
subscriber, Supplier::get, UTF_8, null);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] sbytes = text.getBytes(UTF_8);
@@ -133,7 +128,7 @@
String text = "Bient\u00f4t\r\n nous plongerons\r\n dans\r" +
" les\n\n fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres\r";
ObjectSubscriber subscriber = new ObjectSubscriber();
- BodySubscriber<String> bodySubscriber = BodySubscriber.fromLineSubscriber(
+ BodySubscriber<String> bodySubscriber = BodySubscribers.fromLineSubscriber(
subscriber, Supplier::get, UTF_8, "\n");
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(UTF_8);
@@ -164,7 +159,7 @@
String text = "Bient\u00f4t\r\n nous plongerons\r\n dans\r" +
" les fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres\r\r";
ObjectSubscriber subscriber = new ObjectSubscriber();
- BodySubscriber<String> bodySubscriber = BodySubscriber.fromLineSubscriber(
+ BodySubscriber<String> bodySubscriber = BodySubscribers.fromLineSubscriber(
subscriber, Supplier::get, UTF_8, "\r");
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(UTF_8);
@@ -192,7 +187,7 @@
String text = "Bient\u00f4t\r\n nous plongerons\r\n dans\r" +
" les fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres";
ObjectSubscriber subscriber = new ObjectSubscriber();
- BodySubscriber<String> bodySubscriber = BodySubscriber.fromLineSubscriber(
+ BodySubscriber<String> bodySubscriber = BodySubscribers.fromLineSubscriber(
subscriber, Supplier::get, UTF_8, "\r\n");
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(UTF_8);
@@ -219,7 +214,7 @@
String text = "Bient\u00f4t\r\n nous plongerons\r\n dans\r" +
" les\r\r fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres";
ObjectSubscriber subscriber = new ObjectSubscriber();
- BodySubscriber<String> bodySubscriber = BodySubscriber.fromLineSubscriber(
+ BodySubscriber<String> bodySubscriber = BodySubscribers.fromLineSubscriber(
subscriber, Supplier::get, UTF_8, null);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(UTF_8);
@@ -249,7 +244,7 @@
String text = "Bient\u00f4t\r\n nous plongerons\r\n dans\r" +
" les\r\r fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres\r\r";
ObjectSubscriber subscriber = new ObjectSubscriber();
- BodySubscriber<String> bodySubscriber = BodySubscriber.fromLineSubscriber(
+ BodySubscriber<String> bodySubscriber = BodySubscribers.fromLineSubscriber(
subscriber, Supplier::get, UTF_16, null);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(UTF_16);
@@ -279,7 +274,7 @@
String text = "Bient\u00f4t\r\n nous plongerons\r\n dans\r" +
" les\r\r fr\u00f4\ud801\udc00des\r\n t\u00e9n\u00e8bres";
ObjectSubscriber subscriber = new ObjectSubscriber();
- BodySubscriber<Void> bodySubscriber = BodySubscriber.fromLineSubscriber(subscriber);
+ BodySubscriber<Void> bodySubscriber = BodySubscribers.fromLineSubscriber(subscriber);
SubmissionPublisher<List<ByteBuffer>> publisher = new SubmissionPublisher<>();
byte[] bytes = text.getBytes(UTF_8);
publisher.subscribe(bodySubscriber);
--- a/test/jdk/java/net/httpclient/ManyRequests.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ManyRequests.java Sat Feb 24 11:27:11 2018 +0000
@@ -47,10 +47,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
-import java.net.InetSocketAddress;
-import java.net.URI;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.Arrays;
import java.util.Formatter;
import java.util.HashMap;
@@ -61,8 +63,6 @@
import java.util.concurrent.CompletableFuture;
import javax.net.ssl.SSLContext;
import jdk.testlibrary.SimpleSSLContext;
-import static java.net.http.HttpRequest.BodyPublisher.fromByteArray;
-import static java.net.http.HttpResponse.BodyHandler.asByteArray;
public class ManyRequests {
@@ -144,7 +144,7 @@
URI uri = new URI(baseURI.toString() + String.valueOf(i+1));
HttpRequest r = HttpRequest.newBuilder(uri)
.header("XFixed", "true")
- .POST(fromByteArray(buf))
+ .POST(BodyPublishers.ofByteArray(buf))
.build();
bodies.put(r, buf);
@@ -152,7 +152,7 @@
limiter.whenOkToSend()
.thenCompose((v) -> {
System.out.println("Client: sendAsync: " + r.uri());
- return client.sendAsync(r, asByteArray());
+ return client.sendAsync(r, BodyHandlers.ofByteArray());
})
.thenCompose((resp) -> {
limiter.requestComplete();
--- a/test/jdk/java/net/httpclient/ManyRequestsLegacy.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ManyRequestsLegacy.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -50,17 +50,16 @@
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URLConnection;
-import java.security.NoSuchAlgorithmException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import java.net.http.HttpClient;
import java.net.http.HttpClient.Version;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.InetSocketAddress;
import java.util.Arrays;
@@ -68,12 +67,9 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Random;
-import java.util.concurrent.ExecutorService;
import java.util.logging.Logger;
import java.util.logging.Level;
import jdk.testlibrary.SimpleSSLContext;
-import static java.net.http.HttpRequest.BodyPublisher.fromByteArray;
-import static java.net.http.HttpResponse.BodyHandler.asByteArray;
public class ManyRequestsLegacy {
@@ -236,7 +232,7 @@
URI uri = new URI(baseURI.toString() + String.valueOf(i+1));
HttpRequest r = HttpRequest.newBuilder(uri)
.header("XFixed", "true")
- .POST(fromByteArray(buf))
+ .POST(BodyPublishers.ofByteArray(buf))
.build();
bodies.put(r, buf);
--- a/test/jdk/java/net/httpclient/MappingResponseSubscriber.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/MappingResponseSubscriber.java Sat Feb 24 11:27:11 2018 +0000
@@ -54,6 +54,8 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
+import java.net.http.HttpResponse.BodySubscribers;
import java.net.http.HttpResponse.BodySubscriber;
import java.util.function.Function;
import javax.net.ssl.SSLContext;
@@ -63,9 +65,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static java.lang.System.out;
-import static java.net.http.HttpResponse.BodySubscriber.mapping;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpResponse.BodySubscriber.asString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -139,47 +139,47 @@
@Override
public BodySubscriber<byte[]> apply(int statusCode, HttpHeaders responseHeaders) {
assertEquals(statusCode, 200);
- return HttpResponse.BodySubscriber.mapping(
+ return BodySubscribers.mapping(
new CRSBodySubscriber(), (s) -> s.getBytes(UTF_8)
);
}
}
static class CRSBodySubscriber implements BodySubscriber<String> {
- private final BodySubscriber<String> asString = asString(UTF_8);
+ private final BodySubscriber<String> ofString = BodySubscribers.ofString(UTF_8);
volatile boolean onSubscribeCalled;
@Override
public void onSubscribe(Flow.Subscription subscription) {
//out.println("onSubscribe ");
onSubscribeCalled = true;
- asString.onSubscribe(subscription);
+ ofString.onSubscribe(subscription);
}
@Override
public void onNext(List<ByteBuffer> item) {
// out.println("onNext " + item);
assertTrue(onSubscribeCalled);
- asString.onNext(item);
+ ofString.onNext(item);
}
@Override
public void onError(Throwable throwable) {
//out.println("onError");
assertTrue(onSubscribeCalled);
- asString.onError(throwable);
+ ofString.onError(throwable);
}
@Override
public void onComplete() {
//out.println("onComplete");
assertTrue(onSubscribeCalled, "onComplete called before onSubscribe");
- asString.onComplete();
+ ofString.onComplete();
}
@Override
public CompletionStage<String> getBody() {
- return asString.getBody();
+ return ofString.getBody();
}
}
@@ -318,16 +318,26 @@
HttpClient client = null;
HttpRequest req = null;
- HttpResponse<Integer> r1 = client.send(req, (c,h) -> mapping(asString(UTF_8), s -> 1));
- HttpResponse<Number> r2 = client.send(req, (c,h) -> mapping(asString(UTF_8), s -> 1));
- HttpResponse<String> r3 = client.send(req, (c,h) -> mapping(asString(UTF_8), s -> "s"));
- HttpResponse<CharSequence> r4 = client.send(req, (c,h) -> mapping(asString(UTF_8), s -> "s"));
+ HttpResponse<Integer> r1 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), s -> 1));
+ HttpResponse<Number> r2 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), s -> 1));
+ HttpResponse<String> r3 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), s -> "s"));
+ HttpResponse<CharSequence> r4 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), s -> "s"));
- HttpResponse<Integer> x1 = client.send(req, (c,h) -> mapping(asString(UTF_8), f1));
- HttpResponse<Number> x2 = client.send(req, (c,h) -> mapping(asString(UTF_8), f1));
- HttpResponse<Number> x3 = client.send(req, (c,h) -> mapping(asString(UTF_8), f2));
- HttpResponse<Integer> x4 = client.send(req, (c,h) -> mapping(asString(UTF_8), f3));
- HttpResponse<Number> x5 = client.send(req, (c,h) -> mapping(asString(UTF_8), f3));
- HttpResponse<Number> x7 = client.send(req, (c,h) -> mapping(asString(UTF_8), f4));
+ HttpResponse<Integer> x1 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), f1));
+ HttpResponse<Number> x2 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), f1));
+ HttpResponse<Number> x3 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), f2));
+ HttpResponse<Integer> x4 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), f3));
+ HttpResponse<Number> x5 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), f3));
+ HttpResponse<Number> x7 = client.send(req, (c,h) ->
+ BodySubscribers.mapping(BodySubscribers.ofString(UTF_8), f4));
}
}
--- a/test/jdk/java/net/httpclient/MultiAuthTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/MultiAuthTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -42,12 +42,14 @@
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.URI;
-import java.net.http.*;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static java.nio.charset.StandardCharsets.US_ASCII;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
@@ -173,7 +175,7 @@
HttpResponse resp;
try {
- resp = client.send(req, asString());
+ resp = client.send(req, BodyHandlers.ofString());
ok = resp.statusCode() == 200 &&
resp.body().equals(RESPONSE);
if (resp.statusCode() == 401 || resp.statusCode() == 407) {
@@ -198,7 +200,7 @@
+ " count=" + ca.count.get() + " (expected=" + expectCount+")");
// repeat same request, should succeed but no additional authenticator calls
- resp = client.send(req, asString());
+ resp = client.send(req, BodyHandlers.ofString());
ok = resp.statusCode() == 200 &&
resp.body().equals(RESPONSE);
@@ -208,9 +210,9 @@
// try a POST
req = HttpRequest.newBuilder(uri)
- .POST(fromString(POST_BODY))
+ .POST(BodyPublishers.ofString(POST_BODY))
.build();
- resp = client.send(req, asString());
+ resp = client.send(req, BodyHandlers.ofString());
ok = resp.statusCode() == 200;
if (!ok || ca.count.get() != expectCount)
--- a/test/jdk/java/net/httpclient/NoBodyPartOne.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/NoBodyPartOne.java Sat Feb 24 11:27:11 2018 +0000
@@ -43,14 +43,12 @@
import java.nio.file.Paths;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asByteArray;
-import static java.net.http.HttpResponse.BodyHandler.asFile;
-import static java.net.http.HttpResponse.BodyHandler.asString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -65,9 +63,10 @@
client = newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
- .PUT(fromString(SIMPLE_STRING))
+ .PUT(BodyPublishers.ofString(SIMPLE_STRING))
.build();
- BodyHandler<String> handler = i % 2 == 0 ? asString() : asString(UTF_8);
+ BodyHandler<String> handler = i % 2 == 0 ? BodyHandlers.ofString()
+ : BodyHandlers.ofString(UTF_8);
HttpResponse<String> response = client.send(req, handler);
String body = response.body();
assertEquals(body, "");
@@ -85,10 +84,10 @@
client = newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
- .PUT(fromString(SIMPLE_STRING))
+ .PUT(BodyPublishers.ofString(SIMPLE_STRING))
.build();
Path p = Paths.get("NoBody_testAsFile.txt");
- HttpResponse<Path> response = client.send(req, asFile(p));
+ HttpResponse<Path> response = client.send(req, BodyHandlers.ofFile(p));
Path bodyPath = response.body();
assertTrue(Files.exists(bodyPath));
assertEquals(Files.size(bodyPath), 0);
@@ -106,9 +105,9 @@
client = newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
- .PUT(fromString(SIMPLE_STRING))
+ .PUT(BodyPublishers.ofString(SIMPLE_STRING))
.build();
- HttpResponse<byte[]> response = client.send(req, asByteArray());
+ HttpResponse<byte[]> response = client.send(req, BodyHandlers.ofByteArray());
byte[] body = response.body();
assertEquals(body.length, 0);
}
--- a/test/jdk/java/net/httpclient/NoBodyPartTwo.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/NoBodyPartTwo.java Sat Feb 24 11:27:11 2018 +0000
@@ -43,14 +43,10 @@
import java.util.function.Consumer;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import org.testng.annotations.Test;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asByteArray;
-import static java.net.http.HttpResponse.BodyHandler.asByteArrayConsumer;
-import static java.net.http.HttpResponse.BodyHandler.asInputStream;
-import static java.net.http.HttpResponse.BodyHandler.buffering;
-import static java.net.http.HttpResponse.BodyHandler.replace;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -67,14 +63,14 @@
client = newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
- .PUT(fromString(SIMPLE_STRING))
+ .PUT(BodyPublishers.ofString(SIMPLE_STRING))
.build();
Consumer<Optional<byte[]>> consumer = oba -> {
consumerHasBeenCalled = true;
oba.ifPresent(ba -> fail("Unexpected non-empty optional:" + ba));
};
consumerHasBeenCalled = false;
- client.send(req, asByteArrayConsumer(consumer));
+ client.send(req, BodyHandlers.ofByteArrayConsumer(consumer));
assertTrue(consumerHasBeenCalled);
}
// We have created many clients here. Try to speed up their release.
@@ -90,9 +86,9 @@
client = newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
- .PUT(fromString(SIMPLE_STRING))
+ .PUT(BodyPublishers.ofString(SIMPLE_STRING))
.build();
- HttpResponse<InputStream> response = client.send(req, asInputStream());
+ HttpResponse<InputStream> response = client.send(req, BodyHandlers.ofInputStream());
byte[] body = response.body().readAllBytes();
assertEquals(body.length, 0);
}
@@ -109,9 +105,10 @@
client = newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
- .PUT(fromString(SIMPLE_STRING))
+ .PUT(BodyPublishers.ofString(SIMPLE_STRING))
.build();
- HttpResponse<byte[]> response = client.send(req, buffering(asByteArray(), 1024));
+ HttpResponse<byte[]> response = client.send(req,
+ BodyHandlers.buffering(BodyHandlers.ofByteArray(), 1024));
byte[] body = response.body();
assertEquals(body.length, 0);
}
@@ -128,10 +125,10 @@
client = newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
- .PUT(fromString(SIMPLE_STRING))
+ .PUT(BodyPublishers.ofString(SIMPLE_STRING))
.build();
Object obj = new Object();
- HttpResponse<Object> response = client.send(req, replace(obj));
+ HttpResponse<Object> response = client.send(req, BodyHandlers.replacing(obj));
assertEquals(response.body(), obj);
}
// We have created many clients here. Try to speed up their release.
--- a/test/jdk/java/net/httpclient/ProxyAuthTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ProxyAuthTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -50,10 +50,10 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.Base64;
import java.util.List;
import sun.net.www.MessageHeader;
-import static java.net.http.HttpResponse.BodyHandler.discard;
public class ProxyAuthTest {
private static final String AUTH_USER = "user";
@@ -76,7 +76,7 @@
.authenticator(auth)
.build();
HttpRequest req = HttpRequest.newBuilder(uri).GET().build();
- HttpResponse<?> resp = client.sendAsync(req, discard()).get();
+ HttpResponse<?> resp = client.sendAsync(req, BodyHandlers.discarding()).get();
if (resp.statusCode() != 404) {
throw new RuntimeException("Unexpected status code: " + resp.statusCode());
}
--- a/test/jdk/java/net/httpclient/ProxyTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ProxyTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -209,7 +209,7 @@
System.out.println("Sending request with HttpClient");
HttpResponse<String> response
- = client.send(request, HttpResponse.BodyHandler.asString());
+ = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Got response");
String resp = response.body();
System.out.println("Received: " + resp);
--- a/test/jdk/java/net/httpclient/RequestBodyTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/RequestBodyTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -43,7 +43,9 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -61,8 +63,6 @@
import static java.lang.System.out;
import static java.nio.charset.StandardCharsets.*;
import static java.nio.file.StandardOpenOption.*;
-import static java.net.http.HttpRequest.BodyPublisher.*;
-import static java.net.http.HttpResponse.BodyHandler.*;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
@@ -191,28 +191,28 @@
switch (requestBodyType) {
case BYTE_ARRAY:
- rb.POST(fromByteArray(fileAsBytes));
+ rb.POST(BodyPublishers.ofByteArray(fileAsBytes));
break;
case BYTE_ARRAY_OFFSET:
- rb.POST(fromByteArray(fileAsBytes,
- DEFAULT_OFFSET,
- fileAsBytes.length * DEFAULT_LENGTH_FACTOR));
+ rb.POST(BodyPublishers.ofByteArray(fileAsBytes,
+ DEFAULT_OFFSET,
+ fileAsBytes.length * DEFAULT_LENGTH_FACTOR));
break;
case BYTE_ARRAYS:
Iterable<byte[]> iterable = Arrays.asList(fileAsBytes);
- rb.POST(fromByteArrays(iterable));
+ rb.POST(BodyPublishers.ofByteArrays(iterable));
break;
case FILE:
- rb.POST(fromFile(file));
+ rb.POST(BodyPublishers.ofFile(file));
break;
case INPUTSTREAM:
- rb.POST(fromInputStream(fileInputStreamSupplier(file)));
+ rb.POST(BodyPublishers.ofInputStream(fileInputStreamSupplier(file)));
break;
case STRING:
- rb.POST(fromString(fileAsString));
+ rb.POST(BodyPublishers.ofString(fileAsString));
break;
case STRING_WITH_CHARSET:
- rb.POST(fromString(new String(fileAsBytes), Charset.defaultCharset()));
+ rb.POST(BodyPublishers.ofString(new String(fileAsBytes), Charset.defaultCharset()));
break;
default:
throw new AssertionError("Unknown request body:" + requestBodyType);
@@ -242,8 +242,8 @@
switch (responseBodyType) {
case BYTE_ARRAY:
- BodyHandler<byte[]> bh = asByteArray();
- if (bufferResponseBody) bh = buffering(bh, 50);
+ BodyHandler<byte[]> bh = BodyHandlers.ofByteArray();
+ if (bufferResponseBody) bh = BodyHandlers.buffering(bh, 50);
HttpResponse<byte[]> bar = getResponse(client, request, bh, async);
assertEquals(bar.statusCode(), 200);
assertEquals(bar.body(), fileAsBytes);
@@ -251,8 +251,8 @@
case BYTE_ARRAY_CONSUMER:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Consumer<Optional<byte[]>> consumer = o -> consumerBytes(o, baos);
- BodyHandler<Void> bh1 = asByteArrayConsumer(consumer);
- if (bufferResponseBody) bh1 = buffering(bh1, 49);
+ BodyHandler<Void> bh1 = BodyHandlers.ofByteArrayConsumer(consumer);
+ if (bufferResponseBody) bh1 = BodyHandlers.buffering(bh1, 49);
HttpResponse<Void> v = getResponse(client, request, bh1, async);
byte[] ba = baos.toByteArray();
assertEquals(v.statusCode(), 200);
@@ -260,38 +260,38 @@
break;
case DISCARD:
Object o = new Object();
- BodyHandler<Object> bh2 = replace(o);
- if (bufferResponseBody) bh2 = buffering(bh2, 51);
+ BodyHandler<Object> bh2 = BodyHandlers.replacing(o);
+ if (bufferResponseBody) bh2 = BodyHandlers.buffering(bh2, 51);
HttpResponse<Object> or = getResponse(client, request, bh2, async);
assertEquals(or.statusCode(), 200);
assertSame(or.body(), o);
break;
case FILE:
- BodyHandler<Path> bh3 = asFile(tempFile);
- if (bufferResponseBody) bh3 = buffering(bh3, 48);
+ BodyHandler<Path> bh3 = BodyHandlers.ofFile(tempFile);
+ if (bufferResponseBody) bh3 = BodyHandlers.buffering(bh3, 48);
HttpResponse<Path> fr = getResponse(client, request, bh3, async);
assertEquals(fr.statusCode(), 200);
assertEquals(Files.size(tempFile), fileAsString.length());
assertEquals(Files.readAllBytes(tempFile), fileAsBytes);
break;
case FILE_WITH_OPTION:
- BodyHandler<Path> bh4 = asFile(tempFile, CREATE_NEW, WRITE);
- if (bufferResponseBody) bh4 = buffering(bh4, 52);
+ BodyHandler<Path> bh4 = BodyHandlers.ofFile(tempFile, CREATE_NEW, WRITE);
+ if (bufferResponseBody) bh4 = BodyHandlers.buffering(bh4, 52);
fr = getResponse(client, request, bh4, async);
assertEquals(fr.statusCode(), 200);
assertEquals(Files.size(tempFile), fileAsString.length());
assertEquals(Files.readAllBytes(tempFile), fileAsBytes);
break;
case STRING:
- BodyHandler<String> bh5 = asString();
- if(bufferResponseBody) bh5 = buffering(bh5, 47);
+ BodyHandler<String> bh5 = BodyHandlers.ofString();
+ if(bufferResponseBody) bh5 = BodyHandlers.buffering(bh5, 47);
HttpResponse<String> sr = getResponse(client, request, bh5, async);
assertEquals(sr.statusCode(), 200);
assertEquals(sr.body(), fileAsString);
break;
case STRING_WITH_CHARSET:
- BodyHandler<String> bh6 = asString(StandardCharsets.UTF_8);
- if (bufferResponseBody) bh6 = buffering(bh6, 53);
+ BodyHandler<String> bh6 = BodyHandlers.ofString(StandardCharsets.UTF_8);
+ if (bufferResponseBody) bh6 = BodyHandlers.buffering(bh6, 53);
HttpResponse<String> r = getResponse(client, request, bh6, async);
assertEquals(r.statusCode(), 200);
assertEquals(r.body(), fileAsString);
--- a/test/jdk/java/net/httpclient/RequestBuilderTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/RequestBuilderTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -34,14 +34,13 @@
import java.util.Set;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import static java.time.Duration.ofNanos;
import static java.time.Duration.ofMinutes;
import static java.time.Duration.ofSeconds;
import static java.time.Duration.ZERO;
import static java.net.http.HttpClient.Version.HTTP_1_1;
import static java.net.http.HttpClient.Version.HTTP_2;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpRequest.BodyPublisher.noBody;
import static java.net.http.HttpRequest.newBuilder;
import static org.testng.Assert.*;
@@ -137,51 +136,51 @@
assertEquals(request.method(), "GET");
assertTrue(!request.bodyPublisher().isPresent());
- request = newBuilder(uri).POST(fromString("")).GET().build();
+ request = newBuilder(uri).POST(BodyPublishers.ofString("")).GET().build();
assertEquals(request.method(), "GET");
assertTrue(!request.bodyPublisher().isPresent());
- request = newBuilder(uri).PUT(fromString("")).GET().build();
+ request = newBuilder(uri).PUT(BodyPublishers.ofString("")).GET().build();
assertEquals(request.method(), "GET");
assertTrue(!request.bodyPublisher().isPresent());
- request = newBuilder(uri).DELETE(fromString("")).GET().build();
+ request = newBuilder(uri).DELETE(BodyPublishers.ofString("")).GET().build();
assertEquals(request.method(), "GET");
assertTrue(!request.bodyPublisher().isPresent());
- request = newBuilder(uri).POST(fromString("")).build();
+ request = newBuilder(uri).POST(BodyPublishers.ofString("")).build();
assertEquals(request.method(), "POST");
assertTrue(request.bodyPublisher().isPresent());
- request = newBuilder(uri).PUT(fromString("")).build();
+ request = newBuilder(uri).PUT(BodyPublishers.ofString("")).build();
assertEquals(request.method(), "PUT");
assertTrue(request.bodyPublisher().isPresent());
- request = newBuilder(uri).DELETE(fromString("")).build();
+ request = newBuilder(uri).DELETE(BodyPublishers.ofString("")).build();
assertEquals(request.method(), "DELETE");
assertTrue(request.bodyPublisher().isPresent());
- request = newBuilder(uri).GET().POST(fromString("")).build();
+ request = newBuilder(uri).GET().POST(BodyPublishers.ofString("")).build();
assertEquals(request.method(), "POST");
assertTrue(request.bodyPublisher().isPresent());
- request = newBuilder(uri).GET().PUT(fromString("")).build();
+ request = newBuilder(uri).GET().PUT(BodyPublishers.ofString("")).build();
assertEquals(request.method(), "PUT");
assertTrue(request.bodyPublisher().isPresent());
- request = newBuilder(uri).GET().DELETE(fromString("")).build();
+ request = newBuilder(uri).GET().DELETE(BodyPublishers.ofString("")).build();
assertEquals(request.method(), "DELETE");
assertTrue(request.bodyPublisher().isPresent());
// CONNECT is disallowed in the implementation, since it is used for
// tunneling, and is handled separately for security checks.
- assertThrows(IAE, () -> newBuilder(uri).method("CONNECT", noBody()).build());
+ assertThrows(IAE, () -> newBuilder(uri).method("CONNECT", BodyPublishers.noBody()).build());
- request = newBuilder(uri).method("GET", noBody()).build();
+ request = newBuilder(uri).method("GET", BodyPublishers.noBody()).build();
assertEquals(request.method(), "GET");
assertTrue(request.bodyPublisher().isPresent());
- request = newBuilder(uri).method("POST", fromString("")).build();
+ request = newBuilder(uri).method("POST", BodyPublishers.ofString("")).build();
assertEquals(request.method(), "POST");
assertTrue(request.bodyPublisher().isPresent());
}
@@ -360,7 +359,7 @@
public void testCopy() {
HttpRequest.Builder builder = newBuilder(uri).expectContinue(true)
.header("A", "B")
- .POST(fromString(""))
+ .POST(BodyPublishers.ofString(""))
.timeout(ofSeconds(30))
.version(HTTP_1_1);
HttpRequest.Builder copy = builder.copy();
@@ -410,13 +409,13 @@
assertEquals(builder.build(), builder.build());
assertEquals(builder.build(), newBuilder(uri).build());
- builder.POST(noBody());
+ builder.POST(BodyPublishers.noBody());
assertEquals(builder.build(), builder.build());
- assertEquals(builder.build(), newBuilder(uri).POST(noBody()).build());
- assertEquals(builder.build(), newBuilder(uri).POST(fromString("")).build());
+ assertEquals(builder.build(), newBuilder(uri).POST(BodyPublishers.noBody()).build());
+ assertEquals(builder.build(), newBuilder(uri).POST(BodyPublishers.ofString("")).build());
assertNotEquals(builder.build(), newBuilder(uri).build());
assertNotEquals(builder.build(), newBuilder(uri).GET().build());
- assertNotEquals(builder.build(), newBuilder(uri).PUT(noBody()).build());
+ assertNotEquals(builder.build(), newBuilder(uri).PUT(BodyPublishers.noBody()).build());
builder = newBuilder(uri).header("x", "y");
assertEquals(builder.build(), builder.build());
--- a/test/jdk/java/net/httpclient/ShortRequestBody.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ShortRequestBody.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,12 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
+import java.net.http.HttpTimeoutException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -40,14 +46,8 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
-import java.net.http.HttpClient;
-import java.net.http.HttpResponse;
-import java.net.http.HttpRequest;
-import java.net.http.HttpTimeoutException;
-
import static java.lang.System.err;
import static java.nio.charset.StandardCharsets.US_ASCII;
-import static java.net.http.HttpResponse.BodyHandler.discard;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
@@ -102,21 +102,21 @@
static class StringRequestBody extends AbstractDelegateRequestBody {
StringRequestBody(String body, int additionalLength) {
- super(HttpRequest.BodyPublisher.fromString(body),
+ super(HttpRequest.BodyPublishers.ofString(body),
body.getBytes(UTF_8).length + additionalLength);
}
}
static class ByteArrayRequestBody extends AbstractDelegateRequestBody {
ByteArrayRequestBody(byte[] body, int additionalLength) {
- super(HttpRequest.BodyPublisher.fromByteArray(body),
+ super(BodyPublishers.ofByteArray(body),
body.length + additionalLength);
}
}
static class FileRequestBody extends AbstractDelegateRequestBody {
FileRequestBody(Path path, int additionalLength) throws IOException {
- super(HttpRequest.BodyPublisher.fromFile(path),
+ super(BodyPublishers.ofFile(path),
Files.size(path) + additionalLength);
}
}
@@ -164,7 +164,7 @@
HttpRequest request = HttpRequest.newBuilder(uri)
.POST(publisher)
.build();
- cf = clientSupplier.get().sendAsync(request, discard());
+ cf = clientSupplier.get().sendAsync(request, BodyHandlers.discarding());
HttpResponse<Void> resp = cf.get(30, TimeUnit.SECONDS);
err.println("Response code: " + resp.statusCode());
@@ -181,7 +181,7 @@
HttpRequest request = HttpRequest.newBuilder(uri)
.POST(publisher)
.build();
- cf = clientSupplier.get().sendAsync(request, discard());
+ cf = clientSupplier.get().sendAsync(request, BodyHandlers.discarding());
try {
HttpResponse<Void> r = cf.get(30, TimeUnit.SECONDS);
@@ -208,7 +208,8 @@
.POST(publisher)
.build();
try {
- HttpResponse<Void> r = clientSupplier.get().send(request, discard());
+ HttpResponse<Void> r = clientSupplier.get()
+ .send(request, BodyHandlers.discarding());
throw new RuntimeException("Unexpected response: " + r.statusCode());
} catch (HttpTimeoutException x) {
throw new RuntimeException("Unexpected timeout", x);
--- a/test/jdk/java/net/httpclient/SmallTimeout.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/SmallTimeout.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpTimeoutException;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
@@ -34,7 +35,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import static java.lang.System.out;
-import static java.net.http.HttpResponse.BodyHandler.replace;
/**
* @test
@@ -92,7 +92,7 @@
final HttpRequest req = requests[i];
CompletableFuture<HttpResponse<Object>> response = client
- .sendAsync(req, replace(null))
+ .sendAsync(req, BodyHandlers.replacing(null))
.whenComplete((HttpResponse<Object> r, Throwable t) -> {
Throwable cause = null;
if (r != null) {
@@ -142,7 +142,7 @@
executor.execute(() -> {
Throwable cause = null;
try {
- client.send(req, replace(null));
+ client.send(req, BodyHandlers.replacing(null));
} catch (HttpTimeoutException e) {
out.println("Caught expected timeout: " + e);
} catch (Throwable ee) {
--- a/test/jdk/java/net/httpclient/SmokeTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/SmokeTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -32,7 +32,10 @@
* @compile ../../../com/sun/net/httpserver/LogFilter.java
* @compile ../../../com/sun/net/httpserver/EchoHandler.java
* @compile ../../../com/sun/net/httpserver/FileServerHandler.java
- * @run main/othervm -Djdk.internal.httpclient.debugX=true -Djdk.httpclient.HttpClient.log=errors,ssl,trace SmokeTest
+ * @run main/othervm
+ * -Djdk.internal.httpclient.debugX=true
+ * -Djdk.httpclient.HttpClient.log=errors,ssl,trace
+ * SmokeTest
*/
import com.sun.net.httpserver.Headers;
@@ -54,8 +57,9 @@
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
-import java.nio.file.StandardOpenOption;
+import java.net.http.HttpResponse.BodyHandlers;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -83,12 +87,9 @@
import java.util.List;
import java.util.Random;
import jdk.testlibrary.SimpleSSLContext;
-import static java.net.http.HttpRequest.BodyPublisher.fromFile;
-import static java.net.http.HttpRequest.BodyPublisher.fromInputStream;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.*;
-import static java.net.http.HttpResponse.BodyHandler.asFile;
-import static java.net.http.HttpResponse.BodyHandler.asString;
+import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
+import static java.nio.file.StandardOpenOption.WRITE;
+
import java.util.concurrent.CountDownLatch;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
@@ -252,7 +253,7 @@
HttpRequest request = builder.build();
- HttpResponse<String> response = client.send(request, asString());
+ HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
String body = response.body();
if (!body.equals("This is foo.txt\r\n")) {
@@ -263,7 +264,7 @@
}
// repeat async
- HttpResponse<String> response1 = client.sendAsync(request, asString())
+ HttpResponse<String> response1 = client.sendAsync(request, BodyHandlers.ofString())
.join();
String body1 = response1.body();
@@ -279,10 +280,10 @@
URI uri = new URI(s);
HttpRequest request = HttpRequest.newBuilder(uri)
- .POST(fromString(body))
+ .POST(BodyPublishers.ofString(body))
.build();
- HttpResponse<String> response = client.send(request, asString());
+ HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
if (response.statusCode() != 200) {
throw new RuntimeException(
@@ -303,16 +304,13 @@
Path p = getTempFile(128 * 1024);
HttpRequest request = HttpRequest.newBuilder(uri)
- .POST(fromFile(p))
+ .POST(BodyPublishers.ofFile(p))
.build();
Path resp = getTempFile(1); // will be overwritten
- HttpResponse<Path> response =
- client.send(request,
- BodyHandler.asFile(resp,
- StandardOpenOption.TRUNCATE_EXISTING,
- StandardOpenOption.WRITE));
+ HttpResponse<Path> response = client.send(request,
+ BodyHandlers.ofFile(resp, TRUNCATE_EXISTING, WRITE));
if (response.statusCode() != 200) {
throw new RuntimeException(
@@ -342,7 +340,7 @@
.build();
HttpResponse<Path> response = client.send(request,
- asFile(Paths.get("redir1.txt")));
+ BodyHandlers.ofFile(Paths.get("redir1.txt")));
if (response.statusCode() != 200) {
throw new RuntimeException(
@@ -363,7 +361,8 @@
request = HttpRequest.newBuilder(uri).build();
- response = client.sendAsync(request, asFile(Paths.get("redir2.txt"))).join();
+ response = client.sendAsync(request,
+ BodyHandlers.ofFile(Paths.get("redir2.txt"))).join();
if (response.statusCode() != 200) {
throw new RuntimeException(
@@ -466,7 +465,7 @@
HttpRequest request = HttpRequest.newBuilder(uri).GET().build();
- CompletableFuture<String> fut = cl.sendAsync(request, asString())
+ CompletableFuture<String> fut = cl.sendAsync(request, BodyHandlers.ofString())
.thenApply((response) -> response.body());
String body = fut.get(5, TimeUnit.HOURS);
@@ -492,7 +491,7 @@
HttpRequest.Builder builder = HttpRequest.newBuilder(uri)
.expectContinue(true)
- .POST(fromString(requestBody));
+ .POST(BodyPublishers.ofString(requestBody));
if (fixedLen) {
builder.header("XFixed", "yes");
@@ -500,7 +499,7 @@
HttpRequest request = builder.build();
- HttpResponse<String> response = client.send(request, asString());
+ HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
String body = response.body();
@@ -525,7 +524,7 @@
HttpRequest request = builder.build();
- HttpResponse<String> response = client.send(request, asString());
+ HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
if (response.statusCode() != 200) {
throw new RuntimeException(
@@ -550,7 +549,7 @@
HttpRequest request = HttpRequest.newBuilder().uri(uri).GET().build();
for (int i=0; i<4; i++) {
- HttpResponse<String> r = client.send(request, asString());
+ HttpResponse<String> r = client.send(request, BodyHandlers.ofString());
String body = r.body();
if (!body.equals("OK")) {
throw new RuntimeException("Expected OK, got: " + body);
@@ -558,10 +557,13 @@
}
// Second test: 4 x parallel
- request = HttpRequest.newBuilder().uri(uri).POST(fromFile(requestBody)).build();
+ request = HttpRequest.newBuilder()
+ .uri(uri)
+ .POST(BodyPublishers.ofFile(requestBody))
+ .build();
List<CompletableFuture<String>> futures = new LinkedList<>();
for (int i=0; i<4; i++) {
- futures.add(client.sendAsync(request, asString())
+ futures.add(client.sendAsync(request, BodyHandlers.ofString())
.thenApply((response) -> {
if (response.statusCode() == 200)
return response.body();
@@ -584,7 +586,7 @@
request = HttpRequest.newBuilder(uri).GET().build();
BlockingQueue<String> q = new LinkedBlockingQueue<>();
for (int i=0; i<4; i++) {
- client.sendAsync(request, asString())
+ client.sendAsync(request, BodyHandlers.ofString())
.thenApply((HttpResponse<String> resp) -> {
String body = resp.body();
putQ(q, body);
@@ -601,7 +603,7 @@
if (!body.equals("OK")) {
throw new RuntimeException(body);
}
- client.sendAsync(request, asString())
+ client.sendAsync(request, BodyHandlers.ofString())
.thenApply((resp) -> {
if (resp.statusCode() == 200)
putQ(q, resp.body());
@@ -647,12 +649,12 @@
URI uri = new URI(target);
HttpRequest request = HttpRequest.newBuilder(uri)
- .POST(fromInputStream(SmokeTest::newStream))
- .build();
+ .POST(BodyPublishers.ofInputStream(SmokeTest::newStream))
+ .build();
Path download = Paths.get("test11.txt");
- HttpResponse<Path> response = client.send(request, asFile(download));
+ HttpResponse<Path> response = client.send(request, BodyHandlers.ofFile(download));
if (response.statusCode() != 200) {
throw new RuntimeException("Wrong response code");
@@ -685,7 +687,7 @@
HttpRequest request = HttpRequest.newBuilder(uri).GET().build();
CompletableFuture<HttpResponse<String>> cf =
- client.sendAsync(request, asString());
+ client.sendAsync(request, BodyHandlers.ofString());
try {
HttpResponse<String> response = cf.join();
--- a/test/jdk/java/net/httpclient/SplitResponse.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/SplitResponse.java Sat Feb 24 11:27:11 2018 +0000
@@ -36,7 +36,7 @@
import static java.lang.System.out;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static java.net.http.HttpResponse.BodyHandler.asString;
+import static java.net.http.HttpResponse.BodyHandlers.ofString;
/**
* @test
@@ -150,7 +150,7 @@
// .newBuilder(uri2).version(version).build();
// while (true) {
// try {
- // client.send(request, HttpResponse.BodyHandler.asString());
+ // client.send(request, HttpResponse.BodyHandlers.ofString());
// } catch (IOException ex) {
// System.out.println("Client rejected " + request);
// }
@@ -177,11 +177,11 @@
if (async) {
out.println("send async: " + request);
- cf1 = client.sendAsync(request, asString());
+ cf1 = client.sendAsync(request, ofString());
r = cf1.get();
} else { // sync
out.println("send sync: " + request);
- r = client.send(request, asString());
+ r = client.send(request, ofString());
}
out.println("response " + r);
--- a/test/jdk/java/net/httpclient/SubscriberPublisherAPIExceptions.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/SubscriberPublisherAPIExceptions.java Sat Feb 24 11:27:11 2018 +0000
@@ -31,9 +31,11 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Flow;
import java.net.http.HttpHeaders;
-import java.net.http.HttpRequest.BodyPublisher;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import java.util.function.Function;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -59,20 +61,20 @@
@Test
public void publisherAPIExceptions() {
- assertThrows(NPE, () -> BodyPublisher.fromByteArray(null));
- assertThrows(NPE, () -> BodyPublisher.fromByteArray(null, 0, 1));
- assertThrows(IOB, () -> BodyPublisher.fromByteArray(new byte[100], 0, 101));
- assertThrows(IOB, () -> BodyPublisher.fromByteArray(new byte[100], 1, 100));
- assertThrows(IOB, () -> BodyPublisher.fromByteArray(new byte[100], -1, 10));
- assertThrows(IOB, () -> BodyPublisher.fromByteArray(new byte[100], 99, 2));
- assertThrows(IOB, () -> BodyPublisher.fromByteArray(new byte[1], -100, 1));
- assertThrows(NPE, () -> BodyPublisher.fromByteArrays(null));
- assertThrows(NPE, () -> BodyPublisher.fromFile(null));
- assertThrows(NPE, () -> BodyPublisher.fromInputStream(null));
- assertThrows(NPE, () -> BodyPublisher.fromString(null));
- assertThrows(NPE, () -> BodyPublisher.fromString("A", null));
- assertThrows(NPE, () -> BodyPublisher.fromString(null, UTF_8));
- assertThrows(NPE, () -> BodyPublisher.fromString(null, null));
+ assertThrows(NPE, () -> BodyPublishers.ofByteArray(null));
+ assertThrows(NPE, () -> BodyPublishers.ofByteArray(null, 0, 1));
+ assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], 0, 101));
+ assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], 1, 100));
+ assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], -1, 10));
+ assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], 99, 2));
+ assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[1], -100, 1));
+ assertThrows(NPE, () -> BodyPublishers.ofByteArray(null));
+ assertThrows(NPE, () -> BodyPublishers.ofFile(null));
+ assertThrows(NPE, () -> BodyPublishers.ofInputStream(null));
+ assertThrows(NPE, () -> BodyPublishers.ofString(null));
+ assertThrows(NPE, () -> BodyPublishers.ofString("A", null));
+ assertThrows(NPE, () -> BodyPublishers.ofString(null, UTF_8));
+ assertThrows(NPE, () -> BodyPublishers.ofString(null, null));
}
@DataProvider(name = "nonExistentFiles")
@@ -90,7 +92,7 @@
@Test(dataProvider = "nonExistentFiles", expectedExceptions = FileNotFoundException.class)
public void fromFileCheck(Path path) throws Exception {
- BodyPublisher.fromFile(path);
+ BodyPublishers.ofFile(path);
}
@Test
@@ -101,59 +103,59 @@
if (Files.exists(doesNotExist))
throw new AssertionError("Unexpected " + doesNotExist);
- assertThrows(NPE, () -> BodyHandler.asByteArrayConsumer(null));
- assertThrows(NPE, () -> BodyHandler.asFile(null));
- assertThrows(NPE, () -> BodyHandler.asFile(null, CREATE, WRITE));
- assertThrows(NPE, () -> BodyHandler.asFile(path, (OpenOption[])null));
- assertThrows(NPE, () -> BodyHandler.asFile(path, new OpenOption[] {null}));
- assertThrows(NPE, () -> BodyHandler.asFile(path, new OpenOption[] {CREATE, null}));
- assertThrows(NPE, () -> BodyHandler.asFile(path, new OpenOption[] {null, CREATE}));
- assertThrows(NPE, () -> BodyHandler.asFile(null, (OpenOption[])null));
- assertThrows(NPE, () -> BodyHandler.asFileDownload(null, CREATE, WRITE));
- assertThrows(NPE, () -> BodyHandler.asFileDownload(path, (OpenOption[])null));
- assertThrows(NPE, () -> BodyHandler.asFileDownload(path, new OpenOption[] {null}));
- assertThrows(NPE, () -> BodyHandler.asFileDownload(path, new OpenOption[] {CREATE, null}));
- assertThrows(NPE, () -> BodyHandler.asFileDownload(path, new OpenOption[] {null, CREATE}));
- assertThrows(NPE, () -> BodyHandler.asFileDownload(null, (OpenOption[])null));
- assertThrows(IAE, () -> BodyHandler.asFileDownload(file, CREATE, WRITE));
- assertThrows(IAE, () -> BodyHandler.asFileDownload(doesNotExist, CREATE, WRITE));
- assertThrows(NPE, () -> BodyHandler.asString(null));
- assertThrows(NPE, () -> BodyHandler.buffering(null, 1));
- assertThrows(IAE, () -> BodyHandler.buffering(new NoOpHandler(), 0));
- assertThrows(IAE, () -> BodyHandler.buffering(new NoOpHandler(), -1));
- assertThrows(IAE, () -> BodyHandler.buffering(new NoOpHandler(), Integer.MIN_VALUE));
+ assertThrows(NPE, () -> BodyHandlers.ofByteArrayConsumer(null));
+ assertThrows(NPE, () -> BodyHandlers.ofFile(null));
+ assertThrows(NPE, () -> BodyHandlers.ofFile(null, CREATE, WRITE));
+ assertThrows(NPE, () -> BodyHandlers.ofFile(path, (OpenOption[])null));
+ assertThrows(NPE, () -> BodyHandlers.ofFile(path, new OpenOption[] {null}));
+ assertThrows(NPE, () -> BodyHandlers.ofFile(path, new OpenOption[] {CREATE, null}));
+ assertThrows(NPE, () -> BodyHandlers.ofFile(path, new OpenOption[] {null, CREATE}));
+ assertThrows(NPE, () -> BodyHandlers.ofFile(null, (OpenOption[])null));
+ assertThrows(NPE, () -> BodyHandlers.ofFileDownload(null, CREATE, WRITE));
+ assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, (OpenOption[])null));
+ assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, new OpenOption[] {null}));
+ assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, new OpenOption[] {CREATE, null}));
+ assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, new OpenOption[] {null, CREATE}));
+ assertThrows(NPE, () -> BodyHandlers.ofFileDownload(null, (OpenOption[])null));
+ assertThrows(IAE, () -> BodyHandlers.ofFileDownload(file, CREATE, WRITE));
+ assertThrows(IAE, () -> BodyHandlers.ofFileDownload(doesNotExist, CREATE, WRITE));
+ assertThrows(NPE, () -> BodyHandlers.ofString(null));
+ assertThrows(NPE, () -> BodyHandlers.buffering(null, 1));
+ assertThrows(IAE, () -> BodyHandlers.buffering(new NoOpHandler(), 0));
+ assertThrows(IAE, () -> BodyHandlers.buffering(new NoOpHandler(), -1));
+ assertThrows(IAE, () -> BodyHandlers.buffering(new NoOpHandler(), Integer.MIN_VALUE));
// implementation specific exceptions
- assertThrows(IAE, () -> BodyHandler.asFile(path, READ));
- assertThrows(IAE, () -> BodyHandler.asFile(path, DELETE_ON_CLOSE));
- assertThrows(IAE, () -> BodyHandler.asFile(path, READ, DELETE_ON_CLOSE));
- assertThrows(IAE, () -> BodyHandler.asFileDownload(path, DELETE_ON_CLOSE));
+ assertThrows(IAE, () -> BodyHandlers.ofFile(path, READ));
+ assertThrows(IAE, () -> BodyHandlers.ofFile(path, DELETE_ON_CLOSE));
+ assertThrows(IAE, () -> BodyHandlers.ofFile(path, READ, DELETE_ON_CLOSE));
+ assertThrows(IAE, () -> BodyHandlers.ofFileDownload(path, DELETE_ON_CLOSE));
}
@Test
public void subscriberAPIExceptions() {
Path path = Paths.get(".").resolve("tt");
- assertThrows(NPE, () -> BodySubscriber.asByteArrayConsumer(null));
- assertThrows(NPE, () -> BodySubscriber.asFile(null));
- assertThrows(NPE, () -> BodySubscriber.asFile(null, CREATE, WRITE));
- assertThrows(NPE, () -> BodySubscriber.asFile(path, (OpenOption[])null));
- assertThrows(NPE, () -> BodySubscriber.asFile(path, new OpenOption[] {null}));
- assertThrows(NPE, () -> BodySubscriber.asFile(path, new OpenOption[] {CREATE, null}));
- assertThrows(NPE, () -> BodySubscriber.asFile(path, new OpenOption[] {null, CREATE}));
- assertThrows(NPE, () -> BodySubscriber.asFile(null, (OpenOption[])null));
- assertThrows(NPE, () -> BodySubscriber.asString(null));
- assertThrows(NPE, () -> BodySubscriber.buffering(null, 1));
- assertThrows(IAE, () -> BodySubscriber.buffering(new NoOpSubscriber(), 0));
- assertThrows(IAE, () -> BodySubscriber.buffering(new NoOpSubscriber(), -1));
- assertThrows(IAE, () -> BodySubscriber.buffering(new NoOpSubscriber(), Integer.MIN_VALUE));
- assertThrows(NPE, () -> BodySubscriber.mapping(null, Function.identity()));
- assertThrows(NPE, () -> BodySubscriber.mapping(BodySubscriber.asByteArray(), null));
- assertThrows(NPE, () -> BodySubscriber.mapping(null, null));
+ assertThrows(NPE, () -> BodySubscribers.ofByteArrayConsumer(null));
+ assertThrows(NPE, () -> BodySubscribers.ofFile(null));
+ assertThrows(NPE, () -> BodySubscribers.ofFile(null, CREATE, WRITE));
+ assertThrows(NPE, () -> BodySubscribers.ofFile(path, (OpenOption[])null));
+ assertThrows(NPE, () -> BodySubscribers.ofFile(path, new OpenOption[] {null}));
+ assertThrows(NPE, () -> BodySubscribers.ofFile(path, new OpenOption[] {CREATE, null}));
+ assertThrows(NPE, () -> BodySubscribers.ofFile(path, new OpenOption[] {null, CREATE}));
+ assertThrows(NPE, () -> BodySubscribers.ofFile(null, (OpenOption[])null));
+ assertThrows(NPE, () -> BodySubscribers.ofString(null));
+ assertThrows(NPE, () -> BodySubscribers.buffering(null, 1));
+ assertThrows(IAE, () -> BodySubscribers.buffering(new NoOpSubscriber(), 0));
+ assertThrows(IAE, () -> BodySubscribers.buffering(new NoOpSubscriber(), -1));
+ assertThrows(IAE, () -> BodySubscribers.buffering(new NoOpSubscriber(), Integer.MIN_VALUE));
+ assertThrows(NPE, () -> BodySubscribers.mapping(null, Function.identity()));
+ assertThrows(NPE, () -> BodySubscribers.mapping(BodySubscribers.ofByteArray(), null));
+ assertThrows(NPE, () -> BodySubscribers.mapping(null, null));
// implementation specific exceptions
- assertThrows(IAE, () -> BodySubscriber.asFile(path, READ));
- assertThrows(IAE, () -> BodySubscriber.asFile(path, DELETE_ON_CLOSE));
- assertThrows(IAE, () -> BodySubscriber.asFile(path, READ, DELETE_ON_CLOSE));
+ assertThrows(IAE, () -> BodySubscribers.ofFile(path, READ));
+ assertThrows(IAE, () -> BodySubscribers.ofFile(path, DELETE_ON_CLOSE));
+ assertThrows(IAE, () -> BodySubscribers.ofFile(path, READ, DELETE_ON_CLOSE));
}
static class NoOpHandler implements BodyHandler<Void> {
--- a/test/jdk/java/net/httpclient/ThrowingSubscribers.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ThrowingSubscribers.java Sat Feb 24 11:27:11 2018 +0000
@@ -58,6 +58,7 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscriber;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
@@ -246,7 +247,7 @@
.build();
BodyHandler<String> handler =
new ThrowingBodyHandler((w) -> {},
- BodyHandler.asString());
+ BodyHandlers.ofString());
HttpResponse<String> response = client.send(req, handler);
String body = response.body();
assertEquals(URI.create(body).getPath(), URI.create(uri).getPath());
@@ -261,7 +262,7 @@
{
String test = format("testThrowingAsString(%s, %b, %s)",
uri, sameClient, thrower);
- testThrowing(test, uri, sameClient, BodyHandler::asString,
+ testThrowing(test, uri, sameClient, BodyHandlers::ofString,
this::shouldHaveThrown, thrower,false);
}
@@ -273,7 +274,7 @@
{
String test = format("testThrowingAsLines(%s, %b, %s)",
uri, sameClient, thrower);
- testThrowing(test, uri, sameClient, BodyHandler::asLines,
+ testThrowing(test, uri, sameClient, BodyHandlers::ofLines,
this::checkAsLines, thrower,false);
}
@@ -285,7 +286,7 @@
{
String test = format("testThrowingAsInputStream(%s, %b, %s)",
uri, sameClient, thrower);
- testThrowing(test, uri, sameClient, BodyHandler::asInputStream,
+ testThrowing(test, uri, sameClient, BodyHandlers::ofInputStream,
this::checkAsInputStream, thrower,false);
}
@@ -297,7 +298,7 @@
{
String test = format("testThrowingAsStringAsync(%s, %b, %s)",
uri, sameClient, thrower);
- testThrowing(test, uri, sameClient, BodyHandler::asString,
+ testThrowing(test, uri, sameClient, BodyHandlers::ofString,
this::shouldHaveThrown, thrower, true);
}
@@ -309,7 +310,7 @@
{
String test = format("testThrowingAsLinesAsync(%s, %b, %s)",
uri, sameClient, thrower);
- testThrowing(test, uri, sameClient, BodyHandler::asLines,
+ testThrowing(test, uri, sameClient, BodyHandlers::ofLines,
this::checkAsLines, thrower,true);
}
@@ -321,7 +322,7 @@
{
String test = format("testThrowingAsInputStreamAsync(%s, %b, %s)",
uri, sameClient, thrower);
- testThrowing(test, uri, sameClient, BodyHandler::asInputStream,
+ testThrowing(test, uri, sameClient, BodyHandlers::ofInputStream,
this::checkAsInputStream, thrower,true);
}
--- a/test/jdk/java/net/httpclient/TimeoutBasic.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/TimeoutBasic.java Sat Feb 24 11:27:11 2018 +0000
@@ -27,6 +27,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpTimeoutException;
import jdk.testlibrary.SimpleSSLContext;
@@ -40,7 +41,6 @@
import java.util.function.Function;
import static java.lang.System.out;
-import static java.net.http.HttpResponse.BodyHandler.discard;
/**
* @test
@@ -96,17 +96,17 @@
}
static HttpRequest.Builder DELETE(HttpRequest.Builder builder) {
- HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublisher.noBody();
+ HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublishers.noBody();
return builder.DELETE(noBody);
}
static HttpRequest.Builder PUT(HttpRequest.Builder builder) {
- HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublisher.noBody();
+ HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublishers.noBody();
return builder.PUT(noBody);
}
static HttpRequest.Builder POST(HttpRequest.Builder builder) {
- HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublisher.noBody();
+ HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublishers.noBody();
return builder.POST(noBody);
}
@@ -152,7 +152,7 @@
if (request == null) continue;
count++;
try {
- HttpResponse<?> resp = client.sendAsync(request, discard()).join();
+ HttpResponse<?> resp = client.sendAsync(request, BodyHandlers.discarding()).join();
out.println("Unexpected response for: " + request);
out.println("\t from " + ss.getLocalSocketAddress());
out.println("Response is: " + resp);
@@ -177,7 +177,7 @@
if (request == null) continue;
count++;
try {
- client.send(request, discard());
+ client.send(request, BodyHandlers.discarding());
} catch (HttpTimeoutException e) {
out.println("Caught expected timeout: " + e);
}
--- a/test/jdk/java/net/httpclient/TimeoutOrdering.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/TimeoutOrdering.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpTimeoutException;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
@@ -34,7 +35,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import static java.lang.System.out;
-import static java.net.http.HttpResponse.BodyHandler.replace;
/**
* @test
@@ -74,7 +74,7 @@
final HttpRequest req = requests[i];
CompletableFuture<HttpResponse<Object>> response = client
- .sendAsync(req, replace(null))
+ .sendAsync(req, BodyHandlers.replacing(null))
.whenComplete((HttpResponse<Object> r, Throwable t) -> {
if (r != null) {
out.println("Unexpected response: " + r);
@@ -115,7 +115,7 @@
final HttpRequest req = requests[i];
executor.execute(() -> {
try {
- client.send(req, replace(null));
+ client.send(req, BodyHandlers.replacing(null));
} catch (HttpTimeoutException e) {
out.println("Caught expected timeout: " + e);
queue.offer(req);
--- a/test/jdk/java/net/httpclient/VersionTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/VersionTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -42,18 +42,13 @@
import java.net.ProxySelector;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
-import java.net.InetSocketAddress;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
-import static java.net.http.HttpResponse.BodyHandler.discard;
+import java.net.http.HttpResponse.BodyHandlers;
import static java.net.http.HttpClient.Version.HTTP_1_1;
import static java.net.http.HttpClient.Version.HTTP_2;
-/**
- */
public class VersionTest {
static HttpServer s1 ;
static ProxyServer proxy;
@@ -98,7 +93,7 @@
.GET()
.build();
HttpClient c = proxy ? clientWithProxy : client;
- HttpResponse<Void> resp = c.send(r, discard());
+ HttpResponse<Void> resp = c.send(r, BodyHandlers.discarding());
System.out.printf("Client: response is %d\n", resp.statusCode());
if (resp.version() != HTTP_1_1) {
throw new RuntimeException();
@@ -124,36 +119,34 @@
int proxyPort = proxy.getPort();
proxyAddr = new InetSocketAddress("127.0.0.1", proxyPort);
}
-}
-class Handler implements HttpHandler {
- int counter = 0;
+ static class Handler implements HttpHandler {
+ int counter;
- void checkHeader(Headers h) {
- counter++;
- if (counter == 1 && h.containsKey("Upgrade")) {
- VersionTest.error = true;
+ void checkHeader(Headers h) {
+ counter++;
+ if (counter == 1 && h.containsKey("Upgrade")) {
+ VersionTest.error = true;
+ }
+ if (counter == 2 && !h.containsKey("Upgrade")) {
+ VersionTest.error = true;
+ }
+ if (counter == 3 && h.containsKey("Upgrade")) {
+ VersionTest.error = true;
+ }
}
- if (counter == 2 && !h.containsKey("Upgrade")) {
- VersionTest.error = true;
- }
- if (counter == 3 && h.containsKey("Upgrade")) {
- VersionTest.error = true;
+
+ @Override
+ public synchronized void handle(HttpExchange t) throws IOException {
+ String reply = "Hello world";
+ int len = reply.length();
+ Headers h = t.getRequestHeaders();
+ checkHeader(h);
+ System.out.printf("Sending response 200\n");
+ t.sendResponseHeaders(200, len);
+ OutputStream o = t.getResponseBody();
+ o.write(reply.getBytes());
+ t.close();
}
}
-
- @Override
- public synchronized void handle(HttpExchange t)
- throws IOException
- {
- String reply = "Hello world";
- int len = reply.length();
- Headers h = t.getRequestHeaders();
- checkHeader(h);
- System.out.printf("Sending response 200\n");
- t.sendResponseHeaders(200, len);
- OutputStream o = t.getResponseBody();
- o.write(reply.getBytes());
- t.close();
- }
-}
+}
\ No newline at end of file
--- a/test/jdk/java/net/httpclient/ZeroRedirects.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ZeroRedirects.java Sat Feb 24 11:27:11 2018 +0000
@@ -28,7 +28,6 @@
* @run main/othervm ZeroRedirects
*/
-import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
@@ -36,20 +35,14 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.net.InetSocketAddress;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
-import static java.net.http.HttpResponse.BodyHandler.discard;
-import static java.net.http.HttpClient.Version.HTTP_1_1;
-import static java.net.http.HttpClient.Version.HTTP_2;
-/**
- */
public class ZeroRedirects {
static HttpServer s1 ;
static ExecutorService executor;
@@ -77,7 +70,7 @@
HttpRequest r = HttpRequest.newBuilder(uri)
.GET()
.build();
- HttpResponse<Void> resp = client.send(r, discard());
+ HttpResponse<Void> resp = client.send(r, BodyHandlers.discarding());
System.out.printf("Client: response is %d\n", resp.statusCode());
if (resp.statusCode() != 200)
throw new RuntimeException();
@@ -98,20 +91,18 @@
uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/foo");
System.out.println("HTTP server port = " + port);
}
-}
-class Handler implements HttpHandler {
+ static class Handler implements HttpHandler {
- @Override
- public synchronized void handle(HttpExchange t)
- throws IOException
- {
- String reply = "Hello world";
- int len = reply.length();
- System.out.printf("Sending response 200\n");
- t.sendResponseHeaders(200, len);
- OutputStream o = t.getResponseBody();
- o.write(reply.getBytes());
- t.close();
+ @Override
+ public synchronized void handle(HttpExchange t) throws IOException {
+ String reply = "Hello world";
+ int len = reply.length();
+ System.out.printf("Sending response 200\n");
+ t.sendResponseHeaders(200, len);
+ OutputStream o = t.getResponseBody();
+ o.write(reply.getBytes());
+ t.close();
+ }
}
}
--- a/test/jdk/java/net/httpclient/examples/JavadocExamples.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/examples/JavadocExamples.java Sat Feb 24 11:27:11 2018 +0000
@@ -26,7 +26,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -54,7 +54,7 @@
* <pre> {@code // A PrintSubscriber that implements Flow.Subscriber<String>
* // and print lines received by onNext() on System.out
* PrintSubscriber subscriber = new PrintSubscriber(System.out);
- * client.sendAsync(request, BodyHandler.fromLineSubscriber(subscriber))
+ * client.sendAsync(request, BodyHandlers.fromLineSubscriber(subscriber))
* .thenApply(HttpResponse::statusCode)
* .thenAccept((status) -> {
* if (status != 200) {
@@ -66,7 +66,7 @@
// A PrintSubscriber that implements Flow.Subscriber<String>
// and print lines received by onNext() on System.out
PrintSubscriber subscriber = new PrintSubscriber(System.out);
- client.sendAsync(request, BodyHandler.fromLineSubscriber(subscriber))
+ client.sendAsync(request, BodyHandlers.fromLineSubscriber(subscriber))
.thenApply(HttpResponse::statusCode)
.thenAccept((status) -> {
if (status != 200) {
@@ -86,7 +86,7 @@
* Pattern pattern = ...;
* LineParserSubscriber subscriber = new LineParserSubscriber(pattern);
* HttpResponse<List<String>> response = client.send(request,
- * BodyHandler.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n"));
+ * BodyHandlers.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n"));
* if (response.statusCode() != 200) {
* System.err.printf("ERROR: %d status received%n", response.statusCode());
* } }</pre>
@@ -98,7 +98,7 @@
Pattern pattern = p;
LineParserSubscriber subscriber = new LineParserSubscriber(pattern);
HttpResponse<List<String>> response = client.send(request,
- BodyHandler.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n"));
+ BodyHandlers.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n"));
if (response.statusCode() != 200) {
System.err.printf("ERROR: %d status received%n", response.statusCode());
}
--- a/test/jdk/java/net/httpclient/http2/BadHeadersTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/BadHeadersTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -53,6 +53,8 @@
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse.BodyHandlers;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -60,8 +62,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
import static jdk.internal.net.http.common.Pair.pair;
import static org.testng.Assert.assertThrows;
@@ -147,15 +147,15 @@
client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(uri))
- .POST(fromString("Hello there!"))
+ .POST(BodyPublishers.ofString("Hello there!"))
.build();
final HttpClient cc = client;
if (i % 2 == 0) {
- assertThrows(IOException.class, () -> cc.send(request, asString()));
+ assertThrows(IOException.class, () -> cc.send(request, BodyHandlers.ofString()));
} else {
Throwable t = null;
try {
- cc.sendAsync(request, asString()).join();
+ cc.sendAsync(request, BodyHandlers.ofString()).join();
} catch (Throwable t0) {
t = t0;
}
--- a/test/jdk/java/net/httpclient/http2/BasicTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/BasicTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -35,22 +35,21 @@
import java.io.IOException;
import java.net.*;
-import java.net.http.*;
-import static java.net.http.HttpClient.Version.HTTP_2;
import javax.net.ssl.*;
+import java.net.http.HttpClient;
+import java.net.http.HttpHeaders;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.nio.file.*;
import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import jdk.testlibrary.SimpleSSLContext;
-import static java.net.http.HttpRequest.BodyPublisher.fromFile;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asFile;
-import static java.net.http.HttpResponse.BodyHandler.asString;
-
import org.testng.annotations.Test;
+import static java.net.http.HttpClient.Version.HTTP_2;
@Test
public class BasicTest {
@@ -203,12 +202,12 @@
HttpClient client = getClient();
Path src = TestUtil.getAFile(FILESIZE * 4);
HttpRequest req = HttpRequest.newBuilder(uri)
- .POST(fromFile(src))
+ .POST(BodyPublishers.ofFile(src))
.build();
Path dest = Paths.get("streamtest.txt");
dest.toFile().delete();
- CompletableFuture<Path> response = client.sendAsync(req, asFile(dest))
+ CompletableFuture<Path> response = client.sendAsync(req, BodyHandlers.ofFile(dest))
.thenApply(resp -> {
if (resp.statusCode() != 200)
throw new RuntimeException();
@@ -233,7 +232,7 @@
URI u = new URI("https://127.0.0.1:"+httpsPort+"/foo");
HttpClient client = getClient();
HttpRequest req = HttpRequest.newBuilder(u).build();
- HttpResponse<String> resp = client.send(req, asString());
+ HttpResponse<String> resp = client.send(req, BodyHandlers.ofString());
int stat = resp.statusCode();
if (stat != 200) {
throw new RuntimeException("paramsTest failed "
@@ -250,9 +249,9 @@
HttpClient client = getClient();
HttpRequest req = HttpRequest.newBuilder(uri)
- .POST(fromString(SIMPLE_STRING))
+ .POST(BodyPublishers.ofString(SIMPLE_STRING))
.build();
- HttpResponse<String> response = client.send(req, asString());
+ HttpResponse<String> response = client.send(req, BodyHandlers.ofString());
checkStatus(200, response.statusCode());
String responseBody = response.body();
HttpHeaders h = response.headers();
@@ -270,10 +269,10 @@
CompletableFuture[] responses = new CompletableFuture[LOOPS];
final Path source = TestUtil.getAFile(FILESIZE);
HttpRequest request = HttpRequest.newBuilder(uri)
- .POST(fromFile(source))
+ .POST(BodyPublishers.ofFile(source))
.build();
for (int i = 0; i < LOOPS; i++) {
- responses[i] = client.sendAsync(request, asFile(tempFile()))
+ responses[i] = client.sendAsync(request, BodyHandlers.ofFile(tempFile()))
//.thenApply(resp -> compareFiles(resp.body(), source));
.thenApply(resp -> {
System.out.printf("Resp status %d body size %d\n",
--- a/test/jdk/java/net/httpclient/http2/ContinuationFrameTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/ContinuationFrameTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -46,7 +46,9 @@
import javax.net.ssl.SSLSession;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import jdk.internal.net.http.common.HttpHeadersImpl;
import jdk.internal.net.http.frame.ContinuationFrame;
import jdk.internal.net.http.frame.HeaderFrame;
@@ -59,8 +61,6 @@
import org.testng.annotations.Test;
import static java.lang.System.out;
import static java.net.http.HttpClient.Version.HTTP_2;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -139,13 +139,13 @@
client = HttpClient.newBuilder().sslContext(sslContext).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(uri))
- .POST(fromString("Hello there!"))
+ .POST(BodyPublishers.ofString("Hello there!"))
.build();
HttpResponse<String> resp;
if (i % 2 == 0) {
- resp = client.send(request, asString());
+ resp = client.send(request, BodyHandlers.ofString());
} else {
- resp = client.sendAsync(request, asString()).join();
+ resp = client.sendAsync(request, BodyHandlers.ofString()).join();
}
out.println("Got response: " + resp);
--- a/test/jdk/java/net/httpclient/http2/ErrorTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/ErrorTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -39,15 +39,15 @@
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import jdk.testlibrary.SimpleSSLContext;
import static java.net.http.HttpClient.Version.HTTP_2;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.discard;
import org.testng.annotations.Test;
@@ -92,11 +92,11 @@
System.err.println("Request to " + uri);
HttpRequest req = HttpRequest.newBuilder(uri)
- .POST(fromString(SIMPLE_STRING))
+ .POST(BodyPublishers.ofString(SIMPLE_STRING))
.build();
HttpResponse response;
try {
- response = client.send(req, discard());
+ response = client.send(req, BodyHandlers.discarding());
throw new RuntimeException("Unexpected response: " + response);
} catch (IOException e) {
System.err.println("Caught Expected IOException: " + e);
--- a/test/jdk/java/net/httpclient/http2/FixedThreadPoolTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/FixedThreadPoolTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -35,16 +35,13 @@
import java.net.*;
import java.net.http.*;
-import static java.net.http.HttpClient.Version.HTTP_2;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse.BodyHandlers;
import javax.net.ssl.*;
import java.nio.file.*;
import java.util.concurrent.*;
import jdk.testlibrary.SimpleSSLContext;
-import static java.net.http.HttpRequest.BodyPublisher.fromFile;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asFile;
-import static java.net.http.HttpResponse.BodyHandler.asString;
-
+import static java.net.http.HttpClient.Version.HTTP_2;
import org.testng.annotations.Test;
@Test
@@ -164,12 +161,12 @@
HttpClient client = getClient();
Path src = TestUtil.getAFile(FILESIZE * 4);
HttpRequest req = HttpRequest.newBuilder(uri)
- .POST(fromFile(src))
+ .POST(BodyPublishers.ofFile(src))
.build();
Path dest = Paths.get("streamtest.txt");
dest.toFile().delete();
- CompletableFuture<Path> response = client.sendAsync(req, asFile(dest))
+ CompletableFuture<Path> response = client.sendAsync(req, BodyHandlers.ofFile(dest))
.thenApply(resp -> {
if (resp.statusCode() != 200)
throw new RuntimeException();
@@ -198,7 +195,7 @@
URI u = new URI("https://127.0.0.1:"+port+"/foo");
HttpClient client = getClient();
HttpRequest req = HttpRequest.newBuilder(u).build();
- HttpResponse<String> resp = client.sendAsync(req, asString()).get();
+ HttpResponse<String> resp = client.sendAsync(req, BodyHandlers.ofString()).get();
int stat = resp.statusCode();
if (stat != 200) {
throw new RuntimeException("paramsTest failed "
@@ -214,9 +211,9 @@
HttpClient client = getClient();
HttpRequest req = HttpRequest.newBuilder(uri)
- .POST(fromString(SIMPLE_STRING))
+ .POST(BodyPublishers.ofString(SIMPLE_STRING))
.build();
- HttpResponse<String> response = client.sendAsync(req, asString()).get();
+ HttpResponse<String> response = client.sendAsync(req, BodyHandlers.ofString()).get();
HttpHeaders h = response.headers();
checkStatus(200, response.statusCode());
@@ -232,10 +229,10 @@
CompletableFuture[] responses = new CompletableFuture[LOOPS];
final Path source = TestUtil.getAFile(FILESIZE);
HttpRequest request = HttpRequest.newBuilder(uri)
- .POST(fromFile(source))
+ .POST(BodyPublishers.ofFile(source))
.build();
for (int i = 0; i < LOOPS; i++) {
- responses[i] = client.sendAsync(request, asFile(tempFile()))
+ responses[i] = client.sendAsync(request, BodyHandlers.ofFile(tempFile()))
//.thenApply(resp -> compareFiles(resp.body(), source));
.thenApply(resp -> {
System.out.printf("Resp status %d body size %d\n",
--- a/test/jdk/java/net/httpclient/http2/ImplicitPushCancel.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/ImplicitPushCancel.java Sat Feb 24 11:27:11 2018 +0000
@@ -49,7 +49,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-import java.net.http.HttpResponse.BodyHandler;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.PushPromiseHandler;
import jdk.internal.net.http.common.HttpHeadersImpl;
import org.testng.annotations.AfterTest;
@@ -107,7 +107,7 @@
public void test() throws Exception {
HttpClient client = HttpClient.newHttpClient();
- client.sendAsync(HttpRequest.newBuilder(uri).build(), BodyHandler.asString())
+ client.sendAsync(HttpRequest.newBuilder(uri).build(), BodyHandlers.ofString())
.thenApply(ImplicitPushCancel::assert200ResponseCode)
.thenApply(HttpResponse::body)
.thenAccept(body -> body.equals(MAIN_RESPONSE_BODY))
@@ -116,10 +116,10 @@
ConcurrentMap<HttpRequest, CompletableFuture<HttpResponse<String>>> promises
= new ConcurrentHashMap<>();
PushPromiseHandler<String> pph = PushPromiseHandler
- .of((r) -> BodyHandler.asString(), promises);
+ .of((r) -> BodyHandlers.ofString(), promises);
HttpResponse<String> main = client.sendAsync(
HttpRequest.newBuilder(uri).build(),
- BodyHandler.asString(),
+ BodyHandlers.ofString(),
pph)
.join();
--- a/test/jdk/java/net/httpclient/http2/ProxyTest2.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/ProxyTest2.java Sat Feb 24 11:27:11 2018 +0000
@@ -146,7 +146,7 @@
System.out.println("Sending request with HttpClient");
HttpResponse<String> response
- = client.send(request, HttpResponse.BodyHandler.asString());
+ = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Got response");
String resp = response.body();
System.out.println("Received: " + resp);
--- a/test/jdk/java/net/httpclient/http2/RedirectTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/RedirectTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -35,17 +35,19 @@
* RedirectTest
*/
-import java.net.*;
-import java.net.http.*;
-import java.util.Optional;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.Arrays;
import java.util.Iterator;
import org.testng.annotations.Test;
import static java.net.http.HttpClient.Version.HTTP_2;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
public class RedirectTest {
static int httpPort;
@@ -184,9 +186,9 @@
HttpClient client = getClient();
HttpRequest req = HttpRequest.newBuilder(uri)
- .POST(fromString(SIMPLE_STRING))
+ .POST(BodyPublishers.ofString(SIMPLE_STRING))
.build();
- CompletableFuture<HttpResponse<String>> cf = client.sendAsync(req, asString());
+ CompletableFuture<HttpResponse<String>> cf = client.sendAsync(req, BodyHandlers.ofString());
HttpResponse<String> response = cf.join();
checkStatus(200, response.statusCode());
--- a/test/jdk/java/net/httpclient/http2/ServerPush.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/ServerPush.java Sat Feb 24 11:27:11 2018 +0000
@@ -41,19 +41,16 @@
import java.nio.file.*;
import java.net.http.*;
import java.net.http.HttpResponse.BodyHandler;
-import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodyHandlers;
+import java.net.http.HttpResponse.BodySubscribers;
import java.net.http.HttpResponse.PushPromiseHandler;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Consumer;
-import java.util.function.UnaryOperator;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpResponse.BodyHandler.asByteArrayConsumer;
-import static java.net.http.HttpResponse.BodyHandler.asFile;
-import static java.net.http.HttpResponse.BodyHandler.asString;
import static org.testng.Assert.*;
@@ -93,7 +90,7 @@
resultMap = new ConcurrentHashMap<>();
PushPromiseHandler<String> pph = (initial, pushRequest, acceptor) -> {
- BodyHandler<String> s = BodyHandler.asString(UTF_8);
+ BodyHandler<String> s = BodyHandlers.ofString(UTF_8);
CompletableFuture<HttpResponse<String>> cf = acceptor.apply(s);
resultMap.put(pushRequest, cf);
};
@@ -101,7 +98,7 @@
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(uri).GET().build();
CompletableFuture<HttpResponse<String>> cf =
- client.sendAsync(request, asString(UTF_8), pph);
+ client.sendAsync(request, BodyHandlers.ofString(UTF_8), pph);
cf.join();
resultMap.put(request, cf);
System.err.println("results.size: " + resultMap.size());
@@ -121,13 +118,13 @@
resultMap = new ConcurrentHashMap<>();
PushPromiseHandler<String> pph =
- PushPromiseHandler.of(pushPromise -> asString(UTF_8),
+ PushPromiseHandler.of(pushPromise -> BodyHandlers.ofString(UTF_8),
resultMap);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(uri).GET().build();
CompletableFuture<HttpResponse<String>> cf =
- client.sendAsync(request, asString(UTF_8), pph);
+ client.sendAsync(request, BodyHandlers.ofString(UTF_8), pph);
cf.join();
resultMap.put(request, cf);
System.err.println("results.size: " + resultMap.size());
@@ -150,7 +147,7 @@
} catch (IOException ee) {
throw new UncheckedIOException(ee);
}
- return asFile(path);
+ return BodyHandlers.ofFile(path);
}
// Test 3 - custom written push promise handler, everything as a Path
@@ -250,12 +247,12 @@
(statusCode, headers) -> {
ByteArrayConsumer bc = new ByteArrayConsumer();
byteArrayConsumerMap.put(pushRequest, bc);
- return BodySubscriber.asByteArrayConsumer(bc); } );
+ return BodySubscribers.ofByteArrayConsumer(bc); } );
resultsMap.put(pushRequest, cf);
};
CompletableFuture<HttpResponse<Void>> cf =
- client.sendAsync(request, asByteArrayConsumer(bac), pushPromiseHandler);
+ client.sendAsync(request, BodyHandlers.ofByteArrayConsumer(bac), pushPromiseHandler);
cf.join();
resultsMap.put(request, cf);
@@ -288,12 +285,12 @@
pushRequest -> {
ByteArrayConsumer bc = new ByteArrayConsumer();
byteArrayConsumerMap.put(pushRequest, bc);
- return BodyHandler.asByteArrayConsumer(bc);
+ return BodyHandlers.ofByteArrayConsumer(bc);
},
resultsMap);
CompletableFuture<HttpResponse<Void>> cf =
- client.sendAsync(request, asByteArrayConsumer(bac), pushPromiseHandler);
+ client.sendAsync(request, BodyHandlers.ofByteArrayConsumer(bac), pushPromiseHandler);
cf.join();
resultsMap.put(request, cf);
--- a/test/jdk/java/net/httpclient/http2/ServerPushWithDiffTypes.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/ServerPushWithDiffTypes.java Sat Feb 24 11:27:11 2018 +0000
@@ -43,6 +43,7 @@
import java.net.http.HttpResponse.BodyHandler;
import java.net.http.HttpResponse.PushPromiseHandler;
import java.net.http.HttpResponse.BodySubscriber;
+import java.net.http.HttpResponse.BodySubscribers;
import java.util.*;
import java.util.concurrent.*;
import jdk.internal.net.http.common.HttpHeadersImpl;
@@ -143,9 +144,9 @@
int whichType = count++ % 3; // real world may base this on the request metadata
switch (whichType) {
case 0: // String
- return new BodyAndTypeSubscriber(BodySubscriber.asString(UTF_8));
+ return new BodyAndTypeSubscriber(BodySubscribers.ofString(UTF_8));
case 1: // byte[]
- return new BodyAndTypeSubscriber(BodySubscriber.asByteArray());
+ return new BodyAndTypeSubscriber(BodySubscribers.ofByteArray());
case 2: // Path
URI u = request.uri();
Path path = Paths.get(WORK_DIR.toString(), u.getPath());
@@ -154,7 +155,7 @@
} catch (IOException ee) {
throw new UncheckedIOException(ee);
}
- return new BodyAndTypeSubscriber(BodySubscriber.asFile(path));
+ return new BodyAndTypeSubscriber(BodySubscribers.ofFile(path));
default:
throw new AssertionError("Unexpected " + whichType);
}
--- a/test/jdk/java/net/httpclient/http2/TLSConnection.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/TLSConnection.java Sat Feb 24 11:27:11 2018 +0000
@@ -29,11 +29,10 @@
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
-
+import java.net.http.HttpRequest.BodyPublishers;
+import java.net.http.HttpResponse.BodyHandlers;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
/*
* @test
@@ -173,9 +172,9 @@
HttpClient client = builder.build();
HttpRequest request = HttpRequest.newBuilder(new URI(uriString))
- .POST(fromString("body"))
+ .POST(BodyPublishers.ofString("body"))
.build();
- String body = client.send(request, asString()).body();
+ String body = client.send(request, BodyHandlers.ofString()).body();
System.out.println("Response: " + body);
}
--- a/test/jdk/java/net/httpclient/http2/Timeout.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/http2/Timeout.java Sat Feb 24 11:27:11 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,9 @@
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpTimeoutException;
import java.time.Duration;
import java.util.concurrent.CompletionException;
@@ -34,8 +36,6 @@
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asString;
/*
* @test
@@ -118,9 +118,9 @@
.build();
HttpRequest request = HttpRequest.newBuilder(new URI(server))
.timeout(Duration.ofMillis(TIMEOUT))
- .POST(fromString("body"))
+ .POST(BodyPublishers.ofString("body"))
.build();
- HttpResponse<String> response = client.send(request, asString());
+ HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("Received unexpected reply: " + response.statusCode());
throw new RuntimeException("unexpected successful connection");
} catch (HttpTimeoutException e) {
@@ -135,9 +135,9 @@
.build();
HttpRequest request = HttpRequest.newBuilder(new URI(server))
.timeout(Duration.ofMillis(TIMEOUT))
- .POST(fromString("body"))
+ .POST(BodyPublishers.ofString("body"))
.build();
- HttpResponse<String> response = client.sendAsync(request, asString()).join();
+ HttpResponse<String> response = client.sendAsync(request, BodyHandlers.ofString()).join();
System.out.println("Received unexpected reply: " + response.statusCode());
throw new RuntimeException("unexpected successful connection");
} catch (CompletionException e) {
--- a/test/jdk/java/net/httpclient/offline/OfflineTesting.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/offline/OfflineTesting.java Sat Feb 24 11:27:11 2018 +0000
@@ -32,12 +32,11 @@
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
+import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.net.http.HttpRequest.BodyPublisher.fromString;
-import static java.net.http.HttpResponse.BodyHandler.asByteArray;
-import static java.net.http.HttpResponse.BodyHandler.asString;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -63,7 +62,7 @@
.uri(URI.create("http://openjdk.java.net/"))
.build();
- client.sendAsync(request, asString())
+ client.sendAsync(request, BodyHandlers.ofString())
.thenAccept(response -> {
System.out.println("response: " + response);
assertEquals(response.statusCode(), 200);
@@ -80,7 +79,7 @@
.uri(URI.create("http://openjdk.java.net/"))
.build();
- client.sendAsync(request, asByteArray())
+ client.sendAsync(request, BodyHandlers.ofByteArray())
.thenAccept(response -> {
System.out.println("response: " + response);
assertEquals(response.statusCode(), 200);
@@ -112,7 +111,7 @@
.uri(URI.create("http://openjdk.java.net/notFound"))
.build();
- client.sendAsync(request, asString())
+ client.sendAsync(request, BodyHandlers.ofString())
.thenAccept(response -> {
assertEquals(response.statusCode(), 404);
response.headers().firstValue("Content-Type")
@@ -131,10 +130,10 @@
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://openjdk.java.net/echo"))
- .POST(fromString("Hello World"))
+ .POST(BodyPublishers.ofString("Hello World"))
.build();
- client.sendAsync(request, asString())
+ client.sendAsync(request, BodyHandlers.ofString())
.thenAccept(response -> {
System.out.println("response: " + response);
assertEquals(response.statusCode(), 200);
@@ -151,10 +150,10 @@
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://openjdk.java.net/echo"))
- .POST(fromString("Hello chegar!!"))
+ .POST(BodyPublishers.ofString("Hello chegar!!"))
.build();
- HttpResponse<String> response = client.send(request, asString());
+ HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("response: " + response);
assertEquals(response.statusCode(), 200);
assertEquals(response.body(), "Hello chegar!!");
--- a/test/jdk/java/net/httpclient/security/Security.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/security/Security.java Sat Feb 24 11:27:11 2018 +0000
@@ -89,7 +89,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.reflect.InvocationTargetException;
-import static java.net.http.HttpResponse.BodyHandler.asString;
+import static java.net.http.HttpResponse.BodyHandlers.ofString;
/**
* Security checks test
@@ -181,43 +181,43 @@
test(false, () -> { // Policy 0
URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (1) policy has permission for file URL
test(true, () -> { //Policy 1
URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (2) policy has permission for all file URLs under /files
test(true, () -> { // Policy 2
URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (3) policy has permission for first URL but not redirected URL
test(false, () -> { // Policy 3
URI u = URI.create("http://127.0.0.1:" + port + "/redirect/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (4) policy has permission for both first URL and redirected URL
test(true, () -> { // Policy 4
URI u = URI.create("http://127.0.0.1:" + port + "/redirect/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (5) policy has permission for redirected but not first URL
test(false, () -> { // Policy 5
URI u = URI.create("http://127.0.0.1:" + port + "/redirect/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (6) policy has permission for file URL, but not method
test(false, () -> { //Policy 6
URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (7) policy has permission for file URL, method, but not header
test(false, () -> { //Policy 7
@@ -226,7 +226,7 @@
.header("X-Foo", "bar")
.GET()
.build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (8) policy has permission for file URL, method and header
test(true, () -> { //Policy 8
@@ -235,7 +235,7 @@
.header("X-Foo", "bar")
.GET()
.build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (9) policy has permission for file URL, method and header
test(true, () -> { //Policy 9
@@ -244,7 +244,7 @@
.headers("X-Foo", "bar", "X-Bar", "foo")
.GET()
.build();
- HttpResponse<?> response = client.send(request, asString());
+ HttpResponse<?> response = client.send(request, ofString());
}),
// (10) policy has permission for destination URL but not for proxy
test(false, () -> { //Policy 10
@@ -263,7 +263,7 @@
URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
try {
- HttpResponse<?> response = client.sendAsync(request, asString()).get();
+ HttpResponse<?> response = client.sendAsync(request, ofString()).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof SecurityException) {
throw (SecurityException)e.getCause();
@@ -277,7 +277,7 @@
URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
try {
- HttpResponse<?> response = client.sendAsync(request, asString()).get();
+ HttpResponse<?> response = client.sendAsync(request, ofString()).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof SecurityException) {
throw (SecurityException)e.getCause();
@@ -291,7 +291,7 @@
test(false, () -> { //Policy 12
URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
- HttpResponse.BodyHandler<String> sth = asString();
+ HttpResponse.BodyHandler<String> sth = ofString();
CompletableFuture<HttpResponse<String>> cf =
client.sendAsync(request, new HttpResponse.BodyHandler<String>() {
@@ -372,7 +372,7 @@
HttpRequest request = HttpRequest.newBuilder(u)
.headers("X-Foo", "bar", "X-Bar", "foo")
.build();
- HttpResponse<?> response = cl.send(request, asString());
+ HttpResponse<?> response = cl.send(request, ofString());
}
static void runtest(Test r, String policy, boolean succeeds) {
--- a/test/jdk/java/net/httpclient/security/filePerms/FileProcessorPermissionTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/security/filePerms/FileProcessorPermissionTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -68,15 +68,15 @@
@Test
public void test() throws Exception {
List<PrivilegedExceptionAction<?>> list = List.of(
- () -> HttpRequest.BodyPublisher.fromFile(fromFilePath),
+ () -> HttpRequest.BodyPublishers.ofFile(fromFilePath),
- () -> HttpResponse.BodyHandler.asFile(asFilePath),
- () -> HttpResponse.BodyHandler.asFile(asFilePath, CREATE),
- () -> HttpResponse.BodyHandler.asFile(asFilePath, CREATE, WRITE),
+ () -> HttpResponse.BodyHandlers.ofFile(asFilePath),
+ () -> HttpResponse.BodyHandlers.ofFile(asFilePath, CREATE),
+ () -> HttpResponse.BodyHandlers.ofFile(asFilePath, CREATE, WRITE),
- () -> HttpResponse.BodyHandler.asFileDownload(CWD),
- () -> HttpResponse.BodyHandler.asFileDownload(CWD, CREATE),
- () -> HttpResponse.BodyHandler.asFileDownload(CWD, CREATE, WRITE)
+ () -> HttpResponse.BodyHandlers.ofFileDownload(CWD),
+ () -> HttpResponse.BodyHandlers.ofFileDownload(CWD, CREATE),
+ () -> HttpResponse.BodyHandlers.ofFileDownload(CWD, CREATE, WRITE)
);
// sanity, just run http ( no security manager )
--- a/test/jdk/java/net/httpclient/ssltest/CertificateTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/ssltest/CertificateTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -25,7 +25,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpClient.Version;
import java.net.http.HttpResponse.BodyHandler;
-import static java.net.http.HttpResponse.BodyHandler.asString;
+import static java.net.http.HttpResponse.BodyHandlers.ofString;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import javax.net.ssl.SSLContext;
@@ -103,7 +103,7 @@
.build();
try {
- HttpResponse<String> response = client.send(request, asString());
+ HttpResponse<String> response = client.send(request, ofString());
System.out.printf("Status code %d received\n", response.statusCode());
if (good && response.statusCode() != 200)
error = "Test failed: good: status should be 200";
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -38,6 +38,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpHeaders;
import java.net.http.HttpResponse;
+import java.net.http.HttpResponse.BodyHandlers;
import java.security.AccessController;
import java.util.Arrays;
import java.util.Base64;
@@ -191,7 +192,7 @@
HttpRequestImpl origReq = new HttpRequestImpl(reqBuilder);
HttpRequestImpl req = new HttpRequestImpl(origReq, ps, AccessController.getContext());
MultiExchange<?> multi = new MultiExchange<Void>(origReq, req, client,
- HttpResponse.BodyHandler.replace(null),
+ BodyHandlers.replacing(null),
null, AccessController.getContext());
Exchange<?> exchange = new Exchange<>(req, multi);
out.println("\nSimulating unauthenticated request to " + uri);
@@ -257,7 +258,7 @@
HttpRequestImpl origReq2 = new HttpRequestImpl(reqBuilder2);
HttpRequestImpl req2 = new HttpRequestImpl(origReq2, ps, AccessController.getContext());
MultiExchange<?> multi2 = new MultiExchange<Void>(origReq2, req2, client,
- HttpResponse.BodyHandler.replace(null),
+ HttpResponse.BodyHandlers.replacing(null),
null, AccessController.getContext());
filter.request(req2, multi2);
out.println("Check that filter has added credentials from cache for " + reqURI2
@@ -289,7 +290,7 @@
HttpRequestImpl origReq3 = new HttpRequestImpl(reqBuilder3);
HttpRequestImpl req3 = new HttpRequestImpl(origReq3, ps, AccessController.getContext());
MultiExchange<?> multi3 = new MultiExchange<Void>(origReq3, req3, client,
- HttpResponse.BodyHandler.replace(null),
+ HttpResponse.BodyHandlers.replacing(null),
null, AccessController.getContext());
filter.request(req3, multi3);
if (proxy == null) {
@@ -333,7 +334,7 @@
HttpRequestImpl req4 = new HttpRequestImpl(origReq4, fakeProxy,
AccessController.getContext());
MultiExchange<?> multi4 = new MultiExchange<Void>(origReq4, req4, client,
- HttpResponse.BodyHandler.replace(null), null,
+ HttpResponse.BodyHandlers.replacing(null), null,
AccessController.getContext());
out.println("Simulating new request to " + reqURI4 + " with a proxy " + req4.proxy());
assertTrue((req4.proxy() == null) == (proxy != null),
@@ -374,7 +375,7 @@
HttpRequestImpl req5 = new HttpRequestImpl(origReq5, NO_PROXY,
AccessController.getContext());
MultiExchange<?> multi5 = new MultiExchange<Void>(origReq5, req5, client,
- HttpResponse.BodyHandler.replace(null), null,
+ HttpResponse.BodyHandlers.replacing(null), null,
AccessController.getContext());
out.println("Simulating new request to " + reqURI + " with a proxy " + req5.proxy());
assertTrue(req5.proxy() == null, "req5.proxy() should be null");
@@ -426,7 +427,7 @@
HttpRequestImpl req6 = new HttpRequestImpl(origReq6, ps,
AccessController.getContext());
MultiExchange<?> multi6 = new MultiExchange<Void>(origReq6, req6, client,
- HttpResponse.BodyHandler.replace(null), null,
+ HttpResponse.BodyHandlers.replacing(null), null,
AccessController.getContext());
out.println("Simulating new request to " + reqURI + " with a proxy " + req6.proxy());
assertTrue(req6.proxy() != null, "req6.proxy() should not be null");
@@ -450,7 +451,7 @@
HttpRequestImpl req7 = new HttpRequestImpl(origReq7, ps,
AccessController.getContext());
MultiExchange<?> multi7 = new MultiExchange<Void>(origReq7, req7, client,
- HttpResponse.BodyHandler.replace(null), null,
+ HttpResponse.BodyHandlers.replacing(null), null,
AccessController.getContext());
out.println("Simulating new request to " + reqURI7 + " with a proxy " + req7.proxy());
assertTrue(req7.proxy() == null, "req7.proxy() should be null");
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -43,7 +43,7 @@
import jdk.internal.net.http.websocket.RawChannel;
import jdk.internal.net.http.websocket.WebSocketRequest;
import org.testng.annotations.Test;
-import static java.net.http.HttpResponse.BodyHandler.discard;
+import static java.net.http.HttpResponse.BodyHandlers.discarding;
import static org.testng.Assert.assertEquals;
/*
@@ -193,7 +193,7 @@
((WebSocketRequest)req).isWebSocket(true);
HttpClient client = HttpClient.newHttpClient();
try {
- HttpResponse<?> r = client.send(req, discard());
+ HttpResponse<?> r = client.send(req, discarding());
r.body();
return ((HttpResponseImpl) r).rawChannel();
} finally {
--- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java Fri Feb 23 16:25:32 2018 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java Sat Feb 24 11:27:11 2018 +0000
@@ -37,7 +37,7 @@
import static java.lang.System.out;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.util.concurrent.TimeUnit.SECONDS;
-import static java.net.http.HttpResponse.BodyHandler.discard;
+import static java.net.http.HttpResponse.BodyHandlers.discarding;
/**
* Whitebox test of selector mechanics. Currently only a simple test
@@ -153,7 +153,7 @@
// thus all ordinary procedures apply to it, e.g. it must be put into
// the cache
((HttpRequestImpl) req).isWebSocket(true);
- HttpResponse<?> r = defaultClient().send(req, discard());
+ HttpResponse<?> r = defaultClient().send(req, discarding());
r.body();
return ((HttpResponseImpl) r).rawChannel();
}