Jetty9 - Cleaned up and fixed the failing tests.

This commit is contained in:
Simone Bordet 2012-08-23 15:09:09 +02:00
parent e74a5cd105
commit 85ffa8807e

View File

@ -26,7 +26,6 @@ import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import javax.servlet.ServletException;
@ -34,25 +33,20 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.io.AbstractConnection;
import org.eclipse.jetty.io.AbstractEndPoint;
import org.eclipse.jetty.io.ByteArrayEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.session.HashSessionIdManager;
import org.eclipse.jetty.server.session.HashSessionManager;
import org.eclipse.jetty.server.session.HashedSession;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.IO;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@ -60,13 +54,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
*
*/
public class ResponseTest
{
private Server _server;
private LocalConnector _connector;
private HttpChannel _channel;
private ScheduledExecutorService _timer;
@ -74,55 +64,31 @@ public class ResponseTest
public void init() throws Exception
{
_server = new Server();
_connector = new LocalConnector(_server);
_server.addConnector(_connector);
_timer = new ScheduledThreadPoolExecutor(1);
LocalConnector connector = new LocalConnector(_server, null, _timer, null, null, 1);
_server.addConnector(connector);
_server.setHandler(new DumpHandler());
_server.start();
_timer=new ScheduledThreadPoolExecutor(1);
AbstractEndPoint endp = new ByteArrayEndPoint(_timer,5000);
AbstractEndPoint endp = new ByteArrayEndPoint(_timer, 5000);
HttpInput input = new HttpInput();
Connection connection = new AbstractConnection(endp,new Executor()
_channel = new HttpChannel(connector, new HttpConfiguration(null, false), endp, new HttpTransport()
{
@Override
public void execute(Runnable command)
{
command.run();
}
})
{
@Override
public void onOpen()
{
super.onOpen();
fillInterested();
}
@Override
public void onFillable()
{
}
};
_channel = new HttpChannel(_connector,new HttpConfiguration(null,false),endp,null,null)
{
@Override
public ScheduledExecutorService getScheduler()
{
return null;
}
@Override
protected void execute(Runnable task)
public void commit(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent) throws IOException
{
}
@Override
public Connector getConnector()
public void write(ByteBuffer content, boolean lastContent) throws IOException
{
return null;
}
};
@Override
public void completed()
{
}
}, input);
}
@After
@ -138,47 +104,47 @@ public class ResponseTest
{
Response response = newResponse();
assertEquals(null,response.getContentType());
assertEquals(null, response.getContentType());
response.setHeader("Content-Type","text/something");
assertEquals("text/something",response.getContentType());
response.setHeader("Content-Type", "text/something");
assertEquals("text/something", response.getContentType());
response.setContentType("foo/bar");
assertEquals("foo/bar",response.getContentType());
assertEquals("foo/bar", response.getContentType());
response.getWriter();
assertEquals("foo/bar;charset=ISO-8859-1",response.getContentType());
assertEquals("foo/bar;charset=ISO-8859-1", response.getContentType());
response.setContentType("foo2/bar2");
assertEquals("foo2/bar2;charset=ISO-8859-1",response.getContentType());
response.setHeader("name","foo");
assertEquals("foo2/bar2;charset=ISO-8859-1", response.getContentType());
response.setHeader("name", "foo");
Iterator<String> en = response.getHeaders("name").iterator();
assertEquals("foo",en.next());
assertEquals("foo", en.next());
assertFalse(en.hasNext());
response.addHeader("name","bar");
en=response.getHeaders("name").iterator();
assertEquals("foo",en.next());
assertEquals("bar",en.next());
response.addHeader("name", "bar");
en = response.getHeaders("name").iterator();
assertEquals("foo", en.next());
assertEquals("bar", en.next());
assertFalse(en.hasNext());
response.recycle();
response.setContentType("text/html");
assertEquals("text/html",response.getContentType());
assertEquals("text/html", response.getContentType());
response.getWriter();
assertEquals("text/html;charset=ISO-8859-1",response.getContentType());
assertEquals("text/html;charset=ISO-8859-1", response.getContentType());
response.setContentType("foo2/bar2");
assertEquals("foo2/bar2;charset=ISO-8859-1",response.getContentType());
assertEquals("foo2/bar2;charset=ISO-8859-1", response.getContentType());
response.recycle();
response.setContentType("text/xml;charset=ISO-8859-7");
response.getWriter();
response.setContentType("text/html;charset=UTF-8");
assertEquals("text/html;charset=ISO-8859-7",response.getContentType());
assertEquals("text/html;charset=ISO-8859-7", response.getContentType());
response.recycle();
response.setContentType("text/html;charset=US-ASCII");
response.getWriter();
assertEquals("text/html;charset=US-ASCII",response.getContentType());
assertEquals("text/html;charset=US-ASCII", response.getContentType());
response.recycle();
response.setContentType("text/json");
@ -216,7 +182,6 @@ public class ResponseTest
response.setCharacterEncoding(null);
response.setContentType("foo/bar");
assertEquals("foo/bar", response.getContentType());
}
@Test
@ -225,21 +190,21 @@ public class ResponseTest
Response response = newResponse();
ContextHandler context = new ContextHandler();
context.addLocaleEncoding(Locale.ENGLISH.toString(),"ISO-8859-1");
context.addLocaleEncoding(Locale.ITALIAN.toString(),"ISO-8859-2");
context.addLocaleEncoding(Locale.ENGLISH.toString(), "ISO-8859-1");
context.addLocaleEncoding(Locale.ITALIAN.toString(), "ISO-8859-2");
response.getHttpChannel().getRequest().setContext(context.getServletContext());
response.setLocale(java.util.Locale.ITALIAN);
assertEquals(null,response.getContentType());
assertEquals(null, response.getContentType());
response.setContentType("text/plain");
assertEquals("text/plain;charset=ISO-8859-2",response.getContentType());
assertEquals("text/plain;charset=ISO-8859-2", response.getContentType());
response.recycle();
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
response.setLocale(java.util.Locale.ITALIAN);
assertEquals("text/plain;charset=UTF-8",response.getContentType());
assertTrue(response.toString().indexOf("charset=UTF-8")>0);
assertEquals("text/plain;charset=UTF-8", response.getContentType());
assertTrue(response.toString().indexOf("charset=UTF-8") > 0);
}
@Test
@ -249,26 +214,25 @@ public class ResponseTest
response.setContentType("foo/bar");
response.setCharacterEncoding("utf-8");
assertEquals("foo/bar;charset=UTF-8",response.getContentType());
assertEquals("foo/bar;charset=UTF-8", response.getContentType());
response.getWriter();
assertEquals("foo/bar;charset=UTF-8",response.getContentType());
assertEquals("foo/bar;charset=UTF-8", response.getContentType());
response.setContentType("foo2/bar2");
assertEquals("foo2/bar2;charset=UTF-8",response.getContentType());
assertEquals("foo2/bar2;charset=UTF-8", response.getContentType());
response.setCharacterEncoding("ISO-8859-1");
assertEquals("foo2/bar2;charset=UTF-8",response.getContentType());
assertEquals("foo2/bar2;charset=UTF-8", response.getContentType());
response.recycle();
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
assertEquals("text/html;charset=UTF-8",response.getContentType());
assertEquals("text/html;charset=UTF-8", response.getContentType());
response.getWriter();
assertEquals("text/html;charset=UTF-8",response.getContentType());
assertEquals("text/html;charset=UTF-8", response.getContentType());
response.setContentType("text/xml");
assertEquals("text/xml;charset=UTF-8",response.getContentType());
assertEquals("text/xml;charset=UTF-8", response.getContentType());
response.setCharacterEncoding("ISO-8859-1");
assertEquals("text/xml;charset=UTF-8",response.getContentType());
assertEquals("text/xml;charset=UTF-8", response.getContentType());
}
@Test
@ -277,26 +241,25 @@ public class ResponseTest
Response response = newResponse();
response.setCharacterEncoding("utf-8");
response.setContentType("foo/bar");
assertEquals("foo/bar;charset=UTF-8",response.getContentType());
assertEquals("foo/bar;charset=UTF-8", response.getContentType());
response.getWriter();
assertEquals("foo/bar;charset=UTF-8",response.getContentType());
assertEquals("foo/bar;charset=UTF-8", response.getContentType());
response.setContentType("foo2/bar2");
assertEquals("foo2/bar2;charset=UTF-8",response.getContentType());
assertEquals("foo2/bar2;charset=UTF-8", response.getContentType());
response.setCharacterEncoding("ISO-8859-1");
assertEquals("foo2/bar2;charset=UTF-8",response.getContentType());
assertEquals("foo2/bar2;charset=UTF-8", response.getContentType());
response.recycle();
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
assertEquals("text/html;charset=UTF-8",response.getContentType());
assertEquals("text/html;charset=UTF-8", response.getContentType());
response.getWriter();
assertEquals("text/html;charset=UTF-8",response.getContentType());
assertEquals("text/html;charset=UTF-8", response.getContentType());
response.setContentType("text/xml");
assertEquals("text/xml;charset=UTF-8",response.getContentType());
assertEquals("text/xml;charset=UTF-8", response.getContentType());
response.setCharacterEncoding("iso-8859-1");
assertEquals("text/xml;charset=UTF-8",response.getContentType());
assertEquals("text/xml;charset=UTF-8", response.getContentType());
}
@Test
@ -306,26 +269,25 @@ public class ResponseTest
response.setCharacterEncoding("utf16");
response.setContentType("foo/bar; charset=utf-8");
assertEquals("foo/bar; charset=utf-8",response.getContentType());
assertEquals("foo/bar; charset=utf-8", response.getContentType());
response.getWriter();
assertEquals("foo/bar; charset=utf-8",response.getContentType());
assertEquals("foo/bar; charset=utf-8", response.getContentType());
response.setContentType("foo2/bar2");
assertEquals("foo2/bar2;charset=UTF-8",response.getContentType());
assertEquals("foo2/bar2;charset=UTF-8", response.getContentType());
response.setCharacterEncoding("ISO-8859-1");
assertEquals("foo2/bar2;charset=UTF-8",response.getContentType());
assertEquals("foo2/bar2;charset=UTF-8", response.getContentType());
response.recycle();
response.setCharacterEncoding("utf16");
response.setContentType("text/html; charset=utf-8");
assertEquals("text/html; charset=utf-8",response.getContentType());
assertEquals("text/html; charset=utf-8", response.getContentType());
response.getWriter();
assertEquals("text/html; charset=utf-8",response.getContentType());
assertEquals("text/html; charset=utf-8", response.getContentType());
response.setContentType("text/xml");
assertEquals("text/xml;charset=UTF-8",response.getContentType());
assertEquals("text/xml;charset=UTF-8", response.getContentType());
response.setCharacterEncoding("iso-8859-1");
assertEquals("text/xml;charset=UTF-8",response.getContentType());
assertEquals("text/xml;charset=UTF-8", response.getContentType());
}
@Test
@ -334,21 +296,21 @@ public class ResponseTest
Response response = newResponse();
response.setContentType("foo/bar; other=xyz");
assertEquals("foo/bar; other=xyz",response.getContentType());
assertEquals("foo/bar; other=xyz", response.getContentType());
response.getWriter();
assertEquals("foo/bar; other=xyz;charset=ISO-8859-1",response.getContentType());
assertEquals("foo/bar; other=xyz;charset=ISO-8859-1", response.getContentType());
response.setContentType("foo2/bar2");
assertEquals("foo2/bar2;charset=ISO-8859-1",response.getContentType());
assertEquals("foo2/bar2;charset=ISO-8859-1", response.getContentType());
response.recycle();
response.setCharacterEncoding("utf-8");
response.setContentType("text/html; other=xyz");
assertEquals("text/html; other=xyz;charset=UTF-8",response.getContentType());
assertEquals("text/html; other=xyz;charset=UTF-8", response.getContentType());
response.getWriter();
assertEquals("text/html; other=xyz;charset=UTF-8",response.getContentType());
assertEquals("text/html; other=xyz;charset=UTF-8", response.getContentType());
response.setContentType("text/xml");
assertEquals("text/xml;charset=UTF-8",response.getContentType());
assertEquals("text/xml;charset=UTF-8", response.getContentType());
}
@Test
@ -358,51 +320,50 @@ public class ResponseTest
response.setCharacterEncoding("utf16");
response.setContentType("foo/bar; charset=utf-8 other=xyz");
assertEquals("foo/bar; charset=utf-8 other=xyz",response.getContentType());
assertEquals("foo/bar; charset=utf-8 other=xyz", response.getContentType());
response.getWriter();
assertEquals("foo/bar; charset=utf-8 other=xyz",response.getContentType());
assertEquals("foo/bar; charset=utf-8 other=xyz", response.getContentType());
response.recycle();
response.setCharacterEncoding("utf16");
response.setContentType("text/html; other=xyz charset=utf-8");
assertEquals("text/html; other=xyz charset=utf-8;charset=UTF-16",response.getContentType());
assertEquals("text/html; other=xyz charset=utf-8;charset=UTF-16", response.getContentType());
response.getWriter();
assertEquals("text/html; other=xyz charset=utf-8;charset=UTF-16",response.getContentType());
assertEquals("text/html; other=xyz charset=utf-8;charset=UTF-16", response.getContentType());
response.recycle();
response.setCharacterEncoding("utf16");
response.setContentType("foo/bar; other=pq charset=utf-8 other=xyz");
assertEquals("foo/bar; other=pq charset=utf-8 other=xyz;charset=UTF-16",response.getContentType());
assertEquals("foo/bar; other=pq charset=utf-8 other=xyz;charset=UTF-16", response.getContentType());
response.getWriter();
assertEquals("foo/bar; other=pq charset=utf-8 other=xyz;charset=UTF-16",response.getContentType());
assertEquals("foo/bar; other=pq charset=utf-8 other=xyz;charset=UTF-16", response.getContentType());
}
@Test
public void testStatusCodes() throws Exception
{
Response response=newResponse();
Response response = newResponse();
response.sendError(404);
assertEquals(404, response.getStatus());
assertEquals(null, response.getReason());
response=newResponse();
response = newResponse();
response.sendError(500, "Database Error");
assertEquals(500, response.getStatus());
assertEquals("Database Error", response.getReason());
assertEquals("must-revalidate,no-cache,no-store", response.getHeader(HttpHeader.CACHE_CONTROL.asString()));
response=newResponse();
response = newResponse();
response.setStatus(200);
assertEquals(200, response.getStatus());
assertEquals(null, response.getReason());
response=newResponse();
response = newResponse();
response.sendError(406, "Super Nanny");
assertEquals(406, response.getStatus());
@ -412,73 +373,72 @@ public class ResponseTest
@Test
public void testEncodeRedirect()
throws Exception
throws Exception
{
Response response=newResponse();
Response response = newResponse();
Request request = response.getHttpChannel().getRequest();
request.setServerName("myhost");
request.setServerPort(8888);
request.setContextPath("/path");
assertEquals("http://myhost:8888/path/info;param?query=0&more=1#target",response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/path/info;param?query=0&more=1#target", response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
request.setRequestedSessionId("12345");
request.setRequestedSessionIdFromCookie(false);
HashSessionManager manager=new HashSessionManager();
HashSessionManager manager = new HashSessionManager();
manager.setSessionIdManager(new HashSessionIdManager());
request.setSessionManager(manager);
request.setSession(new TestSession(manager,"12345"));
request.setSession(new TestSession(manager, "12345"));
manager.setCheckingRemoteSessionIdEncoding(false);
assertEquals("http://myhost:8888/path/info;param;jsessionid=12345?query=0&more=1#target",response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param;jsessionid=12345?query=0&more=1#target",response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost/path/info;param;jsessionid=12345?query=0&more=1#target",response.encodeURL("http://myhost/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/other/info;param;jsessionid=12345?query=0&more=1#target",response.encodeURL("http://myhost:8888/other/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/other/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/other/info;param?query=0&more=1#target"));
manager.setCheckingRemoteSessionIdEncoding(true);
assertEquals("http://myhost:8888/path/info;param;jsessionid=12345?query=0&more=1#target",response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param?query=0&more=1#target",response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost/path/info;param?query=0&more=1#target",response.encodeURL("http://myhost/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/other/info;param?query=0&more=1#target",response.encodeURL("http://myhost:8888/other/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param?query=0&more=1#target", response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost/path/info;param?query=0&more=1#target", response.encodeURL("http://myhost/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/other/info;param?query=0&more=1#target", response.encodeURL("http://myhost:8888/other/info;param?query=0&more=1#target"));
request.setContextPath("");
assertEquals("http://myhost:8888/;jsessionid=12345",response.encodeURL("http://myhost:8888"));
assertEquals("https://myhost:8888/;jsessionid=12345",response.encodeURL("https://myhost:8888"));
assertEquals("http://myhost:8888/;jsessionid=12345", response.encodeURL("http://myhost:8888"));
assertEquals("https://myhost:8888/;jsessionid=12345", response.encodeURL("https://myhost:8888"));
assertEquals("mailto:/foo", response.encodeURL("mailto:/foo"));
assertEquals("http://myhost:8888/;jsessionid=12345",response.encodeURL("http://myhost:8888/"));
assertEquals("http://myhost:8888/;jsessionid=12345", response.encodeURL("http://myhost:8888/"));
assertEquals("http://myhost:8888/;jsessionid=12345", response.encodeURL("http://myhost:8888/;jsessionid=7777"));
assertEquals("http://myhost:8888/;param;jsessionid=12345?query=0&more=1#target",response.encodeURL("http://myhost:8888/;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param?query=0&more=1#target",response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param?query=0&more=1#target", response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
manager.setCheckingRemoteSessionIdEncoding(false);
assertEquals("/foo;jsessionid=12345", response.encodeURL("/foo"));
assertEquals("/;jsessionid=12345", response.encodeURL("/"));
assertEquals("/foo.html;jsessionid=12345#target", response.encodeURL("/foo.html#target"));
assertEquals(";jsessionid=12345", response.encodeURL(""));
}
@Test
public void testSendRedirect()
throws Exception
throws Exception
{
String[][] tests={
{"/other/location?name=value","http://myhost:8888/other/location;jsessionid=12345?name=value"},
/* {"/other/location","http://myhost:8888/other/location"},
{"/other/l%20cation","http://myhost:8888/other/l%20cation"},
{"location","http://myhost:8888/path/location"},
{"./location","http://myhost:8888/path/location"},
{"../location","http://myhost:8888/location"},
{"/other/l%20cation","http://myhost:8888/other/l%20cation"},
{"l%20cation","http://myhost:8888/path/l%20cation"},
{"./l%20cation","http://myhost:8888/path/l%20cation"},
{"../l%20cation","http://myhost:8888/l%20cation"},*/
{"../locati%C3%abn","http://myhost:8888/locati%C3%ABn"},
String[][] tests = {
{"/other/location?name=value", "http://myhost:8888/other/location;jsessionid=12345?name=value"},
{"/other/location", "http://myhost:8888/other/location"},
{"/other/l%20cation", "http://myhost:8888/other/l%20cation"},
{"location", "http://myhost:8888/path/location"},
{"./location", "http://myhost:8888/path/location"},
{"../location", "http://myhost:8888/location"},
{"/other/l%20cation", "http://myhost:8888/other/l%20cation"},
{"l%20cation", "http://myhost:8888/path/l%20cation"},
{"./l%20cation", "http://myhost:8888/path/l%20cation"},
{"../l%20cation", "http://myhost:8888/l%20cation"},
{"../locati%C3%abn", "http://myhost:8888/locati%C3%ABn"},
};
for (int i=1;i<tests.length;i++)
for (int i = 1; i < tests.length; i++)
{
Response response=newResponse();
Response response = newResponse();
Request request = response.getHttpChannel().getRequest();
request.setServerName("myhost");
@ -486,29 +446,29 @@ public class ResponseTest
request.setUri(new HttpURI("/path/info;param;jsessionid=12345?query=0&more=1#target"));
request.setContextPath("/path");
request.setRequestedSessionId("12345");
request.setRequestedSessionIdFromCookie(i>0);
HashSessionManager manager=new HashSessionManager();
request.setRequestedSessionIdFromCookie(i > 0);
HashSessionManager manager = new HashSessionManager();
manager.setSessionIdManager(new HashSessionIdManager());
request.setSessionManager(manager);
request.setSession(new TestSession(manager,"12345"));
request.setSession(new TestSession(manager, "12345"));
manager.setCheckingRemoteSessionIdEncoding(false);
response.sendRedirect(tests[i][0]);
String location = response.getHeader("Location");
assertEquals(tests[i][0],tests[i][1],location);
assertEquals(tests[i][0], tests[i][1], location);
}
}
@Test
public void testSetBufferSize () throws Exception
public void testSetBufferSizeAfterHavingWrittenContent() throws Exception
{
Response response=newResponse();
response.setBufferSize(20*1024);
Response response = newResponse();
response.setBufferSize(20 * 1024);
response.getWriter().print("hello");
try
{
response.setBufferSize(21*1024);
response.setBufferSize(21 * 1024);
fail("Expected IllegalStateException on Request.setBufferSize");
}
catch (Exception e)
@ -517,12 +477,10 @@ public class ResponseTest
}
}
// TODO Why are there 2 response instances?
@Ignore
@Test
public void testZeroContent () throws Exception
public void testZeroContent() throws Exception
{
Response response=newResponse();
Response response = newResponse();
PrintWriter writer = response.getWriter();
response.setContentLength(0);
assertTrue(!response.isCommitted());
@ -532,7 +490,6 @@ public class ResponseTest
assertTrue(response.isCommitted());
}
@Test
public void testHead() throws Exception
{
@ -552,35 +509,35 @@ public class ResponseTest
w.flush();
w.println("Doch");
w.flush();
((Request) request).setHandled(true);
((Request)request).setHandled(true);
}
});
server.start();
Socket socket = new Socket("localhost",((NetworkConnector)server.getConnectors()[0]).getLocalPort());
Socket socket = new Socket("localhost", ((NetworkConnector)server.getConnectors()[0]).getLocalPort());
socket.getOutputStream().write("HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n".getBytes());
socket.getOutputStream().write("GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n".getBytes());
socket.getOutputStream().flush();
LineNumberReader reader = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
String line = reader.readLine();
Assert.assertThat(line,Matchers.startsWith("HTTP/1.1 200 OK"));
Assert.assertThat(line, Matchers.startsWith("HTTP/1.1 200 OK"));
// look for blank line
while (line!=null && line.length()>0)
while (line != null && line.length() > 0)
line = reader.readLine();
// Read the first line of the GET
line = reader.readLine();
Assert.assertThat(line,Matchers.startsWith("HTTP/1.1 200 OK"));
Assert.assertThat(line, Matchers.startsWith("HTTP/1.1 200 OK"));
String last=null;
while (line!=null)
String last = null;
while (line != null)
{
last=line;
last = line;
line = reader.readLine();
}
assertEquals("Doch",last);
assertEquals("Doch", last);
}
finally
{
@ -593,7 +550,7 @@ public class ResponseTest
{
Response response = newResponse();
Cookie cookie=new Cookie("name","value");
Cookie cookie = new Cookie("name", "value");
cookie.setDomain("domain");
cookie.setPath("/path");
cookie.setSecure(true);
@ -603,22 +560,20 @@ public class ResponseTest
String set = response.getHttpFields().getStringField("Set-Cookie");
assertEquals("name=value;Path=/path;Domain=domain;Secure;HttpOnly;Comment=comment",set);
assertEquals("name=value;Path=/path;Domain=domain;Secure;HttpOnly;Comment=comment", set);
}
private Response newResponse()
{
_channel.getResponse().getHttpOutput().reset();
Response response = new Response(_channel,_channel.getResponse().getHttpOutput());
return response;
_channel.reset();
return new Response(_channel, _channel.getResponse().getHttpOutput());
}
private static class TestSession extends HashedSession
{
protected TestSession(HashSessionManager hashSessionManager, String id)
{
super(hashSessionManager,0L,0L,id);
super(hashSessionManager, 0L, 0L, id);
}
}
}