malteser
malteser

Reputation: 485

Apache Camel Seda Route still modifies my main routes body

I have the Camel route which I am working on. The route takes a CSV file from one directory in the sftp to another directory inside the sftp while carrying out a transformation to XML.

from(mySftp.getUri("/camel"))
   .choice()
       .when(body().isNull())
           .log("No Files Found")
       .otherwise()
           .process(new Processor() {
                StringBuilder sb = new StringBuilder();
                public void process(Exchange exchange) throws Exception {
                String body =  exchange.getIn().getBody(String.class).toString();
                String [] lines = body.split("\n");
                for(String line : lines) {
                      String [] fields = line.split(",");
                      //trasformation here
                }
                exchange.setProperty("generatedXml", sb.toString());
                }
}).to(mySftp.getUri("/camel/archive"))

This works perfectly fine until I call a seda route i have defined which its purpose is to send an SNS by setting the body and required headers.

The code is below.

from("seda:sendSNS")
.setBody().simple("message")
.setHeader("CamelAwsSnsSubject", simple("subject"))
.to(myInfoSns.getUri());

and this is how I am calling my seda route by using "to"

 from(mySftp.getUri("/camel"))
   .to("seda:sendSNS")
   .choice()
       .when(body().isNull())
           .log("No Files Found")
       .otherwise()
           .process(new Processor() {
                StringBuilder sb = new StringBuilder();
                public void process(Exchange exchange) throws Exception {
                String body =  exchange.getIn().getBody(String.class).toString();
                String [] lines = body.split("\n");
                for(String line : lines) {
                      String [] fields = line.split(",");
                      //trasformation here
                }
                exchange.setProperty("generatedXml", sb.toString());
                }
}).to(mySftp.getUri("/camel/archive"))

I am expecting that although I am calling the seda route and setting its body within, this should not affect my body of my main route. It seems like my XML gets generated successfully but then my main route is failing to move the file to the required destination.

The error which I am getting is

Exhausted after delivery attempt: 1 caught: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: camel/archive/file.csv

No body available of type: java.io.InputStream but has value: RemoteFile[file.csv] of type: org.apache.camel.component.file.remote.RemoteFile on: file.csv. Caused by: Error during type conversion from type: java.lang.String to the required type: java.io.InputStream with value [Body is file based: \tmp\file.csv] due \tmp\file.csv (The system cannot find the file specified). Exchange[ID-IT1289-1521106847220-0-1]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.io.InputStream with value [Body is file based: \tmp\file.csv] due \tmp\file.csv (The system cannot find the file specified)]

Any ideas what may be the cause of this? Why is my file no longer found after I call my seda route "sendSNS".

Upvotes: 0

Views: 881

Answers (1)

ernest_k
ernest_k

Reputation: 45329

Your intention is to send a copy of the message to the seda endpoint, so the integration you need is wireTap:

from(mySftp.getUri("/camel"))
  .wireTap("seda:sendSNS")
  .choice()
  //the rest...

Related documentation is here:

Wire Tap (from the EIP patterns) allows you to route messages to a separate location while they are being forwarded to the ultimate destination.

Upvotes: 3

Related Questions