|
1 /* |
|
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package java.net.http.internal; |
|
27 |
|
28 import java.io.IOException; |
|
29 import java.lang.System.Logger.Level; |
|
30 import java.net.InetSocketAddress; |
|
31 import java.nio.channels.SocketChannel; |
|
32 import java.util.concurrent.CompletableFuture; |
|
33 import java.net.http.internal.common.SSLTube; |
|
34 import java.net.http.internal.common.Utils; |
|
35 |
|
36 |
|
37 /** |
|
38 * Asynchronous version of SSLConnection. |
|
39 */ |
|
40 class AsyncSSLConnection extends AbstractAsyncSSLConnection { |
|
41 |
|
42 final PlainHttpConnection plainConnection; |
|
43 final PlainHttpPublisher writePublisher; |
|
44 private volatile SSLTube flow; |
|
45 |
|
46 AsyncSSLConnection(InetSocketAddress addr, |
|
47 HttpClientImpl client, |
|
48 String[] alpn) { |
|
49 super(addr, client, Utils.getServerName(addr), alpn); |
|
50 plainConnection = new PlainHttpConnection(addr, client); |
|
51 writePublisher = new PlainHttpPublisher(); |
|
52 } |
|
53 |
|
54 @Override |
|
55 PlainHttpConnection plainConnection() { |
|
56 return plainConnection; |
|
57 } |
|
58 |
|
59 @Override |
|
60 public CompletableFuture<Void> connectAsync() { |
|
61 return plainConnection |
|
62 .connectAsync() |
|
63 .thenApply( unused -> { |
|
64 // create the SSLTube wrapping the SocketTube, with the given engine |
|
65 flow = new SSLTube(engine, |
|
66 client().theExecutor(), |
|
67 plainConnection.getConnectionFlow()); |
|
68 return null; } ); |
|
69 } |
|
70 |
|
71 @Override |
|
72 boolean connected() { |
|
73 return plainConnection.connected(); |
|
74 } |
|
75 |
|
76 @Override |
|
77 HttpPublisher publisher() { return writePublisher; } |
|
78 |
|
79 @Override |
|
80 boolean isProxied() { |
|
81 return false; |
|
82 } |
|
83 |
|
84 @Override |
|
85 SocketChannel channel() { |
|
86 return plainConnection.channel(); |
|
87 } |
|
88 |
|
89 @Override |
|
90 ConnectionPool.CacheKey cacheKey() { |
|
91 return ConnectionPool.cacheKey(address, null); |
|
92 } |
|
93 |
|
94 @Override |
|
95 public void close() { |
|
96 plainConnection.close(); |
|
97 } |
|
98 |
|
99 @Override |
|
100 void shutdownInput() throws IOException { |
|
101 debug.log(Level.DEBUG, "plainConnection.channel().shutdownInput()"); |
|
102 plainConnection.channel().shutdownInput(); |
|
103 } |
|
104 |
|
105 @Override |
|
106 void shutdownOutput() throws IOException { |
|
107 debug.log(Level.DEBUG, "plainConnection.channel().shutdownOutput()"); |
|
108 plainConnection.channel().shutdownOutput(); |
|
109 } |
|
110 |
|
111 @Override |
|
112 SSLTube getConnectionFlow() { |
|
113 return flow; |
|
114 } |
|
115 } |