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/05/10 07:45:04 UTC
httpcomponents-core git commit: Keep examples self-contained
Repository: httpcomponents-core
Updated Branches:
refs/heads/4.4.x 44344d4cf -> 0ad926e89
Keep examples self-contained
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/0ad926e8
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/0ad926e8
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/0ad926e8
Branch: refs/heads/4.4.x
Commit: 0ad926e89caa64cff6ec6b1e84ab25d4af6ec6dc
Parents: 44344d4
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed May 10 09:44:25 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed May 10 09:44:25 2017 +0200
----------------------------------------------------------------------
.../http/examples/nio/NHttpReverseProxy.java | 13 ++++-
.../examples/nio/TrustSelfSignedStrategy.java | 50 --------------------
2 files changed, 12 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/0ad926e8/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
index 04c484a..3b3090f 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
@@ -31,6 +31,8 @@ import java.io.InterruptedIOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.nio.ByteBuffer;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicLong;
@@ -101,6 +103,7 @@ import org.apache.http.protocol.ResponseContent;
import org.apache.http.protocol.ResponseDate;
import org.apache.http.protocol.ResponseServer;
import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.ssl.TrustStrategy;
/**
* Asynchronous, fully streaming HTTP/1.1 reverse proxy.
@@ -121,7 +124,15 @@ public class NHttpReverseProxy {
SSLContext sslContext = null;
if (args.length > 2 && args[2].equals("TrustSelfSignedStrategy")) {
System.out.println("Using TrustSelfSignedStrategy (not for production.)");
- sslContext = SSLContextBuilder.create().loadTrustMaterial(TrustSelfSignedStrategy.INSTANCE).build();
+ sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustStrategy() {
+
+ @Override
+ public boolean isTrusted(
+ final X509Certificate[] chain, final String authType) throws CertificateException {
+ return chain.length == 1;
+ }
+
+ }).build();
}
// Target host
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/0ad926e8/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java
deleted file mode 100644
index 5969b1c..0000000
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java
+++ /dev/null
@@ -1,50 +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.http.examples.nio;
-
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-
-import org.apache.http.ssl.TrustStrategy;
-
-/**
- * A trust strategy that accepts self-signed certificates as trusted. Verification of all other
- * certificates is done by the trust manager configured in the SSL context.
- *
- * Copied from HttClient.
- */
-class TrustSelfSignedStrategy implements TrustStrategy {
-
- public static final TrustSelfSignedStrategy INSTANCE = new TrustSelfSignedStrategy();
-
- @Override
- public boolean isTrusted(
- final X509Certificate[] chain, final String authType) throws CertificateException {
- return chain.length == 1;
- }
-
-}