如何从蓝图动态设置HTTP方法(Camel-http)

问题描述 投票:0回答:1

我使用camel-apache companent camel-http。我正在尝试从我的自定义标头设置http方法。我用蓝图

覆盖过程:exchange.getOut().setHeader("custom_http_method", "GET");

蓝图路线:

    <route>
        <from uri="activemq://for_redmine" />
        <setHeader headerName="Content-Type">
            <constant>application/json; charset=utf-8</constant>
        </setHeader>
        <setHeader headerName="X-Redmine-API-Key">
            <constant>beb50ea768f5d16c96030a9dbbf3cb5c4a5ccdcd</constant>
        </setHeader>
         <setHeader headerName="CamelHttpMethod">
          <constant>${header.custom_http_method}</constant> 
         </setHeader> 
        <toD uri="${header.url}"/>
    </route>

错误:org.apache.camel.TypeConversionException:从类型:java.lang.String到所需类型的类型转换期间出错:org.apache.camel.http.common.HttpMethods,其值为$ {header.custom_http_method} due java.lang .IllegalArgumentException:没有枚举常量org.apache.camel.http.common.HttpMethods。$ {header.custom_http_method}

据我所知,$ {header.custom_http_method}没有返回值。

toD uri =“$ {header.url}” - 工作正常

java apache-camel apache-servicemix blueprint-osgi camel-http
1个回答
1
投票

设置头文件CamelHttpMethod时,尝试使用simple而不是constant

 <route>
        <from uri="activemq://for_redmine" />
        ....
         <setHeader headerName="CamelHttpMethod">
          <simple>${header.custom_http_method}</simple> 
         </setHeader> 
        <toD uri="${header.url}"/>
    </route>
© www.soinside.com 2019 - 2024. All rights reserved.