camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aaron Crickenberger" <aaron.crickenber...@intalgent.com>
Subject FileConsumer-to-FileProducer bug
Date Thu, 09 Aug 2007 20:52:33 GMT
I've been playing around with Camel's FileComponent.  I started with 
camel-example-spring, and modified MyRouteBuilder to look like so:

public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
        from("file:/tmp/test/incoming/").to("file:/tmp/test/outgoing/");
    }
}

Putting a file in the "incoming" directory then results in this:

org.apache.camel.InvalidTypeException: Could not convert value: 
java.io.BufferedInputStream@ce6303 to type: java.nio.ByteBuffer but has 
value: java.io.BufferedInputStream@ce6303 of type: 
java.io.BufferedInputStream on the exchange: Exchange[FileMessage: 
/tmp/test/incoming/foo.lock]
        at 
org.apache.camel.util.ExchangeHelper.convertToMandatoryType(ExchangeHelper.java:91)
        at 
org.apache.camel.component.file.FileProducer.process(FileProducer.java:57)
        at 
org.apache.camel.component.file.FileProducer.process(FileProducer.java:50)
        at 
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:65)
        at 
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:78)
        at 
org.apache.camel.component.file.FileConsumer.pollFile(FileConsumer.java:81)
        at 
org.apache.camel.component.file.FileConsumer.pollFileOrDirectory(FileConsumer.java:51)
        at 
org.apache.camel.component.file.FileConsumer.pollFileOrDirectory(FileConsumer.java:58)
        at 
org.apache.camel.component.file.FileConsumer.poll(FileConsumer.java:45)
        at 
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:63)
        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
        at 
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:280)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:135)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:65)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:142)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:166)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
        at java.lang.Thread.run(Thread.java:613)

This extra if block in FileProducer confuses me because it seems like 
there's no InputStream to ByteBuffer conversion:

ByteBuffer payload = exchange.getIn().getBody(ByteBuffer.class);
if (payload == null) {
    InputStream in = ExchangeHelper.getMandatoryInBody(exchange, 
InputStream.class);
    payload = ExchangeHelper.convertToMandatoryType(exchange, 
ByteBuffer.class, in);
}

Adding the following File to ByteBuffer conversion to NIOConverter does 
the trick:

@Converter
public static ByteBuffer toByteBuffer(File file) throws IOException {
    byte[] buf = new byte[(int) file.length()];
    InputStream in = new BufferedInputStream(new FileInputStream(file));
    in.read(buf);
    return ByteBuffer.wrap(buf);
}

Hope this helps!

- aaron

Mime
View raw message