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 2017/10/22 12:24:31 UTC

[1/2] httpcomponents-core git commit: Default I/O reactors to allow null IOReactorConfig parameter

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 13834d92c -> 29d31f9f1


Default I/O reactors to allow null IOReactorConfig parameter


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/3a7e62c6
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/3a7e62c6
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/3a7e62c6

Branch: refs/heads/master
Commit: 3a7e62c6c468edad91664842abe51539e28f3654
Parents: 13834d9
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sun Oct 22 14:05:48 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sun Oct 22 14:05:48 2017 +0200

----------------------------------------------------------------------
 .../org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java    | 2 +-
 .../org/apache/hc/core5/reactor/DefaultListeningIOReactor.java     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3a7e62c6/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
index 8fdb427..69741c2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
@@ -82,7 +82,7 @@ public class DefaultConnectingIOReactor implements IOReactorService, ConnectionI
             final SingleCoreIOReactor dispatcher = new SingleCoreIOReactor(
                     auditLog,
                     eventHandlerFactory,
-                    ioReactorConfig,
+                    ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT,
                     ioSessionDecorator,
                     sessionListener,
                     sessionShutdownCallback);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3a7e62c6/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
index e65a66c..9f6ee54 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
@@ -99,7 +99,7 @@ public class DefaultListeningIOReactor implements IOReactorService, ConnectionIn
             final SingleCoreIOReactor dispatcher = new SingleCoreIOReactor(
                     auditLog,
                     eventHandlerFactory,
-                    ioReactorConfig,
+                    ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT,
                     ioSessionDecorator,
                     sessionListener,
                     sessionShutdownCallback);


[2/2] httpcomponents-core git commit: Renamed HTTP/2 TLS example (no functional changes)

Posted by ol...@apache.org.
Renamed HTTP/2 TLS example (no functional changes)


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/29d31f9f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/29d31f9f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/29d31f9f

Branch: refs/heads/master
Commit: 29d31f9f12afc7e6f8aaa3aa665eb81bf3c7d6b8
Parents: 3a7e62c
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sun Oct 22 14:17:41 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sun Oct 22 14:17:41 2017 +0200

----------------------------------------------------------------------
 .../Http2SSLRequestExecutionExample.java        | 191 ------------------
 .../Http2TlsAlpnRequestExecutionExample.java    | 193 +++++++++++++++++++
 2 files changed, 193 insertions(+), 191 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/29d31f9f/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
