Search code examples
javaapache-camelapache-servicemixblueprint-osgicamel-http

How to set HTTP Method dynamically from blueprint(Camel-http)


I use camel-apache companent camel-http. I'm trying to set the http method from my custom header. I use blueprint

override process: exchange.getOut().setHeader("custom_http_method", "GET");

blueprint route:

    <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>

error: org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: org.apache.camel.http.common.HttpMethods with value ${header.custom_http_method} due java.lang.IllegalArgumentException: No enum constant org.apache.camel.http.common.HttpMethods.${header.custom_http_method}

as far as I understood, $ {header.custom_http_method} did not return value.

toD uri="${header.url}" - works correctly


Solution

  • Try to use simple instead of constant when setting the header CamelHttpMethod

     <route>
            <from uri="activemq://for_redmine" />
            ....
             <setHeader headerName="CamelHttpMethod">
              <simple>${header.custom_http_method}</simple> 
             </setHeader> 
            <toD uri="${header.url}"/>
        </route>