0
votes

I have a camel route that splits and aggregates according to some ids. When an id is retrieved, a call is made to another endpoint to retrieve the project information according to this id. After retrieving the project information i had to enrich it by calling multiple enrich() methods on it. In the first enrich method i have to do some xpath processing wherein ill be able to retrieve a primaryOrgId value that i will set as a property in the exchange, dont worry about the xpath processing, i had that sorted out but my problem is when I set the property (primaryOrgId) inside the 1st enrich. The property value doesn't get persisted when the route goes to the 2nd enrich part. When I log the primaryOrgId value, the original value of "testValue" (this was set in the direct:createSomeIds route) is the one getting displayed instead of "changeTheValueHere" which was set in the 1st enrich part.

I am using Camel 2.15 based on Fuse 6.2.1.

I went to the camel site and read this part from http://camel.apache.org/content-enricher.html . I'm not sure I understood how to implement... "For that you must set the filename in the endpoint URI" .. this text was talking about the header, i'm thinking its also applicable to the properties in the exchange.

pollEnrich or enrich does not access any data from the current Exchange which means when polling it cannot use any of the existing headers you may have set on the Exchange. For example you cannot set a filename in the Exchange.FILE_NAME header and use pollEnrich to consume only that file. For that you must set the filename in the endpoint URI.

Here is my code:

from("direct:createSomeIds")
        .routeId("createSomeIds")
        .process(new IdCreatorProcessor()        
        .setProperty("primaryOrgId").constant("testValue")
    .split(xpath("/TempProjects/TempProject/Code/text()").namespaces(ns) , new IdStrategy())
        .to("direct:splitRouteById")
.end();

from("direct:splitRouteById")
        .routeId("splitRouteById")
        .to("direct:getProjectByID")
        .to("xquery:template/AllProjectToSingleProject.xq") //xquery template
        .convertBodyTo(Project.class)  
        .enrich("direct:getAdditionalInfo", new ProjectStrategy(ProjectStrategy.AggregatorType.AdditionalInfo))
        .enrich("direct:getSecondaryInfo", new ProjectStrategy(ProjectStrategy.AggregatorType.SecondaryInfo))
.end();

 from("direct:getAdditionalInfo")
//some xpath stuff here
        .setProperty("primaryOrgId").constant("changeTheValueHere")

 .end();

 from("direct:getSecondaryInfo")
        .log("Value of primaryOrgId = " + "${exchangeProperty.primaryOrgId}")

 .end();

If you can provide some code example, that would be helpful.

1

1 Answers

0
votes

If you read a bit further down you will see that it's recommended that you instead use RecipientList with an AggregationStrategy.

.recipientList("direct:getAdditionalInfo", "direct:getSecondaryInfo")
    .aggregationStrategy(new ProjectStrategy())

The setting of filename in your endpoint URI would only be applicable if you were to access some file on an FTP or some other file area.

Edit:

I now see that you need the property from the first enrichment in your second enrichment. However, if you're not modifying the message body in the first enrich then I don't actually see the need for it at all.

If you are in fact modifying the body then you can still use the RecipientList but instead you use two separate ones calling only one endpoint in each.