deleted file mode 100644
index 5f9151c..0000000
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.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;
-
-import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.http.Header;
-import org.apache.hc.core5.http.HttpConnection;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.Message;
-import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
-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.config.H2Config;
-import org.apache.hc.core5.http2.frame.RawFrame;
-import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
-import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap;
-import org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy;
-import org.apache.hc.core5.io.ShutdownType;
-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.
- */
-public class Http2SSLRequestExecutionExample {
-
-    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)
-                .build();
-
-        final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
-                .setH2Config(h2Config)
-                .setTlsStrategy(new H2ClientTlsStrategy(sslContext, new SSLSessionVerifier() {
-
-                    @Override
-                    public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
-                        // IMPORTANT uncomment the following line when running Java 9 or older
-                        // in order to avoid the illegal reflective access operation warning
-                        // ====
-                        // return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol());
-                        // ====
-                        return null;
-                    }
-
-                }))
-                .setStreamListener(new Http2StreamListener() {
-
-                    @Override
-                    public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
-                        for (int i = 0; i < headers.size(); i++) {
-                            System.out.println(connection + " (" + streamId + ") << " + headers.get(i));
-                        }
-                    }
-
-                    @Override
-                    public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
-                        for (int i = 0; i < headers.size(); i++) {
-                            System.out.println(connection + " (" + streamId + ") >> " + headers.get(i));
-                        }
-                    }
-
-                    @Override
-                    public void onFrameInput(final HttpConnection connection, final int streamId, final RawFrame frame) {
-                    }
-
-                    @Override
-                    public void onFrameOutput(final HttpConnection connection, final int streamId, final RawFrame frame) {
-                    }
-
-                    @Override
-                    public void onInputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
-                    }
-
-                    @Override
-                    public void onOutputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
-                    }
-
-                })
-                .create();
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            @Override
-            public void run() {
-                System.out.println("HTTP requester shutting down");
-                requester.shutdown(ShutdownType.GRACEFUL);
-            }
-        });
-        requester.start();
-
-        HttpHost target = new HttpHost("http2bin.org", 443, "https");
-        String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
-
-        final CountDownLatch latch = new CountDownLatch(requestUris.length);
-        for (final String requestUri: requestUris) {
-            final Future<AsyncClientEndpoint> future = requester.connect(target, Timeout.ofSeconds(5));
-            final AsyncClientEndpoint clientEndpoint = future.get();
-            clientEndpoint.execute(
-                    new BasicRequestProducer("GET", target, requestUri),
-                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()),
-                    new FutureCallback<Message<HttpResponse, String>>() {
-
-                        @Override
-                        public void completed(final Message<HttpResponse, String> message) {
-                            clientEndpoint.releaseAndReuse();
-                            HttpResponse response = message.getHead();
-                            String body = message.getBody();
-                            System.out.println(requestUri + "->" + response.getCode() + " " + response.getVersion());
-                            System.out.println(body);
-                            latch.countDown();
-                        }
-
-                        @Override
-                        public void failed(final Exception ex) {
-                            clientEndpoint.releaseAndDiscard();
-                            System.out.println(requestUri + "->" + ex);
-                            latch.countDown();
-                        }
-
-                        @Override
-                        public void cancelled() {
-                            clientEndpoint.releaseAndDiscard();
-                            System.out.println(requestUri + " cancelled");
-                            latch.countDown();
-                        }
-
-                    });
-        }
-
-        latch.await();
-        System.out.println("Shutting down I/O reactor");
-        requester.initiateShutdown();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/29d31f9f/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
new file mode 100644
index 0000000..3cac377
--- /dev/null
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2TlsAlpnRequestExecutionExample.java
@@ -0,0 +1,193 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.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;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
+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.config.H2Config;
+import org.apache.hc.core5.http2.frame.RawFrame;
+import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap;
+import org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy;
+import org.apache.hc.core5.io.ShutdownType;
+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).
+ */
+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)
+                .build();
+
+        final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
+                .setH2Config(h2Config)
+                .setTlsStrategy(new H2ClientTlsStrategy(sslContext, new SSLSessionVerifier() {
+
+                    @Override
+                    public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
+                        // IMPORTANT uncomment the following line when running Java 9 or older
+                        // in order to avoid the illegal reflective access operation warning
+                        // ====
+                        // return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol());
+                        // ====
+                        return null;
+                    }
+
+                }))
+                .setStreamListener(new Http2StreamListener() {
+
+                    @Override
+                    public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
+                        for (int i = 0; i < headers.size(); i++) {
+                            System.out.println(connection + " (" + streamId + ") << " + headers.get(i));
+                        }
+                    }
+
+                    @Override
+                    public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
+                        for (int i = 0; i < headers.size(); i++) {
+                            System.out.println(connection + " (" + streamId + ") >> " + headers.get(i));
+                        }
+                    }
+
+                    @Override
+                    public void onFrameInput(final HttpConnection connection, final int streamId, final RawFrame frame) {
+                    }
+
+                    @Override
+                    public void onFrameOutput(final HttpConnection connection, final int streamId, final RawFrame frame) {
+                    }
+
+                    @Override
+                    public void onInputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
+                    }
+
+                    @Override
+                    public void onOutputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
+                    }
+
+                })
+                .create();
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+                System.out.println("HTTP requester shutting down");
+                requester.shutdown(ShutdownType.GRACEFUL);
+            }
+        });
+        requester.start();
+
+        HttpHost target = new HttpHost("http2bin.org", 443, "https");
+        String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
+
+        final CountDownLatch latch = new CountDownLatch(requestUris.length);
+        for (final String requestUri: requestUris) {
+            final Future<AsyncClientEndpoint> future = requester.connect(target, Timeout.ofSeconds(5));
+            final AsyncClientEndpoint clientEndpoint = future.get();
+            clientEndpoint.execute(
+                    new BasicRequestProducer("GET", target, requestUri),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()),
+                    new FutureCallback<Message<HttpResponse, String>>() {
+
+                        @Override
+                        public void completed(final Message<HttpResponse, String> message) {
+                            clientEndpoint.releaseAndReuse();
+                            HttpResponse response = message.getHead();
+                            String body = message.getBody();
+                            System.out.println(requestUri + "->" + response.getCode() + " " + response.getVersion());
+                            System.out.println(body);
+                            latch.countDown();
+                        }
+
+                        @Override
+                        public void failed(final Exception ex) {
+                            clientEndpoint.releaseAndDiscard();
+                            System.out.println(requestUri + "->" + ex);
+                            latch.countDown();
+                        }
+
+                        @Override
+                        public void cancelled() {
+                            clientEndpoint.releaseAndDiscard();
+                            System.out.println(requestUri + " cancelled");
+                            latch.countDown();
+                        }
+
+                    });
+        }
+
+        latch.await();
+        System.out.println("Shutting down I/O reactor");
+        requester.initiateShutdown();
+    }
+
+}