370387 - SafariWebsocketDraft0Test failure during build.

The reason for the failure of this test was that a BufferedReader was used to read the header lines.
However, the buffered reader may have read and buffered also the hixie bytes and subsequently,
when the test was trying to read the hixie bytes directly from the input stream (and not from the
buffered reader), the read was timing out.
Fixed by always using the input stream to read the header and hixie bytes.
This commit is contained in:
Simone Bordet 2012-02-24 11:26:50 +01:00
parent 3a82176531
commit 2e66e54425
1 changed files with 17 additions and 19 deletions

View File

@ -15,9 +15,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.jetty.websocket.helper; package org.eclipse.jetty.websocket.helper;
import static org.hamcrest.Matchers.*;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -35,6 +32,8 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.log.StdErrLog;
import org.junit.Assert; import org.junit.Assert;
import static org.hamcrest.Matchers.is;
public class SafariD00 public class SafariD00
{ {
private static final Logger LOG = Log.getLogger(SafariD00.class); private static final Logger LOG = Log.getLogger(SafariD00.class);
@ -56,7 +55,7 @@ public class SafariD00
/** /**
* Open the Socket to the destination endpoint and * Open the Socket to the destination endpoint and
* *
* @return the open java Socket. * @return the open java Socket.
* @throws IOException * @throws IOException
*/ */
@ -75,7 +74,7 @@ public class SafariD00
/** /**
* Issue an Http websocket (Draft-0) upgrade request (using an example request captured from OSX/Safari) * Issue an Http websocket (Draft-0) upgrade request (using an example request captured from OSX/Safari)
* *
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public void issueHandshake() throws IOException public void issueHandshake() throws IOException
@ -103,23 +102,22 @@ public class SafariD00
out.write(buf,0,buf.length); out.write(buf,0,buf.length);
out.flush(); out.flush();
// Read HTTP 101 Upgrade / Handshake Response
InputStreamReader reader = new InputStreamReader(in);
BufferedReader br = new BufferedReader(reader);
socket.setSoTimeout(10000); socket.setSoTimeout(10000);
LOG.debug("Reading http header"); // Read HTTP 101 Upgrade / Handshake Response
boolean foundEnd = false; InputStreamReader reader = new InputStreamReader(in);
String line;
while (!foundEnd) LOG.debug("Reading http headers");
int crlfs = 0;
while (true)
{ {
line = br.readLine(); int read = in.read();
// System.out.printf("RESP: %s%n",line); if (read == '\r' || read == '\n')
if (line.length() == 0) ++crlfs;
{ else
foundEnd = true; crlfs = 0;
} if (crlfs == 4)
break;
} }
// Read expected handshake hixie bytes // Read expected handshake hixie bytes