use of org.eclipse.jetty.io.EndPoint in project jetty.project by eclipse.
the class ConnectorTimeoutTest method testMaxIdleWithRequest10ClientIgnoresClose.
@Test(timeout = 60000)
public void testMaxIdleWithRequest10ClientIgnoresClose() throws Exception {
final Exchanger<EndPoint> exchanger = new Exchanger<>();
configureServer(new HelloWorldHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
exchanger.exchange(baseRequest.getHttpChannel().getEndPoint());
} catch (Exception e) {
e.printStackTrace();
}
super.handle(target, baseRequest, request, response);
}
});
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
client.setSoTimeout(10000);
Assert.assertFalse(client.isClosed());
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
os.write(("GET / HTTP/1.0\r\n" + "host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" + "connection: close\r\n" + "\r\n").getBytes("utf-8"));
os.flush();
// Get the server side endpoint
EndPoint endPoint = exchanger.exchange(null, 10, TimeUnit.SECONDS);
if (endPoint instanceof SslConnection.DecryptedEndPoint)
endPoint = endPoint.getConnection().getEndPoint();
// read the response
String result = IO.toString(is);
Assert.assertThat("OK", result, Matchers.containsString("200 OK"));
// check client reads EOF
Assert.assertEquals(-1, is.read());
Assert.assertTrue(endPoint.isOutputShutdown());
Thread.sleep(2 * MAX_IDLE_TIME);
// further writes will get broken pipe or similar
try {
long end = System.currentTimeMillis() + MAX_IDLE_TIME + 3000;
while (System.currentTimeMillis() < end) {
os.write("THIS DATA SHOULD NOT BE PARSED!\n\n".getBytes("utf-8"));
os.flush();
Thread.sleep(100);
}
Assert.fail("half close should have timed out");
} catch (SocketException e) {
// expected
// Give the SSL onClose time to act
Thread.sleep(100);
}
// check the server side is closed
Assert.assertFalse(endPoint.isOpen());
}
use of org.eclipse.jetty.io.EndPoint in project zm-mailbox by Zimbra.
the class JettyUtil method setIdleTimeout.
public static void setIdleTimeout(long timeout, HttpServletRequest request) {
if (request != null) {
Object attr = request.getAttribute("org.eclipse.jetty.server.HttpConnection");
if (attr instanceof HttpConnection) {
@SuppressWarnings("resource") HttpConnection conn = (HttpConnection) attr;
EndPoint ep = conn.getEndPoint();
if (ep != null) {
ep.setIdleTimeout(timeout);
} else {
ZimbraLog.misc.warn("null endpoint setting Jetty timeout?", new Exception());
}
} else {
//this won't work for SPDY connections, so we'll have to consider this further once we enable it.
ZimbraLog.misc.warn("got [%s] not instanceof org.eclipse.jetty.server.HttpConnection", attr, new Exception());
}
} else {
ZimbraLog.misc.warn("cannot set timeout for null request", new Exception());
}
}
Aggregations