You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/05/10 14:53:45 UTC
httpcomponents-core git commit: HTTPCORE-524: updated examples to use
nghttp2.org instead of no longer functional http2bin.org [Forced Update!]
Repository: httpcomponents-core
Updated Branches:
refs/heads/master 1d1069eeb -> 74753eb5d (forced update)
HTTPCORE-524: updated examples to use nghttp2.org instead of no longer functional http2bin.org
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/74753eb5
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/74753eb5
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/74753eb5
Branch: refs/heads/master
Commit: 74753eb5d8c9e6aded21fe5a9a8c872447ef0e6b
Parents: 409eda4
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Thu May 10 15:32:32 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu May 10 16:51:13 2018 +0200
----------------------------------------------------------------------
.../examples/Http2FullDuplexClientExample.java | 4 ++-
.../Http2MultiStreamExecutionExample.java | 6 +++--
.../examples/Http2RequestExecutionExample.java | 6 +++--
.../Http2TlsAlpnRequestExecutionExample.java | 27 +++-----------------
4 files changed, 15 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/74753eb5/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexClientExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexClientExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexClientExample.java
index b0c055c..c6d77da 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexClientExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexClientExample.java
@@ -49,6 +49,7 @@ import org.apache.hc.core5.http.nio.RequestChannel;
import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityProducer;
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.http2.frame.RawFrame;
import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
@@ -76,6 +77,7 @@ public class Http2FullDuplexClientExample {
final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
.setIOReactorConfig(ioReactorConfig)
.setH2Config(h2Config)
+ .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2)
.setStreamListener(new Http2StreamListener() {
@Override
@@ -120,7 +122,7 @@ public class Http2FullDuplexClientExample {
});
requester.start();
- final URI requestUri = new URI("http://http2bin.org/post");
+ final URI requestUri = new URI("http://nghttp2.org/httpbin/post");
final BasicRequestProducer requestProducer = new BasicRequestProducer(
"POST", requestUri, new BasicAsyncEntityProducer("stuff", ContentType.TEXT_PLAIN));
final BasicResponseConsumer<String> responseConsumer = new BasicResponseConsumer<>(
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/74753eb5/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java
index 8f314fb..9f20921 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2MultiStreamExecutionExample.java
@@ -42,6 +42,7 @@ import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.BasicRequestProducer;
import org.apache.hc.core5.http.nio.BasicResponseConsumer;
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.http2.frame.RawFrame;
import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
@@ -69,6 +70,7 @@ public class Http2MultiStreamExecutionExample {
final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
.setIOReactorConfig(ioReactorConfig)
+ .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2)
.setH2Config(h2Config)
.setStreamListener(new Http2StreamListener() {
@@ -113,8 +115,8 @@ public class Http2MultiStreamExecutionExample {
});
requester.start();
- HttpHost target = new HttpHost("http2bin.org");
- String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
+ HttpHost target = new HttpHost("nghttp2.org");
+ String[] requestUris = new String[] {"/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers"};
Future<AsyncClientEndpoint> future = requester.connect(target, Timeout.ofSeconds(5));
AsyncClientEndpoint clientEndpoint = future.get();
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/74753eb5/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java
index bd07a25..b2041c8 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2RequestExecutionExample.java
@@ -41,6 +41,7 @@ import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.BasicRequestProducer;
import org.apache.hc.core5.http.nio.BasicResponseConsumer;
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.http2.frame.RawFrame;
import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
@@ -62,6 +63,7 @@ public class Http2RequestExecutionExample {
final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
.setH2Config(h2Config)
+ .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2)
.setStreamListener(new Http2StreamListener() {
@Override
@@ -105,8 +107,8 @@ public class Http2RequestExecutionExample {
});
requester.start();
- HttpHost target = new HttpHost("http2bin.org");
- String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
+ HttpHost target = new HttpHost("nghttp2.org");
+ String[] requestUris = new String[] {"/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers"};
final CountDownLatch latch = new CountDownLatch(requestUris.length);
for (final String requestUri: requestUris) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/74753eb5/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2TlsAlpnRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2TlsAlpnRequestExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2TlsAlpnRequestExecutionExample.java
index 3cac377..ef9de52 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2TlsAlpnRequestExecutionExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2TlsAlpnRequestExecutionExample.java
@@ -26,13 +26,10 @@
*/
package org.apache.hc.core5.http.examples;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
-import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
@@ -57,32 +54,16 @@ import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.ssl.SSLContexts;
-import org.apache.hc.core5.ssl.TrustStrategy;
import org.apache.hc.core5.util.Timeout;
/**
* This example demonstrates how to execute HTTP/2 requests over TLS connections.
* <p>
- * It requires Java runtime with ALPN protocol support (such as Oracle JRE 9).
+ * It requires Java runtime with ALPN protocol support (such as Oracle JRE 9 or newer).
*/
public class Http2TlsAlpnRequestExecutionExample {
public final static void main(final String[] args) throws Exception {
- // Trust standard CA and those trusted by our custom strategy
- final SSLContext sslContext = SSLContexts.custom()
- .loadTrustMaterial(new TrustStrategy() {
-
- @Override
- public boolean isTrusted(
- final X509Certificate[] chain,
- final String authType) throws CertificateException {
- final X509Certificate cert = chain[0];
- return "CN=http2bin.org".equalsIgnoreCase(cert.getSubjectDN().getName());
- }
-
- })
- .build();
-
// Create and start requester
H2Config h2Config = H2Config.custom()
.setPushEnabled(false)
@@ -90,7 +71,7 @@ public class Http2TlsAlpnRequestExecutionExample {
final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
.setH2Config(h2Config)
- .setTlsStrategy(new H2ClientTlsStrategy(sslContext, new SSLSessionVerifier() {
+ .setTlsStrategy(new H2ClientTlsStrategy(SSLContexts.createSystemDefault(), new SSLSessionVerifier() {
@Override
public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
@@ -146,8 +127,8 @@ public class Http2TlsAlpnRequestExecutionExample {
});
requester.start();
- HttpHost target = new HttpHost("http2bin.org", 443, "https");
- String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
+ HttpHost target = new HttpHost("nghttp2.org", 443, "https");
+ String[] requestUris = new String[] {"/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers"};
final CountDownLatch latch = new CountDownLatch(requestUris.length);
for (final String requestUri: requestUris) {