diff --git a/VERSION.txt b/VERSION.txt index 9b92b028e63..bc5db5fb071 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -25,6 +25,7 @@ jetty-7.3.0-SNAPSHOT + 333679 refactor jetty-jmx to support the OSGi PAX tests. + 334062 It should be possible to embed in the jetty.home.bundle the ssl keystore files + 334229 javax-security needs to import the package javax.security.cert in its OSGi manifest + + 334311 fix buffer reuse issue in CachedExchange jetty-7.2.2.v20101205 5 December 2010 + JETTY-1308 327109 (re)fixed AJP handling of empty packets diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/CachedExchange.java b/jetty-client/src/main/java/org/eclipse/jetty/client/CachedExchange.java index c36cb6834d3..9885925c0b6 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/CachedExchange.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/CachedExchange.java @@ -60,7 +60,10 @@ public class CachedExchange extends HttpExchange protected synchronized void onResponseHeader(Buffer name, Buffer value) throws IOException { if (_responseFields != null) - _responseFields.add(name, value); + { + _responseFields.add(name, value.asImmutableBuffer()); + } + super.onResponseHeader(name, value); } } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/CachedHeadersIsolationTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/CachedHeadersIsolationTest.java new file mode 100644 index 00000000000..595f7d818a9 --- /dev/null +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/CachedHeadersIsolationTest.java @@ -0,0 +1,117 @@ +package org.eclipse.jetty.client; + +import java.io.IOException; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; + +import org.eclipse.jetty.client.CachedExchange; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.server.nio.SelectChannelConnector; + +public class CachedHeadersIsolationTest extends TestCase +{ + + Server server; + HttpClient client; + int port; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + server = new Server(); + + Connector connector = new SelectChannelConnector(); + + server.addConnector(connector); + + server.setHandler(new AbstractHandler() + { + + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, + ServletException + { + response.setStatus(HttpStatus.OK_200); + response.addHeader("For",request.getQueryString()); + response.addHeader("Name","Value"); + response.getOutputStream().print("blah"); + response.flushBuffer(); + } + }); + + server.start(); + + port = server.getConnectors()[0].getLocalPort(); + + client = new HttpClient(); + client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); + client.setConnectTimeout(5); + client.start(); + + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + server.stop(); + client.stop(); + } + + public void testHeaderWhenReadEarly() throws Exception + { + + CachedExchange e1 = new CachedExchange(true); + CachedExchange e2 = new CachedExchange(true); + + e1.setURL("http://localhost:" + port + "/?a=short"); + e2.setURL("http://localhost:" + port + "/?a=something_longer"); + + client.send(e1); + while (!e1.isDone()) + Thread.sleep(100); + + assertEquals("Read buffer","Value",e1.getResponseFields().getStringField("Name")); + + client.send(e2); + while (!e2.isDone()) + Thread.sleep(100); + + assertEquals("Overwritten buffer","Value",e1.getResponseFields().getStringField("Name")); + } + + public void testHeaderWhenReadLate() throws Exception + { + + CachedExchange e1 = new CachedExchange(true); + CachedExchange e2 = new CachedExchange(true); + + e1.setURL("http://localhost:" + port + "/?a=short"); + e2.setURL("http://localhost:" + port + "/?a=something_longer"); + + client.send(e1); + while (!e1.isDone()) + Thread.sleep(100); + + client.send(e2); + while (!e2.isDone()) + Thread.sleep(100); + + for ( Enumeration e = e1.getResponseFields().getValues("Name"); e.hasMoreElements();) + { + System.out.println(e.nextElement()); + } + + assertEquals("Overwritten buffer","Value",e1.getResponseFields().getStringField("Name")); + } +} \ No newline at end of file