use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestProxy method testPostAuthProxy.
/**
* Tests POST via authenticating proxy
*/
public void testPostAuthProxy() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
this.server.setHttpService(new FeedbackService());
this.proxy.requireAuthentication(creds, "test", true);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff"));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestProxy method testPostProxyAuthHostAuthConnClose.
/**
* Tests POST via authenticating proxy + host auth + connection close
*/
public void testPostProxyAuthHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getState().setCredentials(AuthScope.ANY, creds);
this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff"));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestRedirects method testPostRedirect.
public void testPostRedirect() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(new BasicRedirectService(host, port));
PostMethod httppost = new PostMethod("/oldlocation/");
httppost.setRequestEntity(new StringRequestEntity("stuff"));
try {
this.client.executeMethod(httppost);
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httppost.getStatusCode());
assertEquals("/oldlocation/", httppost.getPath());
assertEquals(new URI("/oldlocation/", false), httppost.getURI());
} finally {
httppost.releaseConnection();
}
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestConnectionPersistence method testConnKeepAlive.
public void testConnKeepAlive() throws Exception {
this.server.setHttpService(new EchoService());
AccessibleHttpConnectionManager connman = new AccessibleHttpConnectionManager();
this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
this.client.setHttpConnectionManager(connman);
PostMethod httppost = new PostMethod("/test/");
httppost.setRequestEntity(new StringRequestEntity("stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertFalse(connman.getConection().isOpen());
httppost = new PostMethod("/test/");
httppost.setRequestHeader("Connection", "keep-alive");
httppost.setRequestEntity(new StringRequestEntity("more stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertTrue(connman.getConection().isOpen());
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestConnectionPersistence method testConnPersisenceHTTP10.
// ----------------------------------------------------------- Test Methods
public void testConnPersisenceHTTP10() throws Exception {
this.server.setHttpService(new EchoService());
AccessibleHttpConnectionManager connman = new AccessibleHttpConnectionManager();
this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
this.client.setHttpConnectionManager(connman);
PostMethod httppost = new PostMethod("/test/");
httppost.setRequestEntity(new StringRequestEntity("stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertFalse(connman.getConection().isOpen());
httppost = new PostMethod("/test/");
httppost.setRequestEntity(new StringRequestEntity("more stuff"));
try {
this.client.executeMethod(httppost);
} finally {
httppost.releaseConnection();
}
assertFalse(connman.getConection().isOpen());
}
Aggregations