I wanted to try this out for myself :) So, this should work
<route>
<from uri="file:///D:/testing/file1.xml"/>
<unmarshal>
<string/>
</unmarshal>
<splitter>
<xpath>//student/name</xpath>
<convertBodyTo type="java.lang.String"/>
<to
uri="file:///D:/testing/output?expression=${in.header.org.apache.camel.splitCounter}.xml"/>
</splitter>
</route>
Note that in order to get separate files in the output directory
corresponding to the split messages, you can use the file expression
language as shown above. Otherwise, all the messages will get appended
to one file.
Claus Ibsen wrote:
Hi
You can convert it to a type the file component can use to store as a file,
such as a String.class
.convertBodyTo(String.class)
There should be a spring XML type for this.
Camel has build in types for quite a bunch of types.
http://activemq.apache.org/camel/type-converter.html
If there isn't a type converter that supports what you want then you can create
you own. To get going right away you can also insert a processor where you can
do the type convertions in plain java and replace the in body with the correct
type.
But I would like to know if we have a type convert out-of-the-box in Camel that
supports the XML type -> String. So can you try the convertBodyTo first?
BTW: Can you point to the camel documentation where you found this sample.
We should fix it, if it needs a convertBodyTo.
Med venlig hilsen
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: LavanyaKC [mailto:[EMAIL PROTECTED]
Sent: 6. oktober 2008 15:46
To: [email protected]
Subject: Sending splitter output to a file throws InvalidPayloadException
I am using the following spring xml file to split the xml content of a file
to different files.
<camelContext id="camelroute"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="file:///D:/testing/file1.xml"/>
<splitter>
<xpath>//student/name</xpath>
<to uri="file:///D:/testing/file2"/>
</splitter>
</route>
</camelContext>
Running the above spring xml throws an InvalidPayloadException.
The example given in camel documentaion in Java DSL:
from("activemq:my.queue").splitter(xpath("//foo/bar")).to("file://some/directory")
also do not work since the splitter returns a DeferredElementNSImpl type
whereas the file endpoint expects the exchange to be an InputStream. Since
it is Java DSL, there is a way to specify return type as "String.class" or
any other type in the xpath expression to fix this. But I need to use Spring
configuration for my requirement.
Thanks for any help in this regard.