Reputation: 1
I am new to camel and I have written a code for splitter. I've written a context.xml which contains the routes and the beans for mapping the POJOs, and a FileSplitter.java file which contains the following code:
public class FileSplitter {
public List<Object> split(Exchange exchange) throws IOException {
List<Object> outputList;
outputList = (List<Object>) exchange.getIn().getBody(File.class);
return outputList;
}
}
I'm getting an error which goes like this. This is the console output:
java.lang.ClassCastException: java.io.File cannot be cast to java.util.List
at mainJava.FileSplitter.split(FileSplitter.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.lang.Thread.run(Unknown Source)
The error appears to be on this line:
outputList = (List<Object>) exchange.getIn().getBody(File.class);
Upvotes: 0
Views: 100
Reputation: 55550
The call getBody(File.class)
will return a java.io.File
instance, you cannot cast that to a List
then, its always a java.io.File
type.
Its like write in Java
File file = new File("foo.txt");
List list = (List) file;
Which you cannot do, and you get a type cast exception also.
Upvotes: 2