Mike H
Mike H

Reputation: 239

How do I set an exchange header to the result of a route?

I have a camel route which has a step which calls a subroute to convert the text portion of the body to PDF. Unfortunately camel-pdf does not preserve headers. Is there a way I can get the value of the subroute without losing my current exchange?

Sub Route

from("seda:generate-pdf")

// Back up the original in a header
.setHeader("original", body())

// Create the PDF
.to("pdf:create?textProcessingFactory=autoFormatting")
// UHOH! All my headers are gone :(

// Set the PDF as the header for the doc server
.setHeader("pdf", body())

// Move the indicator back to the body
.setBody(header("original")) // <-- this no longer exists

Main Route

// Snip

// Unmarshal into Java

.unmarshal().json(JsonLibrary.Gson, MyReportContainingText.class)

// Call sub-route to generate the PDF
.inOut("seda:generate-pdf")
// UHOH! All my headers are gone :(

// Snip

Upvotes: 1

Views: 6753

Answers (1)

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3191

Instead of saving stuff in the headers which can be removed when you pass from one route to another save them as exchange properties. For example:

.setProperty("pdf", body())
.setProperty("pdf", simple("${body}")

Exchange property exist as long as the exchange exist.

Upvotes: 5

Related Questions