Apache Camel File process is resulting in TypeConversion Error

scarpacci picture scarpacci · Apr 27, 2015 · Viewed 7.7k times · Source

I am using akka-camel to process files. My initial tests were working great, however when I started passing in actual xml files it is puking with type conversions.

Here is my consumer (very simple, but puking at msg.bodyAs[String]

class FileConsumer extends Consumer {
  def endpointUri = "file:/data/input/actor"

  val processor = context.actorOf(Props[Processor], "processor")

  def receive = {
    case msg: CamelMessage => {
      println("Parent...received %s" format msg)
      processor ! msg.bodyAs[String]
    }
  }
}

Error:

[ERROR] [04/27/2015 12:10:48.617] [ArdisSystem-akka.actor.default-dispatcher-5] [akka://ArdisSystem/user/$a] Error during type conversion from type: org.apache.camel.converter.stream.FileInputStreamCache to the required type: java.lang.String with value org.apache.camel.converter.stream.FileInputStreamCache@4611b35a due java.io.FileNotFoundException: /var/folders/dh/zfqvn9gn7cl6h63d3400y4zxp3xtzf/T/camel-tmp-807558/cos2920459202139947606.tmp (No such file or directory)
org.apache.camel.TypeConversionException: Error during type conversion from type: org.apache.camel.converter.stream.FileInputStreamCache to the required type: java.lang.String with value org.apache.camel.converter.stream.FileInputStreamCache@4611b35a due java.io.FileNotFoundException: /var/folders/dh/zfqvn9gn7cl6h63d3400y4zxp3xtzf/T/camel-tmp-807558/cos2920459202139947606.tmp (No such file or directory)

I am wondering if it has something to do with the actual contents of the xml. They are not big at all (roughly 70kb). I doubt I will be able to provide an actual example of the XML itself. Just baffled as to why something so small and being converted to a string is having issues. Other dummy example xml files have worked fine.

EDIT: One of the suggestions I had was to enable StreamCache, which I did. However, it still doesn't seem to be working. As Ankush commented, the error is confusing. I am not sure if it actually is a Stream issue or if it really is a conversion problem.

http://camel.apache.org/stream-caching.html

Added the below

  camel.context.setStreamCaching(true)

Answer

scarpacci picture scarpacci · Apr 30, 2015

I was finally able to figure out the problem. The issue was not bad data, but the size of the files. To account for this, you need to add addtional settings to the camel context.

http://camel.apache.org/stream-caching.html

The settings I used are below. I will need to further research if I should just turn off the streamcache, but this is a start.

camel.context.getProperties.put(CachedOutputStream.THRESHOLD, "750000");

or turn off streamcache

 camel.context.setStreamCaching(false)

Hope this helps someone else.