Announcement Announcement Module
Collapse
No announcement yet.
file:outbound-channel-adapter files are not copying to the output folder Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • file:outbound-channel-adapter files are not copying to the output folder

    Hi,
    written code for file handling.It will just copy from input folder files to output folder files.I had done this with Synchronously.But If i do same thing with @Async notation according to annotation rules if you want to apply @Async notation to a method with Return type You need to cast it to Future.
    @Async
    Future<String> returnSomething(int i) {
    // this will be executed asynchronously
    }

    But here my return type is file.
    public Future<File> handleFile(File input)
    {
    return new AsyncResult<File>;
    }
    My spring configuration file is

    <task:annotation-driven/>
    <context:component-scan base-package="">
    <file:inbound-channel-adapter id="filesIn" directory="${filefeed.source}">
    <integrationoller>
    <integration:interval-trigger interval="1000"/>
    </integrationoller>
    </file:inbound-channel-adapter>

    <integration:service-activator input-channel="filesIn" output-channel="filesOut">
    <bean id="id" class="class name" />
    </integration:service-activator>
    <file:outbound-channel-adapter id="filesOut" directory="${filefeed.dest}" delete-source-files="true"/>

    while executing my logic i am getting below exception

    Caused by: java.lang.IllegalArgumentException: unsupported Message payload type [java.util.concurrent.FutureTask]
    at org.springframework.integration.file.FileWritingMe ssageHandler.handleRequestMessage(FileWritingMessa geHandler.java:174)

    I know why this message is coming my file:outbound-channel-adapter wilk take only files not futuretask.Is there any way from conversion of Future<File> type into File in spring configuration file itself and tell me the solution how i can resolve this?

    Please help me regarding this problem
    Last edited by cthopuri; May 11th, 2010, 06:21 AM.

  • #2
    Before your <file:outbound-channel-adapter/> add a transformer along these lines.
    Code:
    <transformer method="get" class="FutureTransformer" ... />
    The implementation of FutureTransformer is left as an exercise to the reader.

    Comment


    • #3
      First of all thanks Iwein for ur reply.Nice and very good suggestion from ur end.I tried with transformer also.
      here i am giving my spring configuration file after putting transformer.

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:integration="http://www.springframework.org/schema/integration"
      xmlns:file="http://www.springframework.org/schema/integration/file"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:task="http://www.springframework.org/schema/task"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schem...-beans-3.0.xsd
      http://www.springframework.org/schema/task
      http://www.springframework.org/schem...g-task-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schem...ontext-3.0.xsd
      http://www.springframework.org/schema/integration
      http://www.springframework.org/schem...ration-1.0.xsd
      http://www.springframework.org/schema/integration/file
      http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd">

      <bean class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
      <property name="locations">
      <value>lsor_database.properties</value>
      </property>
      </bean>
      <context:annotation-config />
      <task:annotation-driven/>
      <context:component-scan base-package="com/wellsfargo/lbx/lsor/fileservice"/>
      <file:inbound-channel-adapter id="filesIn" directory="${filefeed.source}">
      <integrationoller>
      <integration:interval-trigger interval="1000"/>
      </integrationoller>
      </file:inbound-channel-adapter>

      <integration:service-activator input-channel="filesIn" output-channel="Future">
      <bean id="LsorProfileFileFeedHandler" class="com.wellsfargo.lbx.lsor.fileservice.LsorPro fileFileFeedHandler" />
      </integration:service-activator>

      <integration:transformer input-channel="Future" method="transform"
      output-channel="filesOut">
      <bean id="testTransformer" class="com.wellsfargo.lbx.lsor.fileservice.TestTra nsformer"/>
      </integration:transformer>

      <file:outbound-channel-adapter id="filesOut" directory="${filefeed.dest}" delete-source-files="true"/>

      </beans>



      and my two implemeted beans are


      public class LsorProfileFileFeedHandler
      {

      public LsorProfileFileFeedHandler()
      {
      }

      public String handleString(String input)
      {
      System.out.println((new StringBuilder("Copying text: ")).append(input).toString());
      return input.toUpperCase();
      }
      @Async
      public Future<File> handleFile(File input)
      {
      System.out.println((new StringBuilder("Copying file: ")).append(input.getAbsolutePath()).toString() );
      LsorProfileFileFeedService service = new LsorProfileFileFeedService();

      return new AsyncResult<File>(service.processProfile(input));
      }


      and the transformer bean is

      @Transformer

      public
      File transform(Future<File> future){

      File file =
      null;
      try {
      file = future.get();
      }
      catch (InterruptedException e) {
      // TODO Auto-generated catch block

      e.printStackTrace();
      }
      catch (ExecutionException e) {
      // TODO Auto-generated catch block

      [LEFT]e.printStackTrace();
      }
      return[SIZE=2] file;
      }

      here i am giving my exact problem


      from the first bean my method is invoking asynchronously.so after that according to the annotation concept methods with return type need to convert into future task.That's why i am using future return type in my first bean.So for converting future into my return type i am using transformer.In transformer directly i am getting that file and giving it to the outbound-channel adapter.In my first bean asyn is working and after passing that input to transformer again my method is working as a sync task.Here i need to implement async behaviour.My aim is aynchronusly reading of the files from input direactory and putting them in output dirctory.Any feasible solution for this problem?Please let me know if any solution is there from spring prospective.

      I can read the files asynchronously but i can't put them into output directory asynchronously.
      Last edited by cthopuri; May 20th, 2010, 01:42 AM.

      Comment

      Working...
      X