我试图使用restlest从camel调用rest服务。 我需要设置一些http标头和其他特定于应用程序的标头。
这就是我这样做的方式:
from("timer:50000?repeatCount=1").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message out = exchange.getOut();
Map<String, Object> headers = new HashMap<>();
headers.put(Exchange.CONTENT_TYPE, "application/json");
headers.put("token", "value");
out.setHeaders(headers);
}
})
.to("restlet:https://host:443/api/1/customer?restletMethod=get");
但是生成的http请求根本不会应用标题。
这有什么问题?
答案 0 :(得分:0)
对于那些可能遇到同样问题的人,我终于弄明白了。 我不再使用Restlet,而是改用camel-http.4。
from("timer:50000?repeatCount=1").process(new Processor() {
@Override
public void process(Exchange arg0) throws Exception {
arg0.getOut().setBody("{ \"login\": \"blabla\", \"secret\":\"blabla\"}");
}
})
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.setHeader("CamelHttpMethod", constant("POST"))
.to("https4://test:443/rest/")