thanks Clause, I will try this and get back with you. I appreciate your
response. 

I do actually have an aggregator : and this works fine. it is the ability to
accept files on the other path to the pollEnrich EIP.   where it says
fileName=CMAS...  I need this to be dynamic due to a timestamp at the end of
the file. 

<pollEnrich strategyRef="navSeaAggregationStrategy"
uri="{{fileJoinEndpoint}}?fileName=CMAS_LPD22_MPDE1A_PG2.csv&amp;noop=true"/>

public class NavSeaAggregationStrategy implements AggregationStrategy {

        private String record1 = "";
        private String record2 = "";
        private String record = "";
        
    private Logger log =
LoggerFactory.getLogger(NavSeaAggregationStrategy.class.getName());
    
        @Override
        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

                //Theory 
        
//-------------------------------------------------------------------------------------
                // Arrived    | oldExchange  |  newExchange | Description
        
//-------------------------------------------------------------------------------------
                // A         | NULL         |  A                    | first 
message arrives for the first
group
                // B             | A                    |  B                    
| second message arrives for the first group
                // F             | NULL                 |  F                    
| first message arrives for the second group
                // C             | AB                   |  C                    
| third message arrives for the first group
        
//---------------------------------------------------------------------------------------
                log.info("NAV SEA Aggregation Strategy :: Start");

                if ( newExchange == null ) {
                        return oldExchange;
                }
                String newBody = newExchange.getIn().getBody(String.class); 
//newExchange
is the enriched source  pollEnrich
                String oldBody = oldExchange.getIn().getBody(String.class); 
//oldExchange
is the original message 
                
                StringBuilder sb1 = new StringBuilder(oldBody);  //original msg
                log.info("original or first msg: " + sb1.toString());
                
                StringBuilder sb2 = new StringBuilder(newBody);  //emrich msg 
path msg
                log.info("pollEnrich route msg: " + sb2.toString());
                
                List<String> serviceRecords = new ArrayList<String>();          
                
                //both bodies have the same number of rows
                Scanner sc1 = new Scanner(sb1.toString()).useDelimiter("\\n");  
//orig msg
1st incoming
                Scanner sc2 = new Scanner(sb2.toString()).useDelimiter("\\n");  
//msg to
enrich original with

                while ( sc1.hasNext() ) {
                        record1 = sc1.next();
                        log.info("record 1: " + record1);
                        if ( sc2.hasNext() ) {
                                record2 = sc2.next();
                                log.info("record 2:" + record2);
                                String rc2 = 
record2.substring(record2.indexOf(',', 0) ); // get past
Time Stamp
                                record2 = rc2;
                                log.info("record 2 after removed time stamp - 
rc2: " + record2);
                        }
                        record = record1.trim() + record2.trim() + 
System.lineSeparator();
                        log.info("combined record: " + record);
                        serviceRecords.add(record);
                }
                StringBuilder sbout = new StringBuilder();
                for ( Object o : serviceRecords) {
                        sbout.append(o.toString());
                }

                oldExchange.getIn().setBody( sbout.toString() );
                
                log.info("NAV SEA Aggregation Strategy :: Finish");
                
                return oldExchange;
                
                

        } //Exchange process
} //class AggregationStrategy



--
View this message in context: 
http://camel.465427.n5.nabble.com/pollEnrich-and-variable-file-names-time-stamp-tp5792827p5792880.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to