author | prappo |
Fri, 10 Nov 2017 16:24:07 +0300 | |
branch | http-client-branch |
changeset 55799 | c71f52f48d97 |
parent 55795 | 074bb951658a |
child 55892 | 9f345a976249 |
permissions | -rw-r--r-- |
46157 | 1 |
/* |
2 |
* Copyright (c) 2015, 2017, 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 jdk.incubator.http; |
|
27 |
||
28 |
import java.io.IOException; |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
29 |
import java.lang.System.Logger.Level; |
46157 | 30 |
import java.net.InetSocketAddress; |
31 |
import java.nio.channels.SocketChannel; |
|
32 |
import java.util.concurrent.CompletableFuture; |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
33 |
import jdk.incubator.http.internal.common.SSLTube; |
46157 | 34 |
import jdk.incubator.http.internal.common.Utils; |
35 |
||
36 |
/** |
|
37 |
* An SSL tunnel built on a Plain (CONNECT) TCP tunnel. |
|
38 |
*/ |
|
39 |
class AsyncSSLTunnelConnection extends AbstractAsyncSSLConnection { |
|
40 |
||
41 |
final PlainTunnelingConnection plainConnection; |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
42 |
final PlainHttpPublisher writePublisher; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
43 |
volatile SSLTube flow; |
46157 | 44 |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
45 |
AsyncSSLTunnelConnection(InetSocketAddress addr, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
46 |
HttpClientImpl client, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
47 |
String[] alpn, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
48 |
InetSocketAddress proxy) |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
49 |
{ |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
50 |
super(addr, client, Utils.getServerName(addr), alpn); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
51 |
this.plainConnection = new PlainTunnelingConnection(addr, proxy, client); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
52 |
this.writePublisher = new PlainHttpPublisher(); |
46157 | 53 |
} |
54 |
||
55 |
@Override |
|
56 |
public CompletableFuture<Void> connectAsync() { |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
57 |
debug.log(Level.DEBUG, "Connecting plain tunnel connection"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
58 |
// This will connect the PlainHttpConnection flow, so that |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
59 |
// its HttpSubscriber and HttpPublisher are subscribed to the |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
60 |
// SocketTube |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
61 |
return plainConnection |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
62 |
.connectAsync() |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
63 |
.thenApply( unused -> { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
64 |
debug.log(Level.DEBUG, "creating SSLTube"); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
65 |
// create the SSLTube wrapping the SocketTube, with the given engine |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
66 |
flow = new SSLTube(engine, |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
67 |
client().theExecutor(), |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
68 |
plainConnection.getConnectionFlow()); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
69 |
return null;} ); |
46157 | 70 |
} |
71 |
||
72 |
@Override |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
73 |
boolean connected() { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
74 |
return plainConnection.connected(); // && sslDelegate.connected(); |
46157 | 75 |
} |
76 |
||
77 |
@Override |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
78 |
HttpPublisher publisher() { return writePublisher; } |
46157 | 79 |
|
80 |
@Override |
|
81 |
public String toString() { |
|
82 |
return "AsyncSSLTunnelConnection: " + super.toString(); |
|
83 |
} |
|
84 |
||
85 |
@Override |
|
86 |
PlainTunnelingConnection plainConnection() { |
|
87 |
return plainConnection; |
|
88 |
} |
|
89 |
||
90 |
@Override |
|
91 |
ConnectionPool.CacheKey cacheKey() { |
|
92 |
return ConnectionPool.cacheKey(address, plainConnection.proxyAddr); |
|
93 |
} |
|
94 |
||
95 |
@Override |
|
96 |
public void close() { |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
97 |
plainConnection.close(); |
46157 | 98 |
} |
99 |
||
100 |
@Override |
|
101 |
void shutdownInput() throws IOException { |
|
102 |
plainConnection.channel().shutdownInput(); |
|
103 |
} |
|
104 |
||
105 |
@Override |
|
106 |
void shutdownOutput() throws IOException { |
|
107 |
plainConnection.channel().shutdownOutput(); |
|
108 |
} |
|
109 |
||
110 |
@Override |
|
111 |
SocketChannel channel() { |
|
112 |
return plainConnection.channel(); |
|
113 |
} |
|
114 |
||
115 |
@Override |
|
116 |
boolean isProxied() { |
|
117 |
return true; |
|
118 |
} |
|
119 |
||
120 |
@Override |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
121 |
public void closeExceptionally(Throwable cause) { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
122 |
debug.log(Level.DEBUG, "Closing connection: ", cause); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
123 |
plainConnection.close(); |
46157 | 124 |
} |
125 |
||
126 |
@Override |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
127 |
SSLTube getConnectionFlow() { |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
128 |
return flow; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47216
diff
changeset
|
129 |
} |
46157 | 130 |
} |