use of org.apache.commons.httpclient.HttpMethod in project camel by apache.
the class HttpPollingConsumer method doReceive.
protected Exchange doReceive(int timeout) {
Exchange exchange = endpoint.createExchange();
HttpMethod method = createMethod(exchange);
// set optional timeout in millis
if (timeout > 0) {
method.getParams().setSoTimeout(timeout);
}
try {
// execute request
int responseCode = httpClient.executeMethod(method);
Object body = HttpHelper.readResponseBodyFromInputStream(method.getResponseBodyAsStream(), exchange);
// lets store the result in the output message.
Message message = exchange.getOut();
message.setBody(body);
// lets set the headers
Header[] headers = method.getResponseHeaders();
HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
for (Header header : headers) {
String name = header.getName();
// mapping the content-type
if (name.toLowerCase().equals("content-type")) {
name = Exchange.CONTENT_TYPE;
}
String value = header.getValue();
if (strategy != null && !strategy.applyFilterToExternalHeaders(name, value, exchange)) {
message.setHeader(name, value);
}
}
message.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
message.setHeader(Exchange.HTTP_RESPONSE_TEXT, method.getStatusText());
return exchange;
} catch (IOException e) {
throw new RuntimeCamelException(e);
} finally {
method.releaseConnection();
}
}
use of org.apache.commons.httpclient.HttpMethod in project camel by apache.
the class NettyHttpHeaderMaxSizeTest method testHttpHeaderMaxSizeFail.
@Test
public void testHttpHeaderMaxSizeFail() throws Exception {
HttpClient client = new HttpClient();
HttpMethod method = new PostMethod("http://localhost:" + getPort() + "/myapp/mytest");
method.setRequestHeader("name", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
client.executeMethod(method);
assertEquals(404, method.getStatusCode());
}
use of org.apache.commons.httpclient.HttpMethod 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());
}
use of org.apache.commons.httpclient.HttpMethod 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());
}
use of org.apache.commons.httpclient.HttpMethod in project camel by apache.
the class NettyHttpHeaderCaseTest 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