400503 - WebSocket - squelch legitimate Exceptions during testing to avoid false positives

This commit is contained in:
Joakim Erdfelt 2013-06-17 16:33:47 -07:00
parent d3645ac28c
commit be2cf578ce
5 changed files with 38 additions and 21 deletions

View File

@ -21,9 +21,11 @@ package org.eclipse.jetty.websocket.client;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
@ -75,7 +77,7 @@ public class TomcatServerQuirksTest
try
{
int bufferSize = 512;
final int bufferSize = 512;
server.start();
@ -102,18 +104,17 @@ public class TomcatServerQuirksTest
Assert.assertTrue("Timed out waiting for Client side WebSocket open event",websocket.openLatch.await(1,TimeUnit.SECONDS));
// Have server write frame.
int length = bufferSize / 2;
ByteBuffer serverFrame = ByteBuffer.allocate(bufferSize);
byte payload[] = new byte[bufferSize / 2];
Arrays.fill(payload,(byte)'x');
ByteBuffer serverFrame = BufferUtil.allocate(bufferSize);
BufferUtil.flipToFill(serverFrame);
serverFrame.put((byte)(0x80 | 0x01)); // FIN + TEXT
serverFrame.put((byte)0x7E); // No MASK and 2 bytes length
serverFrame.put((byte)(length >> 8)); // first length byte
serverFrame.put((byte)(length & 0xFF)); // second length byte
for (int i = 0; i < length; ++i)
{
serverFrame.put((byte)'x');
}
serverFrame.flip();
byte buf[] = serverFrame.array();
serverFrame.put((byte)(payload.length >> 8)); // first length byte
serverFrame.put((byte)(payload.length & 0xFF)); // second length byte
serverFrame.put(payload);
BufferUtil.flipToFlush(serverFrame,0);
byte buf[] = BufferUtil.toArray(serverFrame);
socket.write(buf,0,buf.length);
socket.flush();

View File

@ -68,7 +68,7 @@ public class WebSocketOverSSLTest
Future<Session> fut = client.connect(clientSocket,server.getServerUri());
// wait for connect
Session session = fut.get(1,TimeUnit.SECONDS);
Session session = fut.get(3,TimeUnit.SECONDS);
// Generate text frame
String msg = "this is an echo ... cho ... ho ... o";

View File

@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.log.StacklessLogging;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.extensions.Frame;
@ -36,6 +37,7 @@ import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
import org.eclipse.jetty.websocket.server.helper.RFCServlet;
@ -204,14 +206,17 @@ public class WebSocketServletRFCTest
client.sendStandardRequest();
client.expectUpgradeResponse();
// Generate text frame
client.write(WebSocketFrame.text("CRASH"));
try (StacklessLogging context = new StacklessLogging(EventDriver.class))
{
// Generate text frame
client.write(WebSocketFrame.text("CRASH"));
// Read frame (hopefully close frame)
IncomingFramesCapture capture = client.readFrames(1,TimeUnit.MILLISECONDS,500);
Frame cf = capture.getFrames().poll();
CloseInfo close = new CloseInfo(cf);
Assert.assertThat("Close Frame.status code",close.getStatusCode(),is(StatusCode.SERVER_ERROR));
// Read frame (hopefully close frame)
IncomingFramesCapture capture = client.readFrames(1,TimeUnit.MILLISECONDS,500);
Frame cf = capture.getFrames().poll();
CloseInfo close = new CloseInfo(cf);
Assert.assertThat("Close Frame.status code",close.getStatusCode(),is(StatusCode.SERVER_ERROR));
}
}
finally
{

View File

@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
@ -77,7 +78,14 @@ public class ABSocket
}
}
// echo the message back.
this.session.getRemote().sendStringByFuture(message);
try
{
// echo the message back.
this.session.getRemote().sendStringByFuture(message);
}
catch (WebSocketException e)
{
LOG.warn("Unable to echo TEXT message",e);
}
}
}

View File

@ -17,3 +17,6 @@ org.eclipse.jetty.websocket.server.browser.LEVEL=DEBUG
### Disabling intentional error out of RFCSocket
org.eclipse.jetty.websocket.server.helper.RFCSocket.LEVEL=OFF
### Hiding Stack Traces from ABSocket
org.eclipse.jetty.websocket.server.ab.ABSocket.STACKS=OFF