Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 22179200C73 for ; Wed, 10 May 2017 21:12:20 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 20B16160B9C; Wed, 10 May 2017 19:12:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 67D0D160B99 for ; Wed, 10 May 2017 21:12:19 +0200 (CEST) Received: (qmail 42942 invoked by uid 500); 10 May 2017 19:12:17 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 42932 invoked by uid 99); 10 May 2017 19:12:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 May 2017 19:12:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E27D6DFBAB; Wed, 10 May 2017 19:12:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: olegk@apache.org To: commits@hc.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: httpcomponents-core git commit: Keep examples self-contained [Forced Update!] Date: Wed, 10 May 2017 19:12:16 +0000 (UTC) archived-at: Wed, 10 May 2017 19:12:20 -0000 Repository: httpcomponents-core Updated Branches: refs/heads/4.4.x 0ad926e89 -> 5b29a6e4a (forced update) 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/5b29a6e4 Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/5b29a6e4 Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/5b29a6e4 Branch: refs/heads/4.4.x Commit: 5b29a6e4a6c141ddb6b81c496d161564630cc0e0 Parents: 44344d4 Author: Oleg Kalnichevski Authored: Wed May 10 09:44:25 2017 +0200 Committer: Oleg Kalnichevski Committed: Wed May 10 21:11:38 2017 +0200 ---------------------------------------------------------------------- .../http/examples/nio/NHttpReverseProxy.java | 15 +++++- .../examples/nio/TrustSelfSignedStrategy.java | 50 -------------------- 2 files changed, 13 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5b29a6e4/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..82dfa23 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. @@ -120,8 +123,16 @@ public class NHttpReverseProxy { int port = Integer.parseInt(args[1]); 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(); + System.out.println("Using TrustSelfSignedStrategy (not for production)"); + 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/5b29a6e4/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 - * . - * - */ -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; - } - -}