You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by skumar <sk...@stonewain.com> on 2013/07/28 15:17:32 UTC

combining the existing content with a file having dynamic uri then moving the file

Hi All,
      I am a camel newbie and searching for more than 3 days but couldn't
get an appropiate answer.
Actually I have to process lot of files one by one using the same route
based on some criteria.I get the criteria value and the uri of the file from
the database,spitted it using a	splitter and then tried to aggregate the
existing content(in the message header) with the new content which i will
receive from the file://uri.
Seems pollEnrichment couldn't work because it doesn't support dynamic uri.I
am fetching the file path from .properties file and database.So I am stuck
here how to achieve both combining the content and use dynamic uri for file
processing.Note I dont want to use,java.io.file to read the file.Can we use
a consumer template for this but I am anxious how to combine the content
from old and new exchanges.Here is part of my code:
<from uri="timer://foo?fixedRate=true&amp;period=5000"/>
		<to uri="bean:locatesSql?method=getFileFormatDetails" />
			<split>
				<choice><when><simple>${body.streamName} ==
'GenericSupplyBeanIO'</simple>
					<pollEnrich uri=&quot;file:{{inbound_home}}/pgsl?fileName=&quot;here I
want a dynamic uri content in body.FileDir&quot; /> 
I am stuck and will highly appreciate any help.



--
View this message in context: http://camel.465427.n5.nabble.com/combining-the-existing-content-with-a-file-having-dynamic-uri-then-moving-the-file-tp5736365.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: combining the existing content with a file having dynamic uri then moving the file

Posted by skumar <sk...@stonewain.com>.
Hi Claus,
          I am using consumer template to for the same work in the thread as
I want a pattern based reading of file and then move the file after renaming
it with current date some thing like :
file:{{inbound_home}}/bony?include=.*_BNYM_.*txt&amp;move={{data_home}}/${file:onlyname.noext}_${date:now:yyyyMMdd}.TXT&amp;moveFailed={{data_home}}/errorfile&amp;doneFileName=LOADAVAILBNYM"

My Route is like this:

<from uri="timer://foo?fixedRate=true&amp;period=500000" />
                <to uri="bean:locatesSql?method=getFileFormatDetails" />
                <split>
                    <simple>${in.header.accounts}</simple>
                       <setHeader
headerName="clientFileDir"><simple>${in.body.inFileDir}</simple></setHeader> 
                    <choice> <when>                          
                                <to id="result"
uri="bean:locatesConsumer?method=consumeBnymFile" />
                                    <unmarshal ref="bnymAvailabilityBeanIo"
/>
                                    <process ref="bnymAvailabilityProcessor"
/>
                                <to
uri="bean:locatesSql?method=processLocatesFile" />
                                <to
uri="bean:jobLogger?method=logJobCompleted" />
                        </when> </choice></split>

Here inside the camel Header(in.header.accounts) I am keeping list of
account details its type is:
com.oceanview.eai.model.Account

After this on a separate class file named Consumer template I have:

   @Autowired
    private ConsumerTemplate consumer;
    @Autowired
    private ProducerTemplate producer;
public void consumeBnymFile(Exchange arg) throws Exception {    	
    	String fileUri =
"file:{{inbound_home}}/var/tmp/locates/test/bony?fileName=TEST_BNYM.txt";
    	consumer.start(); 

    	while(true) {
    		Exchange  ex = consumer.receive(fileUri, 2000); 
            if(ex != null) { 
                    log.info("Fetching file: " +
ex.getIn().getHeader("CamelFileName")); 
                   // producer.send(fileUri, ex);
                    arg.getIn().setHeader("CamelFileName",
ex.getIn().getHeader("CamelFileName"));
                    arg.getIn().setBody(ex.getIn().getBody());
            } 
         
        }
I have two problems:
1)In first iteration it runs fine but in second and subsequest I am
receiving this error:
Message: com.oceanview.eai.model.Account@338bd37a. Caused by:
 No type converter available to convert from type:
com.oceanview.eai.model.Account to the required type: 
 java.io.InputStream with value com.oceanview.eai.model.Account@338bd37a. 
 Exchange[Message: com.oceanview.eai.model.Account@338bd37a]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - 
 No type converter available to convert from type:
com.oceanview.eai.model.Account to the required type: 
 java.io.InputStream with value com.oceanview.eai.model.Account@338bd37a]

