You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by j_pramanik_ind <ja...@gmail.com> on 2014/04/25 08:07:14 UTC

File content missing in Copied File using Camel XML DSL

Hello All,

I used following route in XML DSL. 

The requirement is to read file content , which is a line of string
delimited by '~', depending on specific pattern of a token I need to copy
the file to respective folder with full content. It copies the file but the
content is found only that token on which it checks the condition.


For example: 

File content (Full) : userid=1~pass=jayanta~oprncode=ATM~custno=4990000001~

The File that was copied contains only : oprncode=ATM  (But actually I need
to get the full content)

Following is the XML DSL ::
-------------------------------------
<route id="route1">
	 <from uri="file:E:\\bankappfiles\\received?delete=true" />
	<log message="Title Name [${body}]"/>
				
	<split stopOnException="true">                                                 
                <tokenize token="~"/>
			<choice>
				<when>
					<simple> ${in.body} == 'oprncode=ATM'</simple> 	
					<to uri="file:E:\\bankappfiles\\atm?noop=true" />									   
				</when>
				<when>
					<simple>${in.body} == 'oprncode=NEFT'</simple>						
					<to uri="file:E:\\bankappfiles\\neft?noop=true" />
				</when>
 		       </choice>
	</split>
</route>

Please advice how can I get the full content of the source file in the
copied one?
			
Thanks in advance,

Jayanta P.




--
View this message in context: http://camel.465427.n5.nabble.com/File-content-missing-in-Copied-File-using-Camel-XML-DSL-tp5750582.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File content missing in Copied File using Camel XML DSL

Posted by Charles Moulliard <ch...@gmail.com>.
I have created a unit test and the tests succeeded

import org.apache.camel.Exchange;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.LanguageTestSupport;
import org.junit.Test;

public class SimpleLanguageTest extends LanguageTestSupport {

    @Test
    public void testWithTilde() throws Exception {

exchange.getIn().setBody("1~pass=jayanta~oprncode=ATM~custno=4990000001");
        assertPredicate("${in.body} contains 'ATM'", true);
    }

    @Test
    public void testWithTildeAndEqual() throws Exception {

exchange.getIn().setBody("1~pass=jayanta~oprncode=ATM~custno=4990000001");
        assertPredicate("${in.body} contains 'oprncode=ATM'", true);
    }

    protected String getLanguageName() {
        return "simple";
    }

}


On Fri, Apr 25, 2014 at 3:25 PM, j_pramanik_ind
<ja...@gmail.com>wrote:

> Hi Claus,
>
> My Camel version is 2.10. I have set streamCache="true" in <camelContext
> ...>.
>
>  My objective is to check incoming file content for a specific parameter in
> the content string and accordingly I need to copy original source file to
> output folder.
>
> Two output folders are there : 'atm' and 'neft'
> Common receiving folder is : 'received'
>
> Previously I used <split> and <tokenize> tags but it did not work properly
> for me.
> I just removed <split> tag along with  <tokenize token="~" /> but I can not
> even print log message after checking condition with <when> .
>
> Now the XML route looks like below -
>
> <route id="route1">
>                         <from
> uri="file:E:\\bankappfiles\\received?delete=true" />
>                         <log message="Title Name [${body}]" />
>
>
>                                 <choice>
>                                         <when>
>                                                 <simple> ${in.body}
> contains 'oprncode=ATM'</simple>
>                                                 <log message="=========>>
> ATM [${in.body}]" />
>                                                 <to
> uri="file:E:\\bankappfiles\\atm?noop=true" />
>                                         </when>
>                                         <when>
>                                                 <simple>${in.body}
> contains 'oprncode=NEFT'</simple>
>                                                 <log message="=========>>
> NEFT [${in.body}]" />
>                                                  <to
> uri="file:E:\\bankappfiles\\neft?noop=true" />
>                                         </when>
>                                 </choice>
>
>                 </route>
>
>
> Please help me regarding this issue as no concrete example and documents
> not
> available for specific problem to resolve.
>
> Thanks in advance.
>
> Jayanta P.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/File-content-missing-in-Copied-File-using-Camel-XML-DSL-tp5750582p5750613.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io

Re: File content missing in Copied File using Camel XML DSL

Posted by j_pramanik_ind <ja...@gmail.com>.
Hi Claus,

My Camel version is 2.10. I have set streamCache="true" in <camelContext
...>.

 My objective is to check incoming file content for a specific parameter in
the content string and accordingly I need to copy original source file to
output folder. 

Two output folders are there : 'atm' and 'neft' 
Common receiving folder is : 'received'

Previously I used <split> and <tokenize> tags but it did not work properly
for me. 
I just removed <split> tag along with  <tokenize token="~" /> but I can not
even print log message after checking condition with <when> .

Now the XML route looks like below -

<route id="route1">
			<from uri="file:E:\\bankappfiles\\received?delete=true" />
			<log message="Title Name [${body}]" />

			
				<choice>
					<when>
						<simple> ${in.body} contains 'oprncode=ATM'</simple>
						<log message="=========>> ATM [${in.body}]" />
						<to uri="file:E:\\bankappfiles\\atm?noop=true" />
					</when>
					<when>
						<simple>${in.body} contains 'oprncode=NEFT'</simple>
						<log message="=========>> NEFT [${in.body}]" />
                                                 <to
