Search in sources :

Example 6 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project camel by apache.

the class NettyHttpMethodRestrictTest method testProperHttpMethod.

@Test
public void testProperHttpMethod() throws Exception {
    HttpClient httpClient = new HttpClient();
    PostMethod httpPost = new PostMethod(getUrl());
    StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null);
    httpPost.setRequestEntity(reqEntity);
    int status = httpClient.executeMethod(httpPost);
    assertEquals("Get a wrong response status", 200, status);
    String result = httpPost.getResponseBodyAsString();
    assertEquals("Get a wrong result", "This is a test response", result);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test)

Example 7 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project camel by apache.

the class NettyHttpMethodRestrictTest method testProperHttpMethod.

@Test
public void testProperHttpMethod() throws Exception {
    HttpClient httpClient = new HttpClient();
    PostMethod httpPost = new PostMethod(getUrl());
    StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null);
    httpPost.setRequestEntity(reqEntity);
    int status = httpClient.executeMethod(httpPost);
    assertEquals("Get a wrong response status", 200, status);
    String result = httpPost.getResponseBodyAsString();
    assertEquals("Get a wrong result", "This is a test response", result);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test)

Example 8 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project camel by apache.

the class CustomFiltersTest method sendRequestAndVerify.

private void sendRequestAndVerify(String url) throws Exception {
    HttpClient httpclient = new HttpClient();
    PostMethod httppost = new PostMethod(url);
    StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null);
    httppost.setRequestEntity(reqEntity);
    int status = httpclient.executeMethod(httppost);
    assertEquals("Get a wrong response status", 200, status);
    String result = httppost.getResponseBodyAsString();
    assertEquals("Get a wrong result", "This is a test response", result);
    assertNotNull("Did not use custom multipart filter", httppost.getResponseHeader("MyTestFilter"));
    // just make sure the KeyWord header is set
    assertEquals("Did not set the right KeyWord header", "KEY", httppost.getResponseHeader("KeyWord").getValue());
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 9 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project camel by apache.

the class HttpMethodRestrictTest method testProperHttpMethod.

@Test
public void testProperHttpMethod() throws Exception {
    HttpClient httpClient = new HttpClient();
    PostMethod httpPost = new PostMethod(getUrl());
    StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null);
    httpPost.setRequestEntity(reqEntity);
    int status = httpClient.executeMethod(httpPost);
    assertEquals("Get a wrong response status", 200, status);
    String result = httpPost.getResponseBodyAsString();
    assertEquals("Get a wrong result", "This is a test response", result);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test)

Example 10 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project camel by apache.

the class HttpRouteTest method testPostParameterInURI.

@Test
public void testPostParameterInURI() throws Exception {
    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod("http://localhost:" + port1 + "/parameter?request=PostParameter&others=bloggs");
    StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8");
    post.setRequestEntity(entity);
    client.executeMethod(post);
    InputStream response = post.getResponseBodyAsStream();
    String out = context.getTypeConverter().convertTo(String.class, response);
    assertEquals("Get a wrong output ", "PostParameter", out);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test)

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