Search in sources :

Example 6 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project camel by apache.

the class HttpProxyTest method testNoHttpProxyConfigured.

@Test
public void testNoHttpProxyConfigured() throws Exception {
    HttpEndpoint http = context.getEndpoint("http://www.google.com", HttpEndpoint.class);
    HttpClient client = http.createHttpClient();
    assertNull("No proxy configured yet", client.getHostConfiguration().getProxyHost());
    assertEquals("No proxy configured yet", -1, client.getHostConfiguration().getProxyPort());
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test)

Example 7 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project camel by apache.

the class HttpProxyTest method testHttpProxyComponentConfigured.

@Test
public void testHttpProxyComponentConfigured() throws Exception {
    HttpConfiguration config = new HttpConfiguration();
    config.setProxyHost("myotherproxy");
    config.setProxyPort(2345);
    HttpComponent comp = context.getComponent("http", HttpComponent.class);
    comp.setHttpConfiguration(config);
    HttpEndpoint http = context.getEndpoint("http://www.google.com", HttpEndpoint.class);
    context.getProperties().put("http.proxyHost", "myproxy");
    context.getProperties().put("http.proxyPort", "1234");
    try {
        HttpClient client = http.createHttpClient();
        assertEquals("myotherproxy", client.getHostConfiguration().getProxyHost());
        assertEquals(2345, client.getHostConfiguration().getProxyPort());
    } finally {
        context.getProperties().remove("http.proxyHost");
        context.getProperties().remove("http.proxyPort");
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) HttpConfiguration(org.apache.camel.http.common.HttpConfiguration) Test(org.junit.Test)

Example 8 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project camel by apache.

the class HttpProxyTest method testHttpProxyConfigured.

@Test
public void testHttpProxyConfigured() throws Exception {
    HttpEndpoint http = context.getEndpoint("http://www.google.com", HttpEndpoint.class);
    context.getProperties().put("http.proxyHost", "myproxy");
    context.getProperties().put("http.proxyPort", "1234");
    try {
        HttpClient client = http.createHttpClient();
        assertEquals("myproxy", client.getHostConfiguration().getProxyHost());
        assertEquals(1234, client.getHostConfiguration().getProxyPort());
    } finally {
        context.getProperties().remove("http.proxyHost");
        context.getProperties().remove("http.proxyPort");
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test)

Example 9 with HttpClient

use of org.apache.commons.httpclient.HttpClient 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 10 with HttpClient

use of org.apache.commons.httpclient.HttpClient 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)

Aggregations

HttpClient (org.apache.commons.httpclient.HttpClient)389 GetMethod (org.apache.commons.httpclient.methods.GetMethod)217 PostMethod (org.apache.commons.httpclient.methods.PostMethod)115 HttpMethod (org.apache.commons.httpclient.HttpMethod)98 Test (org.junit.Test)86 IOException (java.io.IOException)79 InputStream (java.io.InputStream)65 JSONParser (org.json.simple.parser.JSONParser)44 HttpException (org.apache.commons.httpclient.HttpException)43 JSONObject (org.json.simple.JSONObject)40 Map (java.util.Map)32 ArrayList (java.util.ArrayList)27 HttpState (org.apache.commons.httpclient.HttpState)25 ZMailbox (com.zimbra.client.ZMailbox)23 Account (com.zimbra.cs.account.Account)22 HashMap (java.util.HashMap)22 ServiceException (com.zimbra.common.service.ServiceException)21 JSONArray (org.json.simple.JSONArray)21 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)20 Element (org.w3c.dom.Element)20