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/11/22 09:21:12 UTC
[1/4] httpcomponents-core git commit: Moved method to determine JRE
level to ReflectionUtils [Forced Update!]
Repository: httpcomponents-core
Updated Branches:
refs/heads/master 1e2095002 -> fd56c60d2 (forced update)
Moved method to determine JRE level to ReflectionUtils
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/fd56c60d
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/fd56c60d
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/fd56c60d
Branch: refs/heads/master
Commit: fd56c60d27038d68ca8ecf3db8be97ff9b93ba69
Parents: 865947c
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Nov 21 19:01:31 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu Nov 22 10:01:13 2018 +0100
----------------------------------------------------------------------
.../apache/hc/core5/testing/TestingSupport.java | 49 --------------------
.../hc/core5/testing/nio/Http2AlpnTest.java | 4 +-
.../nio/Http2ProtocolNegotiationTest.java | 4 +-
...Http2ServerAndMultiplexingRequesterTest.java | 4 +-
.../nio/Http2ServerAndRequesterTest.java | 4 +-
.../apache/hc/core5/util/ReflectionUtils.java | 17 +++++++
6 files changed, 25 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd56c60d/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/TestingSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/TestingSupport.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/TestingSupport.java
deleted file mode 100644
index 3e79548..0000000
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/TestingSupport.java
+++ /dev/null
@@ -1,49 +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.testing;
-
-public final class TestingSupport {
-
- public static int determineJRELevel() {
- final String s = System.getProperty("java.version");
- final String[] parts = s.split("\\.");
- if (parts.length > 0) {
- try {
- final int majorVersion = Integer.parseInt(parts[0]);
- if (majorVersion > 1) {
- return majorVersion;
- } else if (majorVersion == 1 && parts.length > 1) {
- return Integer.parseInt(parts[1]);
- }
- } catch (final NumberFormatException ignore) {
- }
- }
- return 7;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd56c60d/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2AlpnTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2AlpnTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2AlpnTest.java
index e31ebcc..7142368 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2AlpnTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2AlpnTest.java
@@ -56,7 +56,7 @@ import org.apache.hc.core5.reactor.ExceptionEvent;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
-import org.apache.hc.core5.testing.TestingSupport;
+import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
@@ -160,7 +160,7 @@ public class Http2AlpnTest {
@BeforeClass
public static void determineJavaVersion() {
- javaVersion = TestingSupport.determineJRELevel();
+ javaVersion = ReflectionUtils.determineJRELevel();
}
@Before
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd56c60d/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
index 3e5698a..fe9f9a6 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
@@ -57,8 +57,8 @@ import org.apache.hc.core5.reactor.ExceptionEvent;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
-import org.apache.hc.core5.testing.TestingSupport;
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
+import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
@@ -179,7 +179,7 @@ public class Http2ProtocolNegotiationTest {
@BeforeClass
public static void determineJavaVersion() {
- javaVersion = TestingSupport.determineJRELevel();
+ javaVersion = ReflectionUtils.determineJRELevel();
}
@Before
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd56c60d/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndMultiplexingRequesterTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndMultiplexingRequesterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndMultiplexingRequesterTest.java
index e8de8a0..b2d1a68 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndMultiplexingRequesterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndMultiplexingRequesterTest.java
@@ -63,7 +63,7 @@ import org.apache.hc.core5.reactor.ExceptionEvent;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
-import org.apache.hc.core5.testing.TestingSupport;
+import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
@@ -194,7 +194,7 @@ public class Http2ServerAndMultiplexingRequesterTest {
@BeforeClass
public static void determineJavaVersion() {
- javaVersion = TestingSupport.determineJRELevel();
+ javaVersion = ReflectionUtils.determineJRELevel();
}
@Before
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd56c60d/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
index 3de51ac..36a4678 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
@@ -60,8 +60,8 @@ import org.apache.hc.core5.reactor.ExceptionEvent;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
-import org.apache.hc.core5.testing.TestingSupport;
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
+import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
@@ -196,7 +196,7 @@ public class Http2ServerAndRequesterTest {
@BeforeClass
public static void determineJavaVersion() {
- javaVersion = TestingSupport.determineJRELevel();
+ javaVersion = ReflectionUtils.determineJRELevel();
}
@Before
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd56c60d/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java
index eaa743c..e5fc0bb 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java
@@ -53,4 +53,21 @@ public final class ReflectionUtils {
}
}
+ public static int determineJRELevel() {
+ final String s = System.getProperty("java.version");
+ final String[] parts = s.split("\\.");
+ if (parts.length > 0) {
+ try {
+ final int majorVersion = Integer.parseInt(parts[0]);
+ if (majorVersion > 1) {
+ return majorVersion;
+ } else if (majorVersion == 1 && parts.length > 1) {
+ return Integer.parseInt(parts[1]);
+ }
+ } catch (final NumberFormatException ignore) {
+ }
+ }
+ return 7;
+ }
+
}
[4/4] httpcomponents-core git commit: Added optional dependency on
conscrypt-openjdk-uber 1.4.1;
support for advanced TLS functions (such as ALPN extension) on Java 1.7 and
Java 1.8 through Conscrypt TLS library
Posted by ol...@apache.org.
Added optional dependency on conscrypt-openjdk-uber 1.4.1; support for advanced TLS functions (such as ALPN extension) on Java 1.7 and Java 1.8 through Conscrypt TLS library
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/f322f5ad
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/f322f5ad
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/f322f5ad
Branch: refs/heads/master
Commit: f322f5add27c7c7697c1419eccb22506a30daea8
Parents: adcaa9f
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Nov 21 18:40:59 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu Nov 22 10:01:13 2018 +0100
----------------------------------------------------------------------
httpcore5-h2/pom.xml | 6 +
.../Http2ConscriptRequestExecutionExample.java | 163 +++++++++++++++++++
.../http2/ssl/ConscryptClientTlsStrategy.java | 104 ++++++++++++
.../http2/ssl/ConscryptServerTlsStrategy.java | 113 +++++++++++++
.../hc/core5/http2/ssl/ConscryptSupport.java | 89 ++++++++++
.../apache/hc/core5/http2/ssl/H2TlsSupport.java | 29 ++--
pom.xml | 6 +
7 files changed, 495 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/pom.xml
----------------------------------------------------------------------
diff --git a/httpcore5-h2/pom.xml b/httpcore5-h2/pom.xml
index 1e82751..5a75b94 100644
--- a/httpcore5-h2/pom.xml
+++ b/httpcore5-h2/pom.xml
@@ -44,6 +44,12 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>org.conscrypt</groupId>
+ <artifactId>conscrypt-openjdk-uber</artifactId>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java
new file mode 100644
index 0000000..82585c8
--- /dev/null
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java
@@ -0,0 +1,163 @@
+/*
+ * ====================================================================
+ * 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.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+
+import javax.net.ssl.SSLContext;
+
+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.ConscryptClientTlsStrategy;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.ssl.SSLContexts;
+import org.apache.hc.core5.util.Timeout;
+import org.conscrypt.Conscrypt;
+
+/**
+ * This example demonstrates how to execute HTTP/2 requests over TLS connections
+ * with Java 1.7 or Java 1.8 and Conscrypt TLS library
+ */
+public class Http2ConscriptRequestExecutionExample {
+
+ public final static void main(final String[] args) throws Exception {
+
+ // Create and start requester
+ H2Config h2Config = H2Config.custom()
+ .setPushEnabled(false)
+ .build();
+
+ final SSLContext sslContext = SSLContexts.custom()
+ .setProvider(Conscrypt.newProvider())
+ .build();
+
+ final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
+ .setH2Config(h2Config)
+ .setTlsStrategy(new ConscryptClientTlsStrategy(sslContext))
+ .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.getRemoteAddress() + " (" + 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.getRemoteAddress() + " (" + 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.close(CloseMode.GRACEFUL);
+ }
+ });
+ requester.start();
+
+ HttpHost target = new HttpHost("https", "nghttp2.org", 443);
+ String[] requestUris = new String[] {"/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers"};
+
+ final CountDownLatch latch = new CountDownLatch(requestUris.length);
+ for (final String requestUri: requestUris) {
+ final Future<AsyncClientEndpoint> future = requester.connect(target, Timeout.ofDays(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/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
new file mode 100644
index 0000000..1c701e2
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
@@ -0,0 +1,104 @@
+/*
+ * ====================================================================
+ * 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.http2.ssl;
+
+import java.net.SocketAddress;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
+import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Basic client-side implementation of {@link TlsStrategy} that upgrades to TLS for all endpoints
+ * with {@code HTTPS} scheme.
+ *
+ * @since 5.0
+ */
+public class ConscryptClientTlsStrategy implements TlsStrategy {
+
+ private final SSLContext sslContext;
+ private final SSLBufferMode sslBufferMode;
+ private final SSLSessionInitializer initializer;
+ private final SSLSessionVerifier verifier;
+
+ public ConscryptClientTlsStrategy(
+ final SSLContext sslContext,
+ final SSLBufferMode sslBufferMode,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this.sslContext = Args.notNull(sslContext, "SSL context");
+ this.sslBufferMode = sslBufferMode;
+ this.initializer = initializer;
+ this.verifier = verifier;
+ }
+
+ public ConscryptClientTlsStrategy(
+ final SSLContext sslContext,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, null, initializer, verifier);
+ }
+
+ public ConscryptClientTlsStrategy(
+ final SSLContext sslContext,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, null, null, verifier);
+ }
+
+ public ConscryptClientTlsStrategy(final SSLContext sslContext) {
+ this(sslContext, null, null, null);
+ }
+
+ @Override
+ public boolean upgrade(
+ final TransportSecurityLayer tlsSession,
+ final HttpHost host,
+ final SocketAddress localAddress,
+ final SocketAddress remoteAddress,
+ final Object attachment) {
+ final String scheme = host != null ? host.getSchemeName() : null;
+ if (URIScheme.HTTPS.same(scheme)) {
+ tlsSession.startTls(
+ sslContext,
+ host,
+ sslBufferMode,
+ ConscryptSupport.initialize(attachment, initializer),
+ ConscryptSupport.verify(verifier));
+ return true;
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
new file mode 100644
index 0000000..1cea2cb
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
@@ -0,0 +1,113 @@
+/*
+ * ====================================================================
+ * 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.http2.ssl;
+
+import java.net.SocketAddress;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.nio.ssl.FixedPortStrategy;
+import org.apache.hc.core5.http.nio.ssl.SecurePortStrategy;
+import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
+import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Basic side-side implementation of {@link TlsStrategy} that upgrades to TLS for endpoints
+ * with the specified local ports.
+ *
+ * @since 5.0
+ */
+public class ConscryptServerTlsStrategy implements TlsStrategy {
+
+ private final SSLContext sslContext;
+ private final SecurePortStrategy securePortStrategy;
+ private final SSLBufferMode sslBufferMode;
+ private final SSLSessionInitializer initializer;
+ private final SSLSessionVerifier verifier;
+
+ public ConscryptServerTlsStrategy(
+ final SSLContext sslContext,
+ final SecurePortStrategy securePortStrategy,
+ final SSLBufferMode sslBufferMode,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this.sslContext = Args.notNull(sslContext, "SSL context");
+ this.securePortStrategy = securePortStrategy;
+ this.sslBufferMode = sslBufferMode;
+ this.initializer = initializer;
+ this.verifier = verifier;
+ }
+
+ public ConscryptServerTlsStrategy(
+ final SSLContext sslContext,
+ final SecurePortStrategy securePortStrategy,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, securePortStrategy, null, initializer, verifier);
+ }
+
+ public ConscryptServerTlsStrategy(
+ final SSLContext sslContext,
+ final SecurePortStrategy securePortStrategy,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, securePortStrategy, null, null, verifier);
+ }
+
+ public ConscryptServerTlsStrategy(final SSLContext sslContext, final SecurePortStrategy securePortStrategy) {
+ this(sslContext, securePortStrategy, null, null, null);
+ }
+
+ public ConscryptServerTlsStrategy(final SSLContext sslContext, final int... securePorts) {
+ this(sslContext, new FixedPortStrategy(securePorts));
+ }
+
+ @Override
+ public boolean upgrade(
+ final TransportSecurityLayer tlsSession,
+ final HttpHost host,
+ final SocketAddress localAddress,
+ final SocketAddress remoteAddress,
+ final Object attachment) {
+ if (securePortStrategy != null && securePortStrategy.isSecure(localAddress)) {
+ tlsSession.startTls(
+ sslContext,
+ host,
+ sslBufferMode,
+ ConscryptSupport.initialize(attachment, initializer),
+ ConscryptSupport.verify(verifier));
+ return true;
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java
new file mode 100644
index 0000000..e1a9b9d
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java
@@ -0,0 +1,89 @@
+/*
+ * ====================================================================
+ * 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.http2.ssl;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLParameters;
+
+import org.apache.hc.core5.net.NamedEndpoint;
+import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
+import org.conscrypt.Conscrypt;
+
+/**
+ * Conscrypt TLS support methods
+ *
+ * @since 5.0
+ */
+public final class ConscryptSupport {
+
+ public static SSLSessionInitializer initialize(
+ final Object attachment,
+ final SSLSessionInitializer initializer) {
+ return new SSLSessionInitializer() {
+
+ @Override
+ public void initialize(final NamedEndpoint endpoint, final SSLEngine sslEngine) {
+ final SSLParameters sslParameters = sslEngine.getSSLParameters();
+ sslParameters.setProtocols(H2TlsSupport.excludeBlacklistedProtocols(sslParameters.getProtocols()));
+ sslParameters.setCipherSuites(H2TlsSupport.excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
+ H2TlsSupport.setEnableRetransmissions(sslParameters, false);
+ final String[] appProtocols = H2TlsSupport.selectApplicationProtocols(attachment);
+ if (Conscrypt.isConscrypt(sslEngine)) {
+ sslEngine.setSSLParameters(sslParameters);
+ Conscrypt.setApplicationProtocols(sslEngine, appProtocols);
+ } else {
+ H2TlsSupport.setApplicationProtocols(sslParameters, appProtocols);
+ sslEngine.setSSLParameters(sslParameters);
+ }
+ if (initializer != null) {
+ initialize(endpoint, sslEngine);
+ }
+ }
+
+ };
+ }
+
+ public static SSLSessionVerifier verify(final SSLSessionVerifier verifier) {
+ return new SSLSessionVerifier() {
+
+ @Override
+ public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
+ TlsDetails tlsDetails = verifier != null ? verifier.verify(endpoint, sslEngine) : null;
+ if (tlsDetails == null && Conscrypt.isConscrypt(sslEngine)) {
+ tlsDetails = new TlsDetails(sslEngine.getSession(), Conscrypt.getApplicationProtocol(sslEngine));
+ }
+ return tlsDetails;
+ }
+
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
index e9443eb..df9f49a 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
@@ -374,6 +374,19 @@ public final class H2TlsSupport {
ReflectionSupport.callSetter(sslParameters, "ApplicationProtocols", String[].class, values);
}
+ public static String[] selectApplicationProtocols(final Object attachment) {
+ final HttpVersionPolicy versionPolicy = attachment instanceof HttpVersionPolicy ?
+ (HttpVersionPolicy) attachment : HttpVersionPolicy.NEGOTIATE;
+ switch (versionPolicy) {
+ case FORCE_HTTP_1:
+ return new String[] { ApplicationProtocols.HTTP_1_1.id };
+ case FORCE_HTTP_2:
+ return new String[] { ApplicationProtocols.HTTP_2.id };
+ default:
+ return new String[] { ApplicationProtocols.HTTP_2.id, ApplicationProtocols.HTTP_1_1.id };
+ }
+ }
+
public static SSLSessionInitializer enforceRequirements(
final Object attachment,
final SSLSessionInitializer initializer) {
@@ -385,21 +398,7 @@ public final class H2TlsSupport {
sslParameters.setProtocols(excludeBlacklistedProtocols(sslParameters.getProtocols()));
sslParameters.setCipherSuites(excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
setEnableRetransmissions(sslParameters, false);
- final HttpVersionPolicy versionPolicy = attachment instanceof HttpVersionPolicy ?
- (HttpVersionPolicy) attachment : HttpVersionPolicy.NEGOTIATE;
- final String[] appProtocols;
- switch (versionPolicy) {
- case FORCE_HTTP_1:
- appProtocols = new String[] { ApplicationProtocols.HTTP_1_1.id };
- break;
- case FORCE_HTTP_2:
- appProtocols = new String[] { ApplicationProtocols.HTTP_2.id };
- break;
- default:
- appProtocols = new String[] { ApplicationProtocols.HTTP_2.id, ApplicationProtocols.HTTP_1_1.id };
- break;
- }
- setApplicationProtocols(sslParameters, appProtocols);
+ setApplicationProtocols(sslParameters, selectApplicationProtocols(attachment));
sslEngine.setSSLParameters(sslParameters);
if (initializer != null) {
initializer.initialize(endpoint, sslEngine);
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 89de9fb..5a2a96c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,6 +77,7 @@
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
+ <conscrypt.version>1.4.1</conscrypt.version>
<junit.version>4.12</junit.version>
<mockito.version>2.23.0</mockito.version>
<slf4j.version>1.7.25</slf4j.version>
@@ -86,6 +87,11 @@
<dependencyManagement>
<dependencies>
<dependency>
+ <groupId>org.conscrypt</groupId>
+ <artifactId>conscrypt-openjdk-uber</artifactId>
+ <version>${conscrypt.version}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
[2/4] httpcomponents-core git commit: Updated examples
Posted by ol...@apache.org.
Updated examples
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/61834737
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/61834737
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/61834737
Branch: refs/heads/master
Commit: 6183473728c4ee291788700f7f0207d625003ced
Parents: f322f5a
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Nov 21 18:46:42 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu Nov 22 10:01:13 2018 +0100
----------------------------------------------------------------------
.../hc/core5/http/examples/Http2FileServerExample.java | 4 ++--
.../core5/http/examples/Http2FullDuplexClientExample.java | 4 ++--
.../core5/http/examples/Http2FullDuplexServerExample.java | 4 ++--
.../http/examples/Http2MultiStreamExecutionExample.java | 4 ++--
.../core5/http/examples/Http2RequestExecutionExample.java | 4 ++--
.../examples/Http2TlsAlpnRequestExecutionExample.java | 6 +++---
.../examples/ReactiveFullDuplexClientExample.java | 8 ++++----
.../examples/ReactiveFullDuplexServerExample.java | 8 ++++----
.../core5/http/examples/AsyncFullDuplexClientExample.java | 8 ++++----
.../core5/http/examples/AsyncFullDuplexServerExample.java | 8 ++++----
.../examples/AsyncPipelinedRequestExecutionExample.java | 8 ++++----
.../core5/http/examples/AsyncRequestExecutionExample.java | 9 ++++-----
.../core5/http/examples/ClassicGetExecutionExample.java | 10 +++++-----
.../core5/http/examples/ClassicPostExecutionExample.java | 8 ++++----
14 files changed, 46 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
index c76e712..bc60c38 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
@@ -94,14 +94,14 @@ public class Http2FileServerExample {
@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));
+ System.out.println(connection.getRemoteAddress() + " (" + 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));
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/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 2128139..571f8b2 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
@@ -84,14 +84,14 @@ public class Http2FullDuplexClientExample {
@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));
+ System.out.println(connection.getRemoteAddress() + " (" + 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));
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexServerExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexServerExample.java
index cc79b29..99d88fe 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexServerExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FullDuplexServerExample.java
@@ -89,14 +89,14 @@ public class Http2FullDuplexServerExample {
@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));
+ System.out.println(connection.getRemoteAddress() + " (" + 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));
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/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 1acf335..2f08832 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
@@ -77,14 +77,14 @@ public class Http2MultiStreamExecutionExample {
@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));
+ System.out.println(connection.getRemoteAddress() + " (" + 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));
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/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 d1827da..1cbbf0d 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
@@ -69,14 +69,14 @@ public class Http2RequestExecutionExample {
@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));
+ System.out.println(connection.getRemoteAddress() + " (" + 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));
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/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 d0948c2..fa98e0a 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
@@ -89,14 +89,14 @@ public class Http2TlsAlpnRequestExecutionExample {
@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));
+ System.out.println(connection.getRemoteAddress() + " (" + 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));
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
}
}
@@ -127,7 +127,7 @@ public class Http2TlsAlpnRequestExecutionExample {
});
requester.start();
- HttpHost target = new HttpHost("nghttp2.org", 443, "https");
+ HttpHost target = new HttpHost("https", "nghttp2.org", 443);
String[] requestUris = new String[] {"/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers"};
final CountDownLatch latch = new CountDownLatch(requestUris.length);
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java b/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java
index e741fdd..057bb6c 100644
--- a/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java
+++ b/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexClientExample.java
@@ -79,21 +79,21 @@ public class ReactiveFullDuplexClientExample {
.setStreamListener(new Http1StreamListener() {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexServerExample.java b/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexServerExample.java
index d02b3dd..9e37886 100644
--- a/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexServerExample.java
+++ b/httpcore5-reactive/src/examples/org/apache/hc/core5/reactive/examples/ReactiveFullDuplexServerExample.java
@@ -80,21 +80,21 @@ public class ReactiveFullDuplexServerExample {
.setStreamListener(new Http1StreamListener() {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexClientExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexClientExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexClientExample.java
index 3b16725..f79ee9e 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexClientExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexClientExample.java
@@ -90,21 +90,21 @@ public class AsyncFullDuplexClientExample {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexServerExample.java
index ce1647d..8b1b36a 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFullDuplexServerExample.java
@@ -80,20 +80,20 @@ public class AsyncFullDuplexServerExample {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java
index ab6d003..b25abb4 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncPipelinedRequestExecutionExample.java
@@ -67,21 +67,21 @@ public class AsyncPipelinedRequestExecutionExample {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java
index 976e522..b863d82 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncRequestExecutionExample.java
@@ -65,21 +65,20 @@ public class AsyncRequestExecutionExample {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
-
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
index d605091..06fb274 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
@@ -35,10 +35,10 @@ import org.apache.hc.core5.http.HttpConnection;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http.impl.Http1StreamListener;
import org.apache.hc.core5.http.impl.bootstrap.HttpRequester;
import org.apache.hc.core5.http.impl.bootstrap.RequesterBootstrap;
+import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.apache.hc.core5.http.message.RequestLine;
@@ -57,21 +57,21 @@ public class ClassicGetExecutionExample {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61834737/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
index 718d835..2814fda 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
@@ -64,21 +64,21 @@ public class ClassicPostExecutionExample {
@Override
public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
- System.out.println(connection + " " + new RequestLine(request));
+ System.out.println(connection.getRemoteAddress() + " " + new RequestLine(request));
}
@Override
public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
- System.out.println(connection + " " + new StatusLine(response));
+ System.out.println(connection.getRemoteAddress() + " " + new StatusLine(response));
}
@Override
public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
if (keepAlive) {
- System.out.println(connection + " exchange completed (connection kept alive)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection kept alive)");
} else {
- System.out.println(connection + " exchange completed (connection closed)");
+ System.out.println(connection.getRemoteAddress() + " exchange completed (connection closed)");
}
}
[3/4] httpcomponents-core git commit: Moved reflection util methods
and marked them internal (no functional changes)
Posted by ol...@apache.org.
Moved reflection util methods and marked them internal (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/865947c7
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/865947c7
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/865947c7
Branch: refs/heads/master
Commit: 865947c7ec353b8a5bcc70c8fe6cd8bb08ede9b9
Parents: 6183473
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Nov 21 18:55:20 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu Nov 22 10:01:13 2018 +0100
----------------------------------------------------------------------
.../apache/hc/core5/http2/ssl/H2TlsSupport.java | 6 +--
.../hc/core5/reactor/ssl/SSLIOSession.java | 4 +-
.../apache/hc/core5/ssl/ReflectionSupport.java | 53 ------------------
.../apache/hc/core5/util/ReflectionUtils.java | 56 ++++++++++++++++++++
4 files changed, 61 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/865947c7/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
index df9f49a..696fdd3 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
@@ -39,7 +39,7 @@ import javax.net.ssl.SSLParameters;
import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
-import org.apache.hc.core5.ssl.ReflectionSupport;
+import org.apache.hc.core5.util.ReflectionUtils;
/**
* HTTP/2 TLS support methods
@@ -367,11 +367,11 @@ public final class H2TlsSupport {
}
public static void setEnableRetransmissions(final SSLParameters sslParameters, final boolean value) {
- ReflectionSupport.callSetter(sslParameters, "EnableRetransmissions", Boolean.TYPE, value);
+ ReflectionUtils.callSetter(sslParameters, "EnableRetransmissions", Boolean.TYPE, value);
}
public static void setApplicationProtocols(final SSLParameters sslParameters, final String[] values) {
- ReflectionSupport.callSetter(sslParameters, "ApplicationProtocols", String[].class, values);
+ ReflectionUtils.callSetter(sslParameters, "ApplicationProtocols", String[].class, values);
}
public static String[] selectApplicationProtocols(final Object attachment) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/865947c7/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index 1b350ab..81bc5d6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -54,9 +54,9 @@ import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.EventMask;
import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.ssl.ReflectionSupport;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Asserts;
+import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
/**
@@ -358,7 +358,7 @@ public class SSLIOSession implements IOSession {
}
if (this.tlsDetails == null) {
final SSLSession sslSession = this.sslEngine.getSession();
- final String applicationProtocol = ReflectionSupport.callGetter(this.sslEngine, "ApplicationProtocol", String.class);
+ final String applicationProtocol = ReflectionUtils.callGetter(this.sslEngine, "ApplicationProtocol", String.class);
this.tlsDetails = new TlsDetails(sslSession, applicationProtocol);
}
if (this.callback != null) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/865947c7/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
deleted file mode 100644
index 8b1ab6d..0000000
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
+++ /dev/null
@@ -1,53 +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.ssl;
-
-import java.lang.reflect.Method;
-
-public final class ReflectionSupport {
-
- public static void callSetter(final Object object, final String setterName, final Class<?> type, final Object value) {
- try {
- final Class<?> clazz = object.getClass();
- final Method method = clazz.getMethod("set" + setterName, type);
- method.invoke(object, value);
- } catch (final Exception ignore) {
- }
- }
-
- public static <T> T callGetter(final Object object, final String getterName, final Class<T> resultType) {
- try {
- final Class<?> clazz = object.getClass();
- final Method method = clazz.getMethod("get" + getterName);
- return resultType.cast(method.invoke(object));
- } catch (final Exception ignore) {
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/865947c7/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java
new file mode 100644
index 0000000..eaa743c
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/ReflectionUtils.java
@@ -0,0 +1,56 @@
+/*
+ * ====================================================================
+ * 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.util;
+
+import java.lang.reflect.Method;
+
+import org.apache.hc.core5.annotation.Internal;
+
+@Internal
+public final class ReflectionUtils {
+
+ public static void callSetter(final Object object, final String setterName, final Class<?> type, final Object value) {
+ try {
+ final Class<?> clazz = object.getClass();
+ final Method method = clazz.getMethod("set" + setterName, type);
+ method.invoke(object, value);
+ } catch (final Exception ignore) {
+ }
+ }
+
+ public static <T> T callGetter(final Object object, final String getterName, final Class<T> resultType) {
+ try {
+ final Class<?> clazz = object.getClass();
+ final Method method = clazz.getMethod("get" + getterName);
+ return resultType.cast(method.invoke(object));
+ } catch (final Exception ignore) {
+ return null;
+ }
+ }
+
+}