8156825: java/net/httpclient/BasicWebSocketAPITest.java failed with java.lang.AssertionError

Reviewed-by: rriggs
This commit is contained in:
Michael McMahon 2016-05-16 16:04:14 +01:00
parent baf59c0bd8
commit fc86d03190
5 changed files with 42 additions and 32 deletions

View File

@ -35,6 +35,7 @@ import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Iterator;
@ -155,6 +156,15 @@ class HttpClientImpl extends HttpClient implements BufferHandler {
selmgr.register(exchange);
}
/**
* Only used from RawChannel to disconnect the channel from
* the selector
*/
void cancelRegistration(SocketChannel s) {
selmgr.cancel(s);
}
Http2ClientImpl client2() {
return client2;
}
@ -220,6 +230,13 @@ class HttpClientImpl extends HttpClient implements BufferHandler {
selector.wakeup();
}
synchronized void cancel(SocketChannel e) {
SelectionKey key = e.keyFor(selector);
if (key != null)
key.cancel();
selector.wakeup();
}
void wakeupSelector() {
selector.wakeup();
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
*/
package java.net.http;
public interface HttpHeaders1 extends HttpHeaders {
public void makeUnmodifiable();
}

View File

@ -176,7 +176,7 @@ class HttpResponseImpl extends HttpResponse {
*
* @return
*/
RawChannel rawChannel() {
RawChannel rawChannel() throws IOException {
if (rawchan == null) {
rawchan = new RawChannel(request.client(), connection);
}

View File

@ -29,6 +29,7 @@ import java.nio.channels.ByteChannel;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
//
// Used to implement WebSocket. Each RawChannel corresponds to a TCP connection
@ -56,9 +57,21 @@ final class RawChannel implements ByteChannel, GatheringByteChannel {
interface NonBlockingEvent extends RawEvent {
}
RawChannel(HttpClientImpl client, HttpConnection connection) {
RawChannel(HttpClientImpl client, HttpConnection connection)
throws IOException {
this.client = client;
this.connection = connection;
SocketChannel chan = connection.channel();
client.cancelRegistration(chan);
chan.configureBlocking(false);
}
SocketChannel socketChannel() {
return connection.channel();
}
ByteBuffer getRemaining() {
return connection.getRemaining();
}
private class RawAsyncEvent extends AsyncEvent {

View File

@ -24,6 +24,8 @@
*/
package java.net.http;
import java.io.UncheckedIOException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
@ -126,6 +128,8 @@ final class WSOpeningHandshake {
return CompletableFuture.completedFuture(result);
} catch (WebSocketHandshakeException e) {
return CompletableFuture.failedFuture(e);
} catch (UncheckedIOException ee) {
return CompletableFuture.failedFuture(ee.getCause());
}
});
}
@ -149,7 +153,12 @@ final class WSOpeningHandshake {
checkAccept(response, h);
checkExtensions(response, h);
String subprotocol = checkAndReturnSubprotocol(response, h);
RawChannel channel = ((HttpResponseImpl) response).rawChannel();
RawChannel channel = null;
try {
channel = ((HttpResponseImpl) response).rawChannel();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return new Result(subprotocol, channel);
}