mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-09 03:25:28 +00:00
HTTPCORE-524: updated examples to use nghttp2.org instead of no longer functional http2bin.org
This commit is contained in:
parent
e3cdb72de7
commit
a6a29892fa
@ -70,7 +70,7 @@ public static void main(final String[] args) throws Exception {
|
|||||||
|
|
||||||
client.start();
|
client.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(
|
final BasicRequestProducer requestProducer = new BasicRequestProducer(
|
||||||
"POST", requestUri, new BasicAsyncEntityProducer("stuff", ContentType.TEXT_PLAIN));
|
"POST", requestUri, new BasicAsyncEntityProducer("stuff", ContentType.TEXT_PLAIN));
|
||||||
final BasicResponseConsumer<String> responseConsumer = new BasicResponseConsumer<>(
|
final BasicResponseConsumer<String> responseConsumer = new BasicResponseConsumer<>(
|
||||||
|
@ -62,11 +62,11 @@ public static void main(final String[] args) throws Exception {
|
|||||||
|
|
||||||
client.start();
|
client.start();
|
||||||
|
|
||||||
final HttpHost target = new HttpHost("http2bin.org");
|
final HttpHost target = new HttpHost("nghttp2.org");
|
||||||
final Future<AsyncClientEndpoint> leaseFuture = client.lease(target, null);
|
final Future<AsyncClientEndpoint> leaseFuture = client.lease(target, null);
|
||||||
final AsyncClientEndpoint endpoint = leaseFuture.get(30, TimeUnit.SECONDS);
|
final AsyncClientEndpoint endpoint = leaseFuture.get(30, TimeUnit.SECONDS);
|
||||||
try {
|
try {
|
||||||
final String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
|
final String[] requestUris = new String[] {"/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers"};
|
||||||
|
|
||||||
final CountDownLatch latch = new CountDownLatch(requestUris.length);
|
final CountDownLatch latch = new CountDownLatch(requestUris.length);
|
||||||
for (final String requestUri: requestUris) {
|
for (final String requestUri: requestUris) {
|
||||||
|
@ -114,8 +114,8 @@ public void releaseResources() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final HttpHost target = new HttpHost("http2bin.org");
|
final HttpHost target = new HttpHost("nghttp2.org");
|
||||||
final String requestURI = "/";
|
final String requestURI = "/httpbin/";
|
||||||
final Future<Void> future = client.execute(
|
final Future<Void> future = client.execute(
|
||||||
AsyncRequestBuilder.get(target, requestURI).build(),
|
AsyncRequestBuilder.get(target, requestURI).build(),
|
||||||
new AbstractCharResponseConsumer<Void>() {
|
new AbstractCharResponseConsumer<Void>() {
|
||||||
|
@ -26,11 +26,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hc.client5.http.examples;
|
package org.apache.hc.client5.http.examples;
|
||||||
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||||
@ -49,7 +46,6 @@
|
|||||||
import org.apache.hc.core5.http2.HttpVersionPolicy;
|
import org.apache.hc.core5.http2.HttpVersionPolicy;
|
||||||
import org.apache.hc.core5.io.ShutdownType;
|
import org.apache.hc.core5.io.ShutdownType;
|
||||||
import org.apache.hc.core5.ssl.SSLContexts;
|
import org.apache.hc.core5.ssl.SSLContexts;
|
||||||
import org.apache.hc.core5.ssl.TrustStrategy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This example demonstrates how to avoid the illegal reflective access operation warning
|
* This example demonstrates how to avoid the illegal reflective access operation warning
|
||||||
@ -58,22 +54,8 @@
|
|||||||
public class AsyncClientTlsAlpn {
|
public class AsyncClientTlsAlpn {
|
||||||
|
|
||||||
public final static void main(final String[] args) throws Exception {
|
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();
|
|
||||||
final TlsStrategy tlsStrategy = new H2TlsStrategy(
|
final TlsStrategy tlsStrategy = new H2TlsStrategy(
|
||||||
sslcontext,
|
SSLContexts.createSystemDefault(),
|
||||||
H2TlsStrategy.getDefaultHostnameVerifier()) {
|
H2TlsStrategy.getDefaultHostnameVerifier()) {
|
||||||
|
|
||||||
// IMPORTANT uncomment the following method when running Java 9 or older
|
// IMPORTANT uncomment the following method when running Java 9 or older
|
||||||
@ -94,8 +76,8 @@ public boolean isTrusted(
|
|||||||
|
|
||||||
client.start();
|
client.start();
|
||||||
|
|
||||||
final HttpHost target = new HttpHost("http2bin.org", 443, "https");
|
final HttpHost target = new HttpHost("nghttp2.org", 443, "https");
|
||||||
final String requestUri = "/";
|
final String requestUri = "/httpbin/";
|
||||||
final HttpClientContext clientContext = HttpClientContext.create();
|
final HttpClientContext clientContext = HttpClientContext.create();
|
||||||
|
|
||||||
final SimpleHttpRequest request = SimpleHttpRequest.get(target, requestUri);
|
final SimpleHttpRequest request = SimpleHttpRequest.get(target, requestUri);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user