[resolved] Passing Header values to a SubJob in a route

One Star

[resolved] Passing Header values to a SubJob in a route

I am trying to figure out the best way to pass header values from a Job to a SubJob within a route.
Here is how my current route looks (Screenshot attached - Hopefully):
Main Job:
Poll for a content file -->
Set header values for fileName, fileSize, DBConnection, etc -->
Call a stored proc to insert the file -->
Store the result as a header value to use later (result is a UID) -->
Move the file to a different directory -->
Create the body of my JMS message which is just the location of the file to Checksum -->
Call a JMS Queue to do a MD5Checksum on the file.
SubJob:
Receive JMS Message with File Location and Name -->
Checksum the file -->
Set the checksum result as a header value -->
Call a stored procedure to add the checksum to the file record in the DB
When I call the subjob I lose all of the Header Values that I set in the main job. I could change my JMS message to contain all of the data I need, but I would like to pass all the header values in the JMS message instead. Is there a way to do this?

Accepted Solutions
One Star

Re: [resolved] Passing Header values to a SubJob in a route

I figured out my issue. In my route I was doing a setBody to create a checksum request. When I created that new message I lost all of the headers from my original message. I changed the set body so that the headers were propagated to the new message and everything worked.
In my setBody (cProcessor) I had this:
//get fileName header
String fileName = exchange.getIn().getHeader("fileName", String.class);
System.out.println("fileName = " + fileName);
//set body to full file path with header value
exchange.getOut().setBody(context.ProjectRoot + context.WorkingDir + fileName);
and changed it to this:
//get fileName header
String fileName = exchange.getIn().getHeader("fileName", String.class);
System.out.println("fileName = " + fileName);
//set body to full file path with header value
exchange.getOut().setBody(context.ProjectRoot + context.WorkingDir + fileName);
//reset headers so you dont lose them
exchange.getOut().setHeaders(exchange.getIn().getHeaders());

All Replies
One Star

Re: [resolved] Passing Header values to a SubJob in a route

I figured out my issue. In my route I was doing a setBody to create a checksum request. When I created that new message I lost all of the headers from my original message. I changed the set body so that the headers were propagated to the new message and everything worked.
In my setBody (cProcessor) I had this:
//get fileName header
String fileName = exchange.getIn().getHeader("fileName", String.class);
System.out.println("fileName = " + fileName);
//set body to full file path with header value
exchange.getOut().setBody(context.ProjectRoot + context.WorkingDir + fileName);
and changed it to this:
//get fileName header
String fileName = exchange.getIn().getHeader("fileName", String.class);
System.out.println("fileName = " + fileName);
//set body to full file path with header value
exchange.getOut().setBody(context.ProjectRoot + context.WorkingDir + fileName);
//reset headers so you dont lose them
exchange.getOut().setHeaders(exchange.getIn().getHeaders());

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

An API-First Approach to Modernizing Applications

Learn how to use an API-First Approach to Modernize your Applications

Watch Now

Talend API Designer – Technical Overview

Take a look at this technical overview video of Talend API Designer

Watch Now

Getting Started with APIs

Find out how to get started with APIs

Read