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());
}
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");
}
}
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");
}
}
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());
}
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());
}
Aggregations