how to get and set parameters in Camel HTTP Proxy
apache-camel, http, java, proxy
Solution
Try following route:
from("servlet://abc")
.process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
// Camel will populate all request.parameter and request.headers,
// no need for placeholders in the "from" endpoint
String id = exchange.getIn().getHeader("id", String.class);
String name = exchange.getIn().getHeader("name", String.class);
// This URI will override http://dummyhost
exchange.getIn().setHeader(Exchange.HTTP_URI, "http://example.com");
// Add input path. This will override the original input path.
// If you need to keep the original input path, then add the id to the
// URI above instead
exchange.getIn().setHeader(Exchange.HTTP_PATH, id);
// Add query parameter such as "?name=xxx"
exchange.getIn().setHeader(Exchange.HTTP_QUERY, "name="+name);
}
.to("http://dummyhost")
If you request is `http://localhost:8080/hello/world?id=111&name=moon`, then it should be forwarded to `http://example.com/111?name=moon`.
Problem
lets say for an example i have a code: ``` from(servlet://abc?id={id}&name={name}).process(new Processor(){ @Override public void process(Exchange arg0) throws Exception { id = arg0.getIn().getHeader("id", String.class); id_type = arg0.getIn().getHeader("name",String.class); System.out.println(id); System.out.println(name); String url = "//example.com/"+id+"?name="+name; System.out.println(url); /*Thread.sleep(10000);*/ }.setHeader(Exchange.HTTP).to("http:"+url+"&bridgeEndpoint=true&throwExceptionOnFailure=false)" ``` I dont see my url there. its showing null value. how to solve this problem? I used to set this string in Exchange header but its giving me java.lang.IllegalArgumentException: