use of org.apache.commons.httpclient.server.SimpleRequest in project ecf by eclipse.
the class TestResponseHeaders method testForceCloseConnection2.
public void testForceCloseConnection2() throws Exception {
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("Content-Type: garbage");
out.println("Connection: close");
out.println();
out.println("stuff");
out.flush();
return true;
}
});
FakeHttpMethod method = new FakeHttpMethod();
client.executeMethod(method);
assertTrue("Connection should be closed", method.shouldCloseConnection(connectionManager.getConection()));
assertFalse("Connection should NOT be closed", method.isConnectionCloseForced());
}
use of org.apache.commons.httpclient.server.SimpleRequest 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.SimpleRequest 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.SimpleRequest in project ecf by eclipse.
the class TestNoncompliant method testNoncompliantHeadWithResponseBody.
/**
* Test if a response to HEAD method from non-compliant server that contains
* an unexpected body content can be correctly redirected
*/
public void testNoncompliantHeadWithResponseBody() 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;
}
});
HeadMethod method = new HeadMethod("/");
method.getParams().setIntParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 50);
client.executeMethod(method);
assertEquals(200, method.getStatusCode());
method.releaseConnection();
}
use of org.apache.commons.httpclient.server.SimpleRequest in project ecf by eclipse.
the class TestNoncompliant method testNoncompliantPostMethodString.
/**
* Tests if client is able to recover gracefully when HTTP server or
* proxy fails to send 100 status code when expected. The client should
* resume sending the request body after a defined timeout without having
* received "continue" code.
*/
public void testNoncompliantPostMethodString() throws Exception {
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: 0");
out.println();
out.flush();
return true;
}
});
PostMethod method = new PostMethod("/");
method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
method.setRequestEntity(new StringRequestEntity("This is data to be sent in the body of an HTTP POST."));
client.executeMethod(method);
assertEquals(200, method.getStatusCode());
}
Aggregations