Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2010-10-22 19:12:22 -0400
committerGreg Wilkins2010-10-22 19:12:22 -0400
commit72e6f5ee407fc373ea6cf27c1e3e99758606bcf2 (patch)
tree928dda2b9c596a2fca6bd62694b91042b95185bc
parente5df5d82ee7d7a02a5eb2d8b2fbd953b818f6fdc (diff)
downloadorg.eclipse.jetty.project-72e6f5ee407fc373ea6cf27c1e3e99758606bcf2.tar.gz
org.eclipse.jetty.project-72e6f5ee407fc373ea6cf27c1e3e99758606bcf2.tar.xz
org.eclipse.jetty.project-72e6f5ee407fc373ea6cf27c1e3e99758606bcf2.zip
328199 ensure SSL closes connections when shutdownoutput is attempted
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2388 7e9141cc-0065-0410-87d8-b60c137991c4
-rw-r--r--VERSION.txt1
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java2
-rw-r--r--jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java1
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java3
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/Response.java42
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java18
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java19
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSocketConnector.java1
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java42
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java3
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java8
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java2
-rw-r--r--test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java8
-rw-r--r--tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java8
14 files changed, 126 insertions, 32 deletions
diff --git a/VERSION.txt b/VERSION.txt
index f529e53698..5879d444b6 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -2,6 +2,7 @@
+ 328199 Ensure blocking connectors always close socket
+ 328205 Improved SelectManager stopping
+ 328306 Serialization of FormAuthentication
+ + 328332 Response.getContentType works with setHeader
jetty-7.2.0.v20101020 20 October 2010
+ 289540 added javadoc into distribution
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java
index db0db7902f..023ad96835 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/AbstractGenerator.java
@@ -260,7 +260,7 @@ public abstract class AbstractGenerator implements Generator
?_persistent.booleanValue()
:(isRequest()?true:_version>HttpVersions.HTTP_1_0_ORDINAL);
}
-
+
/* ------------------------------------------------------------ */
public void setPersistent(boolean persistent)
{
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java
index cc33561bae..a4f8140d36 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/bio/SocketEndPoint.java
@@ -21,7 +21,6 @@ import java.net.Socket;
import org.eclipse.jetty.util.StringUtil;
/**
- *
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java
index 0f67c9f49f..fce6b7f194 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java
@@ -658,6 +658,9 @@ public class HttpConnection implements Connection
// send the body anyway, or close. So we no longer need to
// do anything special here.
_expect100Continue = false;
+
+ if (!_response.isCommitted())
+ _generator.setPersistent(false);
}
if(_endp.isOpen())
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
index 688126af93..35d5be2415 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
@@ -17,7 +17,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.List;
import java.util.Locale;
import javax.servlet.ServletOutputStream;
@@ -39,7 +38,6 @@ import org.eclipse.jetty.io.BufferCache.CachedBuffer;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.util.ByteArrayISO8859Writer;
-import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
@@ -64,15 +62,6 @@ public class Response implements HttpServletResponse
*/
public final static String SET_INCLUDE_HEADER_PREFIX = "org.eclipse.jetty.server.include.";
- private static final PrintWriter __nullPrintWriter;
- private static final ServletOutputStream __nullServletOut;
-
- static
- {
- __nullPrintWriter = new PrintWriter(IO.getNullWriter());
- __nullServletOut = new NullOutput();
- }
-
private final HttpConnection _connection;
private int _status=SC_OK;
private String _reason;
@@ -472,20 +461,25 @@ public class Response implements HttpServletResponse
*/
public void setHeader(String name, String value)
{
- if (_connection.isIncluding())
- {
- if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
- name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
- else
- return;
- }
- _connection.getResponseFields().put(name, value);
- if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
+ if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name))
+ setContentType(value);
+ else
{
- if (value==null)
- _connection._generator.setContentLength(-1);
- else
- _connection._generator.setContentLength(Long.parseLong(value));
+ if (_connection.isIncluding())
+ {
+ if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
+ name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
+ else
+ return;
+ }
+ _connection.getResponseFields().put(name, value);
+ if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
+ {
+ if (value==null)
+ _connection._generator.setContentLength(-1);
+ else
+ _connection._generator.setContentLength(Long.parseLong(value));
+ }
}
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java
index 36df99e7e1..7af5e1c7fc 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/bio/SocketConnector.java
@@ -267,10 +267,24 @@ public class SocketConnector extends AbstractConnector
_connections.remove(this);
}
- // ensure it really is closed and not just shutdown.
+ // wait for client to close, but if not, close ourselves.
try
{
- _socket.close();
+ if (!_socket.isClosed())
+ {
+ long timestamp=System.currentTimeMillis();
+ int max_idle=getMaxIdleTime();
+
+ _socket.setSoTimeout(getMaxIdleTime());
+ int c=0;
+ do
+ {
+ c = _socket.getInputStream().read();
+ }
+ while (c>=0 && (System.currentTimeMillis()-timestamp)<max_idle);
+ if (!_socket.isClosed())
+ _socket.close();
+ }
}
catch(IOException e)
{
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java
index 60b34ab2f2..6210c218f3 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/BlockingChannelConnector.java
@@ -290,6 +290,7 @@ public class BlockingChannelConnector extends AbstractNIOConnector
}
_connection = _connection.handle();
+
}
}
catch (EofException e)
@@ -315,10 +316,24 @@ public class BlockingChannelConnector extends AbstractNIOConnector
connectionClosed(_connection);
_endpoints.remove(this);
- // ensure it really is closed and not just shutdown.
+ // wait for client to close, but if not, close ourselves.
try
{
- _socket.close();
+ if (!_socket.isClosed())
+ {
+ long timestamp=System.currentTimeMillis();
+ int max_idle=getMaxIdleTime();
+
+ _socket.setSoTimeout(getMaxIdleTime());
+ int c=0;
+ do
+ {
+ c = _socket.getInputStream().read();
+ }
+ while (c>=0 && (System.currentTimeMillis()-timestamp)<max_idle);
+ if (!_socket.isClosed())
+ _socket.close();
+ }
}
catch(IOException e)
{
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSocketConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSocketConnector.java
index 26d9713990..af412b21c9 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSocketConnector.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSocketConnector.java
@@ -607,6 +607,7 @@ public class SslSocketConnector extends SocketConnector implements SslConnector
@Override
public void shutdownOutput() throws IOException
{
+ close();
}
@Override
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
index 2108ec03c4..fd97916469 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
@@ -691,6 +691,48 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
}
}
+ @Test
+ public void testBlockedClient() throws Exception
+ {
+ configureServer(new HelloWorldHandler());
+
+ Socket client=newSocket(HOST,_connector.getLocalPort());
+ try
+ {
+ OutputStream os=client.getOutputStream();
+ InputStream is=client.getInputStream();
+
+ // Send a request with chunked input and expect 100
+ os.write((
+ "GET / HTTP/1.1\r\n"+
+ "Host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
+ "Transfer-Encoding: chunked\r\n"+
+ "Expect: 100-continue\r\n"+
+ "Connection: Keep-Alive\r\n"+
+ "\r\n"
+ ).getBytes());
+
+ // Never send a body.
+ // HelloWorldHandler does not read content, so 100 is not sent.
+ // So close will have to happen anyway, without reset!
+
+ os.flush();
+
+ client.setSoTimeout(2000);
+ long start=System.currentTimeMillis();
+ String in = IO.toString(is);
+ assertTrue(System.currentTimeMillis()-start<1000);
+ assertTrue(in.indexOf("Connection: close")>0);
+ assertTrue(in.indexOf("Hello world")>0);
+
+ }
+ finally
+ {
+ client.close();
+ }
+ }
+
+
/**
* Read entire response from the client. Close the output.
*
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
index af16951854..75b18d0141 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
@@ -78,6 +78,9 @@ public class ResponseTest
assertEquals(null,response.getContentType());
+ response.setHeader("Content-Type","text/something");
+ assertEquals("text/something",response.getContentType());
+
response.setContentType("foo/bar");
assertEquals("foo/bar",response.getContentType());
response.getWriter();
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java
index 5f6a991af6..1754b86397 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelServerTest.java
@@ -67,5 +67,11 @@ public class SslSelectChannelServerTest extends HttpServerTestBase
{
// TODO this test uses URL, so noop for now
}
-
+
+ @Test
+ @Override
+ public void testBlockedClient() throws Exception
+ {
+ }
+
}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java
index 6e2dbb1a04..4b13a838e0 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java
@@ -66,5 +66,5 @@ public class SslSocketServerTest extends HttpServerTestBase
{
// TODO this test uses URL, so noop for now
}
-
+
}
diff --git a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java
index c70f65ce16..25bbaee7ec 100644
--- a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java
+++ b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java
@@ -34,6 +34,7 @@ import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.server.handler.RequestLogHandler;
+import org.eclipse.jetty.server.nio.BlockingChannelConnector;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.server.session.HashSessionManager;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
@@ -87,6 +88,13 @@ public class TestServer
connector2.setMaxIdleTime(30000);
connector2.setConfidentialPort(8443);
server.addConnector(connector2);
+
+ // Setup Connectors
+ BlockingChannelConnector connector3 = new BlockingChannelConnector();
+ connector3.setPort(8083);
+ connector3.setMaxIdleTime(30000);
+ connector3.setConfidentialPort(8443);
+ server.addConnector(connector3);
SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector();
ssl_connector.setPort(8443);
diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java
index 026b1a4bfd..2f61564e47 100644
--- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java
+++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java
@@ -721,8 +721,11 @@ public abstract class RFC2616BaseTest
response.assertStatusOK("8.2.3 expect 100");
}
+
+
/**
* Test Message Transmission Requirements -- Acceptable bad client behavior, Expect 100 with body content.
+ * @throws Exception failure
*
* @see <a href="http://tools.ietf.org/html/rfc2616#section-8.2">RFC 2616 (section 8.2)</a>
*/
@@ -749,10 +752,15 @@ public abstract class RFC2616BaseTest
List<HttpResponseTester> responses = http.requests(req3);
+ System.err.println(responses);
+
response=responses.get(0);
+ System.err.println(response.getRawResponse());
+
response.assertStatus("8.2.3 ignored no 100",302);
response=responses.get(1);
+ System.err.println(response.getRawResponse());
response.assertStatus("8.2.3 ignored no 100",200);
response.assertBody("87654321\n");
}

Back to the top