saw303
saw303

Reputation: 9072

Writing an Camel Exchange property to the HTTP Header

I am having a Camel route with several steps configured in Spring XML. After the last step I want to set the a header entry Content-Type using a value from the Exchange properties. How can I achieve that?

<route id="servlet.direct">        
    <from uri="direct:onlinePlatformExport"/>
    <bean ref="exportService" method="doSomething"/>
    <to uri="smooks://META-INF/spring/a.xml"/>                
    <bean ref="charsetConverterService" method="convertBody"/>
    <setHeader headerName="Content-Type">
       <constant>text/xml</constant>
    </setHeader>
</route>

Upvotes: 0

Views: 5214

Answers (2)

Alexander Durnev
Alexander Durnev

Reputation: 341

You can do it as following:

<setHeader headerName="Content-Type">
    <simple>${property.myProperty}</simple>
</setHeader>

Upvotes: 0

saw303
saw303

Reputation: 9072

I found the answer. You can access the exchange object using Groovy.

<setHeader headerName="Content-Type">
   <groovy>"text/xml; charset=${exchange.properties[<your-key>]}"</groovy>
</setHeader>

Upvotes: 1

Related Questions