use of org.apache.commons.httpclient.server.HttpService in project ecf by eclipse.
the class TestResponseHeaders method testHeaders.
// ----------------------------------------------------------- Test Methods
public void testHeaders() throws Exception {
final String body = "XXX\r\nYYY\r\nZZZ";
this.server.setHttpService(new HttpService() {
public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
response.addHeader(new Header("Connection", "close"));
response.addHeader(new Header("Content-Length", Integer.toString(body.length())));
response.addHeader(new Header("Content-Type", "text/xml; charset=utf-8"));
response.addHeader(new Header("Date", "Wed, 28 Mar 2001 05:05:04 GMT"));
response.addHeader(new Header("Server", "UserLand Frontier/7.0-WinNT"));
response.setBodyString(body);
return true;
}
});
HttpMethod method = new GetMethod();
client.executeMethod(method);
assertEquals("close", method.getResponseHeader("Connection").getValue());
assertEquals(body.length(), Integer.parseInt(method.getResponseHeader("Content-Length").getValue()));
assertEquals("text/xml; charset=utf-8", method.getResponseHeader("Content-Type").getValue());
assertEquals("Wed, 28 Mar 2001 05:05:04 GMT", method.getResponseHeader("Date").getValue());
assertEquals("UserLand Frontier/7.0-WinNT", method.getResponseHeader("Server").getValue());
}
use of org.apache.commons.httpclient.server.HttpService in project ecf by eclipse.
the class TestResponseHeaders method testInvalidContentLength1.
public void testInvalidContentLength1() throws Exception {
this.server.setHttpService(new HttpService() {
public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
response.addHeader(new Header("Content-Length", "5"));
response.addHeader(new Header("Content-Length", "stuff"));
response.setBodyString("12345");
return true;
}
});
GetMethod method = new GetMethod("/");
client.executeMethod(method);
assertEquals(5, method.getResponseContentLength());
}
use of org.apache.commons.httpclient.server.HttpService in project ecf by eclipse.
the class TestResponseHeaders method testNullHeaders.
public void testNullHeaders() throws Exception {
this.server.setHttpService(new HttpService() {
public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
response.addHeader(new Header("Connection", "close"));
response.setBodyString("XXX\r\nYYY\r\nZZZ");
return true;
}
});
HttpMethod method = new GetMethod("/");
client.executeMethod(method);
assertEquals(null, method.getResponseHeader(null));
assertEquals(null, method.getResponseHeader("bogus"));
}
use of org.apache.commons.httpclient.server.HttpService in project ecf by eclipse.
the class TestResponseHeaders method testInvalidContentLength2.
public void testInvalidContentLength2() throws Exception {
this.server.setHttpService(new HttpService() {
public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
response.addHeader(new Header("Content-Length", "stuff"));
response.addHeader(new Header("Content-Length", "5"));
response.setBodyString("12345");
return true;
}
});
GetMethod method = new GetMethod("/");
client.executeMethod(method);
assertEquals(5, method.getResponseContentLength());
}
use of org.apache.commons.httpclient.server.HttpService in project ecf by eclipse.
the class TestResponseHeaders method testDuplicateConnection.
public void testDuplicateConnection() throws Exception {
this.server.setHttpService(new HttpService() {
public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
response.addHeader(new Header("Connection", "close"));
response.addHeader(new Header("Connection", "close"));
return true;
}
});
GetMethod method = new GetMethod("/");
client.executeMethod(method);
method.getResponseBodyAsString();
assertFalse(connectionManager.getConection().isOpen());
this.server.setHttpService(new HttpService() {
public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
response.setStatusLine(HttpVersion.HTTP_1_0, 200);
response.addHeader(new Header("Connection", "keep-alive"));
response.addHeader(new Header("Connection", "keep-alive"));
response.setBodyString("aa");
return true;
}
});
method = new GetMethod("/");
client.executeMethod(method);
method.getResponseBodyAsString();
assertTrue(connectionManager.getConection().isOpen());
}
Aggregations