2.I am not being able to use include=.*_BNYM_.*tx or move or move failed in
String fileUri =
"file:{{inbound_home}}/bony?include=.*_BNYM_.*txt&amp;move={{data_home}}/${file:onlyname.noext}_${date:now:yyyyMMdd}.TXT&amp;moveFailed={{data_home}}/errorfile&amp;


Please help...

Thanks,
Sanjeev









 



--
View this message in context: http://camel.465427.n5.nabble.com/combining-the-existing-content-with-a-file-having-dynamic-uri-then-moving-the-file-tp5736365p5736797.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: combining the existing content with a file having dynamic uri then moving the file

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Jul 28, 2013 at 8:18 PM, skumar <sk...@stonewain.com> wrote:
> Thanks,Claus.It is working fine.But I have still one question.Can I use it
> for reading the pattern based file and moving the file to a archive
> directory.Something like this:
>
>  <from uri=&quot;file:{{inbound_home}}/pgsl?&lt;b>include=.*.*xls*&amp;
> move={{data_home}}/${file:onlyname.noext}_${date:now:yyyyMMdd}.XLS&amp;
> moveFailed={{data_home}}/errorfile&amp;doneFileName=LOADGENERICSUPPLY" />
>

No you would need to move the file yourself, if you use the
<transform><simple> code I showed.
Though you can use onException to handle the failed situation.

BTW there is a JIRA ticket about allowing dynamic <enrich> and
<pollEnrich> so in a future Camel release this would be easier.



>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/combining-the-existing-content-with-a-file-having-dynamic-uri-then-moving-the-file-tp5736365p5736374.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: combining the existing content with a file having dynamic uri then moving the file

Posted by skumar <sk...@stonewain.com>.
Thanks,Claus.It is working fine.But I have still one question.Can I use it
for reading the pattern based file and moving the file to a archive
directory.Something like this:

 <from uri=&quot;file:{{inbound_home}}/pgsl?&lt;b>include=.*.*xls*&amp;
move={{data_home}}/${file:onlyname.noext}_${date:now:yyyyMMdd}.XLS&amp;
moveFailed={{data_home}}/errorfile&amp;doneFileName=LOADGENERICSUPPLY" />



--
View this message in context: http://camel.465427.n5.nabble.com/combining-the-existing-content-with-a-file-having-dynamic-uri-then-moving-the-file-tp5736365p5736374.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: combining the existing content with a file having dynamic uri then moving the file

Posted by Claus Ibsen <cl...@gmail.com>.
If you just want to read a file in pollEnrich then you can transform
the message to a java.io.File and specify the file name dynamically
using the simple/file language.


<split>
  ...
  <transform>
    <simple resultType="java.io.File">file:{{inbound_home}}/pgsl/${body.FileDir}</simple>
  </transform>

</split>


On Sun, Jul 28, 2013 at 3:17 PM, skumar <sk...@stonewain.com> wrote:
> Hi All,
>       I am a camel newbie and searching for more than 3 days but couldn't
> get an appropiate answer.
> Actually I have to process lot of files one by one using the same route
> based on some criteria.I get the criteria value and the uri of the file from
> the database,spitted it using a splitter and then tried to aggregate the
> existing content(in the message header) with the new content which i will
> receive from the file://uri.
> Seems pollEnrichment couldn't work because it doesn't support dynamic uri.I
> am fetching the file path from .properties file and database.So I am stuck
> here how to achieve both combining the content and use dynamic uri for file
> processing.Note I dont want to use,java.io.file to read the file.Can we use
> a consumer template for this but I am anxious how to combine the content
> from old and new exchanges.Here is part of my code:
> <from uri="timer://foo?fixedRate=true&amp;period=5000"/>
>                 <to uri="bean:locatesSql?method=getFileFormatDetails" />
>                         <split>
>                                 <choice><when><simple>${body.streamName} ==
> 'GenericSupplyBeanIO'</simple>
>                                         <pollEnrich uri=&quot;file:{{inbound_home}}/pgsl?fileName=&quot;here I
> want a dynamic uri content in body.FileDir&quot; />
> I am stuck and will highly appreciate any help.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/combining-the-existing-content-with-a-file-having-dynamic-uri-then-moving-the-file-tp5736365.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen