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
143 public synchronized RawChannel rawChannel() throws IOException {
144 if (rawchan == null) {
145 ExchangeImpl<?> exchImpl = exchangeImpl();
146 if (!(exchImpl instanceof Http1Exchange)) {
147 // RawChannel is only used for WebSocket - and WebSocket
148 // is not supported over HTTP/2 yet, so we should not come
149 // here. Getting a RawChannel over HTTP/2 might be supported
150 // in the future, but it would entail retrieving any left over
151 // bytes that might have been read but not consumed by the
152 // HTTP/2 connection.
153 throw new UnsupportedOperationException("RawChannel is not supported over HTTP/2");
154 }
155 // Http1Exchange may have some remaining bytes in its
156 // internal buffer.
157 Supplier<ByteBuffer> initial = ((Http1Exchange<?>)exchImpl)::drainLeftOverBytes;
158 rawchan = new RawChannelTube(connection, initial);
159 }
160 return rawchan;
161 }
162
163 @Override
164 public String toString() {
165 StringBuilder sb = new StringBuilder();
166 String method = request().method();
167 URI uri = request().uri();
168 String uristring = uri == null ? "" : uri.toString();
169 sb.append('(')
170 .append(method)
171 .append(" ")
172 .append(uristring)
173 .append(") ")
174 .append(statusCode());
175 return sb.toString();
176 }
177 }
|
1 /*
2 * Copyright (c) 2015, 2020, 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
143 public synchronized RawChannel rawChannel() throws IOException {
144 if (rawchan == null) {
145 ExchangeImpl<?> exchImpl = exchangeImpl();
146 if (!(exchImpl instanceof Http1Exchange)) {
147 // RawChannel is only used for WebSocket - and WebSocket
148 // is not supported over HTTP/2 yet, so we should not come
149 // here. Getting a RawChannel over HTTP/2 might be supported
150 // in the future, but it would entail retrieving any left over
151 // bytes that might have been read but not consumed by the
152 // HTTP/2 connection.
153 throw new UnsupportedOperationException("RawChannel is not supported over HTTP/2");
154 }
155 // Http1Exchange may have some remaining bytes in its
156 // internal buffer.
157 Supplier<ByteBuffer> initial = ((Http1Exchange<?>)exchImpl)::drainLeftOverBytes;
158 rawchan = new RawChannelTube(connection, initial);
159 }
160 return rawchan;
161 }
162
163 /**
164 * Closes the RawChannel that may have been used for WebSocket protocol.
165 *
166 * @apiNote This method should be called to close the connection
167 * if an exception occurs during the websocket handshake, in cases where
168 * {@link #rawChannel() rawChannel().close()} would have been called.
169 * An unsuccessful handshake may prevent the creation of the RawChannel:
170 * if a RawChannel has already been created, this method wil close it.
171 * Otherwise, it will close the connection.
172 *
173 * @throws IOException if an I/O exception occurs while closing
174 * the channel.
175 */
176 public synchronized void closeRawChannel() throws IOException {
177 // close the rawChannel, if created, or the
178 // connection, if not.
179 if (rawchan != null) rawchan.close();
180 else connection.close();
181 }
182
183 @Override
184 public String toString() {
185 StringBuilder sb = new StringBuilder();
186 String method = request().method();
187 URI uri = request().uri();
188 String uristring = uri == null ? "" : uri.toString();
189 sb.append('(')
190 .append(method)
191 .append(" ")
192 .append(uristring)
193 .append(") ")
194 .append(statusCode());
195 return sb.toString();
196 }
197 }
|