use of org.apache.commons.httpclient.methods.StringRequestEntity in project ecf by eclipse.
the class TestProxy method testPostInteractiveProxyAuthHostAuthConnKeepAlive.
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive
*/
public void testPostInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER, new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
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 TestProxy method testSimplePost.
/**
* Tests POST via non-authenticating proxy
*/
public void testSimplePost() throws Exception {
this.server.setHttpService(new FeedbackService());
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 testPostProxyAuthHostAuthConnKeepAlive.
/**
* Tests POST via authenticating proxy + host auth + connection keep-alive
*/
public void testPostProxyAuthHostAuthConnKeepAlive() 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", true));
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 TestProxy method testPostInteractiveHostAuthConnKeepAlive.
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive
*/
public void testPostInteractiveHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER, new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
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 testPostProxyAuthHostInvalidAuth.
/**
* Tests POST via non-authenticating proxy + invalid host auth
*/
public void testPostProxyAuthHostInvalidAuth() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("testuser", "wrongstuff"));
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_UNAUTHORIZED, post.getStatusCode());
} finally {
post.releaseConnection();
}
}
Aggregations