use of org.apache.commons.httpclient.server.SimpleResponse 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());
}
use of org.apache.commons.httpclient.server.SimpleResponse in project ecf by eclipse.
the class TestResponseHeaders method testDuplicateContentLength.
/**
* Tests that having a duplicate content length causes no problems.
*/
public void testDuplicateContentLength() 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("Content-Length", Integer.toString(body.length())));
response.addHeader(new Header("Content-Length", Integer.toString(body.length())));
response.setBodyString(body);
return true;
}
});
HttpMethod method = new GetMethod();
client.executeMethod(method);
assertNotNull("Response body is null.", method.getResponseBodyAsStream());
}
use of org.apache.commons.httpclient.server.SimpleResponse in project ecf by eclipse.
the class TestConnectionPersistence method testRequestConnClose.
public void testRequestConnClose() throws Exception {
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(final SimpleHttpServerConnection conn, final SimpleRequest request) throws IOException {
// Make sure the request if fully consumed
request.getBodyBytes();
SimpleResponse response = new SimpleResponse();
response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
response.setBodyString("stuff back");
conn.setKeepAlive(true);
conn.writeResponse(response);
return true;
}
});
AccessibleHttpConnectionManager connman = new AccessibleHttpConnectionManager();
this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
this.client.setHttpConnectionManager(connman);
PostMethod httppost = new PostMethod("/test/");
httppost.setRequestHeader("Connection", "close");
httppost.setRequestEntity(new StringRequestEntity("stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertFalse(connman.getConection().isOpen());
}
Aggregations