use of org.apache.commons.httpclient.server.SimpleHttpServerConnection in project ecf by eclipse.
the class TestResponseHeaders method testForceCloseConnection.
public void testForceCloseConnection() 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();
out.println("stuff");
out.flush();
return true;
}
});
FakeHttpMethod method = new FakeHttpMethod();
client.executeMethod(method);
assertTrue("Connection should be closed", method.shouldCloseConnection(connectionManager.getConection()));
assertTrue("Connection should be force-closed", method.isConnectionCloseForced());
}
use of org.apache.commons.httpclient.server.SimpleHttpServerConnection 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.SimpleHttpServerConnection 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.SimpleHttpServerConnection 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());
}
use of org.apache.commons.httpclient.server.SimpleHttpServerConnection in project ecf by eclipse.
the class TestNoncompliant method testMalformed204Response.
public void testMalformed204Response() throws Exception {
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
conn.setSocketTimeout(20000);
ResponseWriter out = conn.getWriter();
out.println("HTTP/1.1 204 OK");
out.println("Connection: close");
out.println("Content-Length: 100");
out.println();
out.flush();
conn.setKeepAlive(true);
return true;
}
});
GetMethod method = new GetMethod("/");
method.getParams().setSoTimeout(1000);
client.executeMethod(method);
assertEquals(HttpStatus.SC_NO_CONTENT, method.getStatusCode());
method.getResponseBody();
}
Aggregations