Search in sources :

Example 1 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod 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 2 with PostMethod

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

the class HttpHeaderCaseTest method testHttpHeaderCase.

@Test
public void testHttpHeaderCase() throws Exception {
    HttpClient client = new HttpClient();
    HttpMethod method = new PostMethod("http://localhost:" + getPort() + "/myapp/mytest");
    method.setRequestHeader("clientHeader", "fooBAR");
    method.setRequestHeader("OTHER", "123");
    method.setRequestHeader("beer", "Carlsberg");
    client.executeMethod(method);
    assertEquals("Bye World", method.getResponseBodyAsString());
    assertEquals("aBc123", method.getResponseHeader("MyCaseHeader").getValue());
    assertEquals("456DEf", method.getResponseHeader("otherCaseHeader").getValue());
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) HttpMethod(org.apache.commons.httpclient.HttpMethod) Test(org.junit.Test)

Example 3 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod 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 4 with PostMethod

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

the class HttpRouteTest method testPostParameter.

@Test
public void testPostParameter() throws Exception {
    NameValuePair[] data = { new NameValuePair("request", "PostParameter"), new NameValuePair("others", "bloggs") };
    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod("http://localhost:" + port1 + "/parameter");
    post.setRequestBody(data);
    client.executeMethod(post);
    InputStream response = post.getResponseBodyAsStream();
    String out = context.getTypeConverter().convertTo(String.class, response);
    assertEquals("Get a wrong output ", "PostParameter", out);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) 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)

Example 5 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod 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

PostMethod (org.apache.commons.httpclient.methods.PostMethod)203 HttpClient (org.apache.commons.httpclient.HttpClient)114 Test (org.junit.Test)55 IOException (java.io.IOException)32 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)28 Part (org.apache.commons.httpclient.methods.multipart.Part)25 NameValuePair (org.apache.commons.httpclient.NameValuePair)24 FilePart (org.apache.commons.httpclient.methods.multipart.FilePart)23 Map (java.util.Map)21 GetMethod (org.apache.commons.httpclient.methods.GetMethod)21 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)21 StringPart (org.apache.commons.httpclient.methods.multipart.StringPart)21 HttpMethod (org.apache.commons.httpclient.HttpMethod)17 Header (org.apache.commons.httpclient.Header)16 Note (org.apache.zeppelin.notebook.Note)13 HttpException (org.apache.commons.httpclient.HttpException)12 File (java.io.File)11 InputStream (java.io.InputStream)11 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)11 JSONParser (org.json.simple.parser.JSONParser)11