AbstractAsyncSSLConnection.java revision 17571:4e7ef83423c2
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
30Sstevel@tonic-gate * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
40Sstevel@tonic-gate *
50Sstevel@tonic-gate * This code is free software; you can redistribute it and/or modify it
60Sstevel@tonic-gate * under the terms of the GNU General Public License version 2 only, as
70Sstevel@tonic-gate * published by the Free Software Foundation.  Oracle designates this
80Sstevel@tonic-gate * particular file as subject to the "Classpath" exception as provided
90Sstevel@tonic-gate * by Oracle in the LICENSE file that accompanied this code.
100Sstevel@tonic-gate *
110Sstevel@tonic-gate * This code is distributed in the hope that it will be useful, but WITHOUT
120Sstevel@tonic-gate * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
130Sstevel@tonic-gate * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
140Sstevel@tonic-gate * version 2 for more details (a copy is included in the LICENSE file that
150Sstevel@tonic-gate * accompanied this code).
160Sstevel@tonic-gate *
170Sstevel@tonic-gate * You should have received a copy of the GNU General Public License version
180Sstevel@tonic-gate * 2 along with this work; if not, write to the Free Software Foundation,
190Sstevel@tonic-gate * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
200Sstevel@tonic-gate *
210Sstevel@tonic-gate * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
220Sstevel@tonic-gate * or visit www.oracle.com if you need additional information or have any
230Sstevel@tonic-gate * questions.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gatepackage jdk.incubator.http;
270Sstevel@tonic-gate
280Sstevel@tonic-gateimport java.io.IOException;
290Sstevel@tonic-gateimport java.net.InetSocketAddress;
300Sstevel@tonic-gateimport java.nio.ByteBuffer;
310Sstevel@tonic-gateimport java.util.concurrent.CompletableFuture;
320Sstevel@tonic-gateimport javax.net.ssl.SSLEngine;
330Sstevel@tonic-gateimport jdk.incubator.http.internal.common.ExceptionallyCloseable;
340Sstevel@tonic-gate
350Sstevel@tonic-gate
360Sstevel@tonic-gate/**
370Sstevel@tonic-gate * Asynchronous version of SSLConnection.
380Sstevel@tonic-gate *
390Sstevel@tonic-gate * There are two concrete implementations of this class: AsyncSSLConnection
400Sstevel@tonic-gate * and AsyncSSLTunnelConnection.
410Sstevel@tonic-gate * This abstraction is useful when downgrading from HTTP/2 to HTTP/1.1 over
420Sstevel@tonic-gate * an SSL connection. See ExchangeImpl::get in the case where an ALPNException
430Sstevel@tonic-gate * is thrown.
440Sstevel@tonic-gate *
450Sstevel@tonic-gate * Note: An AsyncSSLConnection wraps a PlainHttpConnection, while an
460Sstevel@tonic-gate *       AsyncSSLTunnelConnection wraps a PlainTunnelingConnection.
470Sstevel@tonic-gate *       If both these wrapped classes where made to inherit from a
480Sstevel@tonic-gate *       common abstraction then it might be possible to merge
490Sstevel@tonic-gate *       AsyncSSLConnection and AsyncSSLTunnelConnection back into
500Sstevel@tonic-gate *       a single class - and simply use different factory methods to
510Sstevel@tonic-gate *       create different wrappees, but this is left up for further cleanup.
520Sstevel@tonic-gate *
530Sstevel@tonic-gate */
540Sstevel@tonic-gateabstract class AbstractAsyncSSLConnection extends HttpConnection
550Sstevel@tonic-gate               implements AsyncConnection, ExceptionallyCloseable {
560Sstevel@tonic-gate
570Sstevel@tonic-gate
580Sstevel@tonic-gate    AbstractAsyncSSLConnection(InetSocketAddress addr, HttpClientImpl client) {
590Sstevel@tonic-gate        super(addr, client);
600Sstevel@tonic-gate    }
610Sstevel@tonic-gate
620Sstevel@tonic-gate    abstract SSLEngine getEngine();
630Sstevel@tonic-gate    abstract AsyncSSLDelegate sslDelegate();
640Sstevel@tonic-gate    abstract HttpConnection plainConnection();
650Sstevel@tonic-gate    abstract HttpConnection downgrade();
660Sstevel@tonic-gate
670Sstevel@tonic-gate    @Override
680Sstevel@tonic-gate    final boolean isSecure() {
690Sstevel@tonic-gate        return true;
700Sstevel@tonic-gate    }
710Sstevel@tonic-gate
720Sstevel@tonic-gate    // Blocking read functions not used here
730Sstevel@tonic-gate    @Override
740Sstevel@tonic-gate    protected final ByteBuffer readImpl() throws IOException {
750Sstevel@tonic-gate        throw new UnsupportedOperationException("Not supported.");
760Sstevel@tonic-gate    }
770Sstevel@tonic-gate
780Sstevel@tonic-gate    // whenReceivedResponse only used in HTTP/1.1 (Http1Exchange)
790Sstevel@tonic-gate    // AbstractAsyncSSLConnection is only used with HTTP/2
800Sstevel@tonic-gate    @Override
810Sstevel@tonic-gate    final CompletableFuture<Void> whenReceivingResponse() {
820Sstevel@tonic-gate        throw new UnsupportedOperationException("Not supported.");
830Sstevel@tonic-gate    }
840Sstevel@tonic-gate
850Sstevel@tonic-gate}
860Sstevel@tonic-gate