use of org.apache.commons.httpclient.server.HttpRequestHandler in project ecf by eclipse.
the class TestNoncompliant method testNoncompliantHeadStrictMode.
/**
* Test if a response to HEAD method from non-compliant server causes an
* HttpException to be thrown
*/
public void testNoncompliantHeadStrictMode() throws Exception {
final String body = "Test body";
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
ResponseWriter out = conn.getWriter();
out.println("HTTP/1.1 200 OK");
out.println("Connection: close");
out.println("Content-Length: " + body.length());
out.println();
out.print(body);
out.flush();
return true;
}
});
client.getParams().setBooleanParameter(HttpMethodParams.REJECT_HEAD_BODY, true);
HeadMethod method = new NoncompliantHeadMethod("/");
method.getParams().setIntParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 50);
try {
client.executeMethod(method);
fail("HttpException should have been thrown");
} catch (HttpException e) {
// Expected
}
method.releaseConnection();
}
use of org.apache.commons.httpclient.server.HttpRequestHandler 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