【问题标题】:Camel how do I add an authorisation header to a rest route?骆驼如何将授权标头添加到休息路线?
【发布时间】:2019-12-30 12:48:09
【问题描述】:

我正在尝试向我的骆驼休息路线添加授权标头。路线如下:

    restConfiguration().producerComponent("http4").host(env.getProperty("my.rest.host"));
    from(env.getProperty("in.route"))
            .to(env.getProperty("rest.endpoint.path"))

我熟悉“非骆驼”程序,例如使用 RestTemplate,您可以在其中执行 setHeader("Authorisation", "Bearer myJWT...") 之类的操作。我原以为骆驼也会有同样简单的东西。但是我的搜索到目前为止还没有成功!谁能给个提示?

谢谢:)

【问题讨论】:

    标签: java apache-camel jwt authorization token


    【解决方案1】:

    使用交换和更新标头

     from(env.getProperty("in.route")).process(new  Processor {
        public void process(Exchange exchange) throws Exception {
            //you token logic
            String token = "--token logic-------"
            exchange.getIn().setHeader("Authorization", token)
    
        }
    }).to(env.getProperty("rest.endpoint.path"))
    

    【讨论】:

    • 谢谢,顺便说一下,Bearer Token JWT 类型授权应该是:.setHeader("Authorization", constant("Bearer MyToken")) ?
    • 嗨 @JohnnyAlpha 我可以更新答案吗,请看一下,如果需要,您可以从交换中检索参数
    猜你喜欢
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 2017-05-24
    相关资源
    最近更新 更多