If you are using POST
to send data you can configure the
charset
using the Exchange
property:
exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
This sample polls the Google homepage every 10 seconds and write the page to the file
message.html
:
from("timer://foo?fixedRate=true&delay=0&period=10000") .to("http4://www.google.com") .setHeader(FileComponent.HEADER_FILE_NAME, "message.html") .to("file:target/google");
In this sample we have the complete URI endpoint that is just what you would have
typed in a web browser. Multiple URI parameters can of course be set using the
&
character as separator, just as you would in the web browser. Camel
does no tricks here.
// we query for Camel at the Google page template.sendBody("http4://www.google.com/search?q=Camel", null);
Map headers = new HashMap(); headers.put(Exchange.HTTP_QUERY, "q=Camel&lr=lang_en"); // we query for Camel and English language at Google template.sendBody("http4://www.google.com/search", null, headers);
In the header value above notice that it should not be prefixed with ?
and you can separate parameters as usual
with the &
char.
You can get the HTTP response code from the HTTP4 component by getting the value from
the Out message header with Exchange.HTTP_RESPONSE_CODE
.
Exchange exchange = template.send("http4://www.google.com/search", new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setHeader( Exchange.HTTP_QUERY, constant("hl=en&q=activemq")); } }); Message out = exchange.getOut(); int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);