Search in sources :

Example 21 with PostMethod

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

the class NettyHttpHeaderMaxSizeTest method testHttpHeaderMaxSizeOk.

@Test
public void testHttpHeaderMaxSizeOk() throws Exception {
    HttpClient client = new HttpClient();
    HttpMethod method = new PostMethod("http://localhost:" + getPort() + "/myapp/mytest");
    method.setRequestHeader("name", "you");
    client.executeMethod(method);
    assertEquals(200, method.getStatusCode());
    assertEquals("Bye World", method.getResponseBodyAsString());
}
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 22 with PostMethod

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

the class NettyHttpMapHeadersFalseTest 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 23 with PostMethod

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

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

the class AddBreadcrumbHttpHeaderTestInterceptor method handleRequest.

@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
    // no extra op
    TransportContext context = TransportContextHolder.getTransportContext();
    CommonsHttpConnection connection = (CommonsHttpConnection) context.getConnection();
    PostMethod postMethod = connection.getPostMethod();
    postMethod.addRequestHeader("breadcrumbId", "ID-Ralfs-MacBook-Pro-local-50523-1423553069254-0-5");
    return true;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) TransportContext(org.springframework.ws.transport.context.TransportContext) CommonsHttpConnection(org.springframework.ws.transport.http.CommonsHttpConnection)

Example 25 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project h2o-2 by h2oai.

the class CloudConnect method launch.

/**
   * Upload jars to an existing cloud and launches a custom job. Uses the Web API.
   */
public static void launch(String job, String host, File... jars) throws Exception {
    HttpClient client = new HttpClient();
    String args = "job_class=" + job + "&jars=";
    for (File f : jars) {
        PostMethod post = new PostMethod("http://" + host + "/Upload.json?key=" + f.getName());
        Part[] parts = { new FilePart(f.getName(), f) };
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
        if (200 != client.executeMethod(post))
            throw new RuntimeException("Request failed: " + post.getStatusLine());
        args += f.getName() + ",";
        post.releaseConnection();
    }
    String href = new LaunchJar().href();
    GetMethod get = new GetMethod("http://" + host + href + ".json?" + args);
    if (200 != client.executeMethod(get))
        throw new RuntimeException("Request failed: " + get.getStatusLine());
    get.releaseConnection();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) LaunchJar(water.deploy.LaunchJar)

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