PDA

View Full Version : Migration from M5 to M6 --- FtpSource thows ClassCastException



pgangi@wsgc.com
Aug 25th, 2008, 04:33 PM
Hi,

Here is my FtpSource configuration. Which was working perfectly fine with M5.

<ftp-source id="rmsFtpServerRejectsSource"
host="ihrhbpdev1"
username="dsfsf"
password="bddfsd"
port="21"
type="file"
local-working-directory="c:\\temp\\"
remote-working-directory="/home/ftptest/"/>

But, with M6... I get the following exception


[8/25/08 13:50:30:245 PDT] 000000ef SystemOut O 2008-08-25 13:50:30,245 WARN [org.springframework.integration.channel.MessagePub lishingErrorHandler] - failure occurred in messaging task with message: null
org.springframework.integration.message.MessagingE xception: Error while polling for messages.
at org.springframework.integration.adapter.file.Abstr actDirectorySource.receive(AbstractDirectorySource .java:76)
at org.springframework.integration.message.MessageExc hangeTemplate.doReceive(MessageExchangeTemplate.ja va:212)
at org.springframework.integration.message.MessageExc hangeTemplate.doReceiveAndForward(MessageExchangeT emplate.java:231)
at org.springframework.integration.message.MessageExc hangeTemplate.receiveAndForward(MessageExchangeTem plate.java:191)
at org.springframework.integration.dispatcher.Polling Dispatcher.run(PollingDispatcher.java:127)
at org.springframework.integration.scheduling.spi.Pro viderTaskScheduler$TaskRunner.run(ProviderTaskSche duler.java:221)
at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:432)
at java.util.concurrent.FutureTask$Sync.innerRunAndRe set(FutureTask.java:295)
at java.util.concurrent.FutureTask.runAndReset(Future Task.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.access$101(ScheduledThreadPoolE xecutor.java:80)
at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.runPeriodic(ScheduledThreadPool Executor.java:157)
at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.run(ScheduledThreadPoolExecutor .java:181)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:665)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:690)
at java.lang.Thread.run(Thread.java:797)
Caused by:
java.lang.ClassCastException: java.util.ArrayList incompatible with java.io.File
at org.springframework.integration.adapter.file.Abstr actFileMessageCreator.createMessage(AbstractFileMe ssageCreator.java:1)
at org.springframework.integration.adapter.file.Abstr actDirectorySource.buildNextMessage(AbstractDirect orySource.java:107)
at org.springframework.integration.adapter.file.Abstr actDirectorySource.receive(AbstractDirectorySource .java:71)

iwein
Aug 25th, 2008, 11:26 PM
Yes, in M6 some improvements have been made to make the FtpSource less wasteful on connections. One of the things I haven't hidden is the fact that the FtpSource returns a message containing a List<File> as a payload. If you want to use the same setup as before you'll have to add a splitter between the FtpSource and the rest of your system.

If you post the exact code you're using to consume the messages we can probably find a way to make the error message a little more specific. If the MessageSource<T> is connected to MessageTarget<S> where !S.isAssignableFrom(T) we might be able to warn about that during the startup instead of letting the classcast exception happen at runtime.

pgangi@wsgc.com
Aug 26th, 2008, 11:56 AM
Hi Iwein,
Thanks for quick reply. I found the reason for ClassCastException.
The default FtpSource is using org.springframework.integration.adapter.file.FileM essageCreator as a Message creator. But, this is not compatible with the the FtpSource.java/AbstractDirectorySource.java.

I have changed the FtpSource configuration as given below with custom MessageCreator.

<bean id="ftpSource"
class="org.springframework.integration.adapter.ftp.FtpSou rce">

<constructor-arg ref="ftpFileMessageCreator"/>
<constructor-arg ref="queuedFTPClient"/>
<property name="localWorkingDirectory" value="${localTempDirectory}" />
</bean>


<bean id="ftpFileMessageCreator" class="com.......support.FtpFileMessageCreator"/>


FtpFileMessageCreator .....


public class FtpFileMessageCreator implements MessageCreator<List<File>, List<File>> {

public Message<List<File>> createMessage(List<File> object) {

return new GenericMessage<List<File>>(object);

}
}

With this configuration FtpSource works fine and i am able to ftp the files to remote server.

Thanks,
Prabhakara Gangi.

iwein
Aug 26th, 2008, 12:55 PM
Cheers, you are spot on! see issue http://jira.springframework.org/browse/INT-356.

You can still use the namespace and provide a message-creator there. I'll look into using a parametrized DefaultMessageCreator for this. You will be very welcome to comment on the issue linked

iwein
Sep 1st, 2008, 12:47 PM
I changed the defaults to work with DefaultMessageCreator<T>. That should do the trick.