Search in sources :

Example 21 with StringRequestEntity

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();
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpServiceHandler(org.apache.commons.httpclient.server.HttpServiceHandler) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpRequestHandlerChain(org.apache.commons.httpclient.server.HttpRequestHandlerChain) AuthRequestHandler(org.apache.commons.httpclient.server.AuthRequestHandler)

Example 22 with StringRequestEntity

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();
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 23 with StringRequestEntity

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();
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpServiceHandler(org.apache.commons.httpclient.server.HttpServiceHandler) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpRequestHandlerChain(org.apache.commons.httpclient.server.HttpRequestHandlerChain) AuthRequestHandler(org.apache.commons.httpclient.server.AuthRequestHandler)

Example 24 with StringRequestEntity

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();
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpServiceHandler(org.apache.commons.httpclient.server.HttpServiceHandler) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpRequestHandlerChain(org.apache.commons.httpclient.server.HttpRequestHandlerChain) AuthRequestHandler(org.apache.commons.httpclient.server.AuthRequestHandler)

Example 25 with StringRequestEntity

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();
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpServiceHandler(org.apache.commons.httpclient.server.HttpServiceHandler) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpRequestHandlerChain(org.apache.commons.httpclient.server.HttpRequestHandlerChain) AuthRequestHandler(org.apache.commons.httpclient.server.AuthRequestHandler)

Aggregations

StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)102 PostMethod (org.apache.commons.httpclient.methods.PostMethod)63 HttpClient (org.apache.commons.httpclient.HttpClient)33 Test (org.junit.Test)23 PutMethod (org.apache.commons.httpclient.methods.PutMethod)19 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)18 IOException (java.io.IOException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 AuthRequestHandler (org.apache.commons.httpclient.server.AuthRequestHandler)12 HttpRequestHandlerChain (org.apache.commons.httpclient.server.HttpRequestHandlerChain)12 HttpServiceHandler (org.apache.commons.httpclient.server.HttpServiceHandler)12 Header (org.apache.commons.httpclient.Header)9 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)9 GetMethod (org.apache.commons.httpclient.methods.GetMethod)9 InputStream (java.io.InputStream)8 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)7 StringWriter (java.io.StringWriter)6 Map (java.util.Map)6 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)6 PutMethod (org.apache.jackrabbit.webdav.client.methods.PutMethod)6