uri="file:E:\\bankappfiles\\neft?noop=true" />
					</when>
				</choice>
			
		</route>


Please help me regarding this issue as no concrete example and documents not
available for specific problem to resolve.

Thanks in advance.

Jayanta P.




--
View this message in context: http://camel.465427.n5.nabble.com/File-content-missing-in-Copied-File-using-Camel-XML-DSL-tp5750582p5750613.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File content missing in Copied File using Camel XML DSL

Posted by Claus Ibsen <cl...@gmail.com>.
Try enable stream caching

See this FAQ
http://camel.apache.org/why-is-my-message-body-empty.html

And btw what Camel version do you use?

On Fri, Apr 25, 2014 at 9:21 AM, j_pramanik_ind
<ja...@gmail.com> wrote:
> Hi Charles,
>
> Thanks for your reply. I changed my DSL as below but it didn't work as what
> I need. The file is not copied to target folder. Can you please suggest any
> other way -
>
>
>                          *<route id="route1">
>                                 <from uri="file:E:\\bankappfiles\\received?delete=true" />
>                                 <log message="Title Name [${body}]"/>
>
>                                 <choice>
>                                         <when>
>                                                 <simple> ${body} contains 'ATM'</simple>
>                                                 <log message="For ATM :: [${body}]"/>
>                                                 <to uri="file:E:\\bankappfiles\\atm?noop=true" />
>                                         </when>
>                                         <when>
>                                                 <simple>${body} contains 'NEFT'</simple>
>                                                 <log message="For NEFT :: [${body}]"/>
>                                                 <to uri="file:E:\\bankappfiles\\neft?noop=true" />
>                                         </when>
>                                 </choice>
>
>                         </route>*
>
>
>
> Thanks.
>
> Jayanta P.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/File-content-missing-in-Copied-File-using-Camel-XML-DSL-tp5750582p5750596.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
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: File content missing in Copied File using Camel XML DSL

Posted by j_pramanik_ind <ja...@gmail.com>.
Hi Charles,

Thanks for your reply. I changed my DSL as below but it didn't work as what
I need. The file is not copied to target folder. Can you please suggest any
other way -


                         *<route id="route1">
				<from uri="file:E:\\bankappfiles\\received?delete=true" />
				<log message="Title Name [${body}]"/>
				
				<choice>
					<when>
						<simple> ${body} contains 'ATM'</simple> 
						<log message="For ATM :: [${body}]"/>	
						<to uri="file:E:\\bankappfiles\\atm?noop=true" />									   
					</when>
					<when>
						<simple>${body} contains 'NEFT'</simple>	
						<log message="For NEFT :: [${body}]"/>					
						<to uri="file:E:\\bankappfiles\\neft?noop=true" />
					</when>
				</choice>
				
			</route>*



Thanks. 

Jayanta P.




--
View this message in context: http://camel.465427.n5.nabble.com/File-content-missing-in-Copied-File-using-Camel-XML-DSL-tp5750582p5750596.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: File content missing in Copied File using Camel XML DSL

Posted by Charles Moulliard <ch...@gmail.com>.
Hi Jayanta,

As you split your file using the tilde separator before to call the content
base router EIP pattern (choice/when), only each token resulting from the
split will be saved under the destination file. Instead of splitting the
content of your file, you should just use the CBR with the expression
(${in.body}
contains 'oprncode=ATM') to route your file to the correct destination
folder.

Regards,

Charles


On Fri, Apr 25, 2014 at 8:07 AM, j_pramanik_ind
<ja...@gmail.com>wrote:

> Hello All,
>
> I used following route in XML DSL.
>
> The requirement is to read file content , which is a line of string
> delimited by '~', depending on specific pattern of a token I need to copy
> the file to respective folder with full content. It copies the file but the
> content is found only that token on which it checks the condition.
>
>
> For example:
>
> File content (Full) : userid=1~pass=jayanta~oprncode=ATM~custno=4990000001~
>
> The File that was copied contains only : oprncode=ATM  (But actually I need
> to get the full content)
>
> Following is the XML DSL ::
> -------------------------------------
> <route id="route1">
>          <from uri="file:E:\\bankappfiles\\received?delete=true" />
>         <log message="Title Name [${body}]"/>
>
>         <split stopOnException="true">
>                 <tokenize token="~"/>
>                         <choice>
>                                 <when>
>                                         <simple> ${in.body} ==
> 'oprncode=ATM'</simple>
>                                         <to
> uri="file:E:\\bankappfiles\\atm?noop=true" />
>                                 </when>
>                                 <when>
>                                         <simple>${in.body} ==
> 'oprncode=NEFT'</simple>
>                                         <to
> uri="file:E:\\bankappfiles\\neft?noop=true" />
>                                 </when>
>                        </choice>
>         </split>
> </route>
>
> Please advice how can I get the full content of the source file in the
> copied one?
>
> Thanks in advance,
>
> Jayanta P.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/File-content-missing-in-Copied-File-using-Camel-XML-DSL-tp5750582.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io