我正在尝试添加授权标头,但我可以这样做,但是所有端点的身份验证都相同。就我而言,我需要每个终结点使用不同的标头。我尝试在处理器中使用它,但是无法区分要设置标头的端点:
在下面的代码中,我需要https://call1/agreements和https://call2/agreements才能具有单独的身份验证标头。下面是我的路线。
public class AgreementRoute extends RouteBuilder {
public void configure(){
try
{
from("jetty://http://0.0.0.0:9191/agreement")
.log(LoggingLevel.INFO, "${body}")
.setProperty("test.body", body())
// .removeHeaders("CamelHttp*")
// .setHeader("Content-Type", constant("application/json"))
// .setHeader(Exchange.HTTP_METHOD, constant("POST"))
// .setHeader("Authorization", constant("<secret here"))
// .setBody(exchangeProperty("test.body"))
.multicast().onPrepare(new AgreementProcessor())
.to("https://call1/agreements", "https://call2/agreements");
}
catch(Exception ex)
{
ex.printStackTrace(System.out);
System.out.println(ex.getMessage());
}
}
}
这里是自定义处理器:
public class AgreementProcessor implements Processor {
public void process (Exchange exchange) throws Exception {
System.out.println("ExchagneID: " + exchange.getContext());
Map<String, Object> headers = exchange.getIn().getHeaders();
Object bodyObjectIn = exchange.getIn().getBody();
System.out.println("Exchange.DESTINATION_OVERRIDE_URL: " + exchange.getIn().getHeader(Exchange.DESTINATION_OVERRIDE_URL));
System.out.println("Exchange.RECIPIENT_LIST_ENDPOINT: " + exchange.getIn().getHeader(Exchange.RECIPIENT_LIST_ENDPOINT));
System.out.println("bodyObjectIn: " + bodyObjectIn.toString());
System.out.println("Printing getIn().headers");
for (Map.Entry<String, Object> entry : headers.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println(key + " : " + value);
}
exchange.removeProperties("Authorization");
}
}