Java Outbound Adaptor processing











up vote
0
down vote

favorite












I have created an application that adds inbound adaptors at run time for ftp servers and registers them for removing at a certain stage if needed, this app will pull a csv file from ftp server(s) and place it in my local in a folder having the name of the ftp server, so every server I add will have a separate local folder created and the csv file is saved in it, now this is accomplished smoothly, the second part is I want to change the format of that file and then send it back to the respective server, so basically I need to use outbound adaptor, in this case I would need to create outbound adaptors at run time at the same time when creating inbound adaptor or adding a server, this should be done through controller same as the inbound, I searched for possible solutions and tried a one that is below but did not work or did not perform any sending of files to destination, any solution on how I can accomplish this?
In the configuration class I added the below:



public IntegrationFlow ftpOutboundFlow(Branch myBranch){

return IntegrationFlows.from(OUTBOUND_CHANNEL)
.handle(Ftp.outboundAdapter(createNewFtpSessionFactory(myBranch), FileExistsMode.FAIL)
.useTemporaryFileName(true)
.remoteFileSeparator("/")
//.fileNameExpression("BEY/FEFOexportBEY.csv")
.remoteDirectory(myBranch.getFolderPath()))
.get();

}

@MessagingGateway
public interface MyGateway {

@Gateway(requestChannel = OUTBOUND_CHANNEL)
void sendToFtp(File file);

}

@Bean
public IntegrationFlow ftpOutboundChannel() {

return IntegrationFlows.from(OUTBOUND_CHANNEL)
.transform(p -> {
LOG.info("Outbound intermediate Channel, message=rename file:" + p);
return p;
})
.channel(new NullChannel())
.get();
}


And in the Controller class



@RequestMapping("/branch/showbranch/{id}")
public String getBranch (@PathVariable String id, Model model){
model.addAttribute("branch", branchService.getById(Long.valueOf(id)));
addFlowftp(id);
addFlowftpOutbound(id);
return "/branch/showbranch";

}

private void addFlowftpOutbound(String name) {
branch = branchService.getById(Long.valueOf(name));
System.out.println(branch.getBranchCode());
myGateway.sendToFtp(new File("BEY/FEFOexportBEY.csv"));
IntegrationFlow flow = ftIntegration.ftpOutboundFlow(branch);
//this.flowContext.registration(flow).id(name).register();
}


When I run the app and add a new branch with name BEY for example it does not send the file to the FTP server, not sure if I'm doing anything wrong here or if I have the methods written incorrectly.



Here is what I get in the consol



BEY
2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : Adding {transformer} as a subscriber to the '94.channel#0' channel
2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.integration.channel.DirectChannel : Channel 'application.94.channel#0' has 1 subscriber(s).
2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : started 94.org.springframework.integration.config.ConsumerEndpointFactoryBean#0
2018-11-19 15:07:11.631 INFO 7212 --- [nio-8081-exec-6] o.s.i.e.SourcePollingChannelAdapter : started stockInboundPoller
BEY
2018-11-19 15:07:11.640 INFO 7212 --- [nio-8081-exec-6] f.s.s.configuration.FTIntegration : Outbound intermediate Channel, message=rename file:BEYFEFOexportBEY.csv
2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockInboundFlowFromAFT, message=incoming file: BEYFEFOexportBEY.csv
2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockIntermediateStageChannel, message=rename file: BEYFEFOexportBEY.csv









share|improve this question




























    up vote
    0
    down vote

    favorite












    I have created an application that adds inbound adaptors at run time for ftp servers and registers them for removing at a certain stage if needed, this app will pull a csv file from ftp server(s) and place it in my local in a folder having the name of the ftp server, so every server I add will have a separate local folder created and the csv file is saved in it, now this is accomplished smoothly, the second part is I want to change the format of that file and then send it back to the respective server, so basically I need to use outbound adaptor, in this case I would need to create outbound adaptors at run time at the same time when creating inbound adaptor or adding a server, this should be done through controller same as the inbound, I searched for possible solutions and tried a one that is below but did not work or did not perform any sending of files to destination, any solution on how I can accomplish this?
    In the configuration class I added the below:



    public IntegrationFlow ftpOutboundFlow(Branch myBranch){

    return IntegrationFlows.from(OUTBOUND_CHANNEL)
    .handle(Ftp.outboundAdapter(createNewFtpSessionFactory(myBranch), FileExistsMode.FAIL)
    .useTemporaryFileName(true)
    .remoteFileSeparator("/")
    //.fileNameExpression("BEY/FEFOexportBEY.csv")
    .remoteDirectory(myBranch.getFolderPath()))
    .get();

    }

    @MessagingGateway
    public interface MyGateway {

    @Gateway(requestChannel = OUTBOUND_CHANNEL)
    void sendToFtp(File file);

    }

    @Bean
    public IntegrationFlow ftpOutboundChannel() {

    return IntegrationFlows.from(OUTBOUND_CHANNEL)
    .transform(p -> {
    LOG.info("Outbound intermediate Channel, message=rename file:" + p);
    return p;
    })
    .channel(new NullChannel())
    .get();
    }


    And in the Controller class



    @RequestMapping("/branch/showbranch/{id}")
    public String getBranch (@PathVariable String id, Model model){
    model.addAttribute("branch", branchService.getById(Long.valueOf(id)));
    addFlowftp(id);
    addFlowftpOutbound(id);
    return "/branch/showbranch";

    }

    private void addFlowftpOutbound(String name) {
    branch = branchService.getById(Long.valueOf(name));
    System.out.println(branch.getBranchCode());
    myGateway.sendToFtp(new File("BEY/FEFOexportBEY.csv"));
    IntegrationFlow flow = ftIntegration.ftpOutboundFlow(branch);
    //this.flowContext.registration(flow).id(name).register();
    }


    When I run the app and add a new branch with name BEY for example it does not send the file to the FTP server, not sure if I'm doing anything wrong here or if I have the methods written incorrectly.



    Here is what I get in the consol



    BEY
    2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : Adding {transformer} as a subscriber to the '94.channel#0' channel
    2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.integration.channel.DirectChannel : Channel 'application.94.channel#0' has 1 subscriber(s).
    2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : started 94.org.springframework.integration.config.ConsumerEndpointFactoryBean#0
    2018-11-19 15:07:11.631 INFO 7212 --- [nio-8081-exec-6] o.s.i.e.SourcePollingChannelAdapter : started stockInboundPoller
    BEY
    2018-11-19 15:07:11.640 INFO 7212 --- [nio-8081-exec-6] f.s.s.configuration.FTIntegration : Outbound intermediate Channel, message=rename file:BEYFEFOexportBEY.csv
    2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockInboundFlowFromAFT, message=incoming file: BEYFEFOexportBEY.csv
    2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockIntermediateStageChannel, message=rename file: BEYFEFOexportBEY.csv









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have created an application that adds inbound adaptors at run time for ftp servers and registers them for removing at a certain stage if needed, this app will pull a csv file from ftp server(s) and place it in my local in a folder having the name of the ftp server, so every server I add will have a separate local folder created and the csv file is saved in it, now this is accomplished smoothly, the second part is I want to change the format of that file and then send it back to the respective server, so basically I need to use outbound adaptor, in this case I would need to create outbound adaptors at run time at the same time when creating inbound adaptor or adding a server, this should be done through controller same as the inbound, I searched for possible solutions and tried a one that is below but did not work or did not perform any sending of files to destination, any solution on how I can accomplish this?
      In the configuration class I added the below:



      public IntegrationFlow ftpOutboundFlow(Branch myBranch){

      return IntegrationFlows.from(OUTBOUND_CHANNEL)
      .handle(Ftp.outboundAdapter(createNewFtpSessionFactory(myBranch), FileExistsMode.FAIL)
      .useTemporaryFileName(true)
      .remoteFileSeparator("/")
      //.fileNameExpression("BEY/FEFOexportBEY.csv")
      .remoteDirectory(myBranch.getFolderPath()))
      .get();

      }

      @MessagingGateway
      public interface MyGateway {

      @Gateway(requestChannel = OUTBOUND_CHANNEL)
      void sendToFtp(File file);

      }

      @Bean
      public IntegrationFlow ftpOutboundChannel() {

      return IntegrationFlows.from(OUTBOUND_CHANNEL)
      .transform(p -> {
      LOG.info("Outbound intermediate Channel, message=rename file:" + p);
      return p;
      })
      .channel(new NullChannel())
      .get();
      }


      And in the Controller class



      @RequestMapping("/branch/showbranch/{id}")
      public String getBranch (@PathVariable String id, Model model){
      model.addAttribute("branch", branchService.getById(Long.valueOf(id)));
      addFlowftp(id);
      addFlowftpOutbound(id);
      return "/branch/showbranch";

      }

      private void addFlowftpOutbound(String name) {
      branch = branchService.getById(Long.valueOf(name));
      System.out.println(branch.getBranchCode());
      myGateway.sendToFtp(new File("BEY/FEFOexportBEY.csv"));
      IntegrationFlow flow = ftIntegration.ftpOutboundFlow(branch);
      //this.flowContext.registration(flow).id(name).register();
      }


      When I run the app and add a new branch with name BEY for example it does not send the file to the FTP server, not sure if I'm doing anything wrong here or if I have the methods written incorrectly.



      Here is what I get in the consol



      BEY
      2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : Adding {transformer} as a subscriber to the '94.channel#0' channel
      2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.integration.channel.DirectChannel : Channel 'application.94.channel#0' has 1 subscriber(s).
      2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : started 94.org.springframework.integration.config.ConsumerEndpointFactoryBean#0
      2018-11-19 15:07:11.631 INFO 7212 --- [nio-8081-exec-6] o.s.i.e.SourcePollingChannelAdapter : started stockInboundPoller
      BEY
      2018-11-19 15:07:11.640 INFO 7212 --- [nio-8081-exec-6] f.s.s.configuration.FTIntegration : Outbound intermediate Channel, message=rename file:BEYFEFOexportBEY.csv
      2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockInboundFlowFromAFT, message=incoming file: BEYFEFOexportBEY.csv
      2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockIntermediateStageChannel, message=rename file: BEYFEFOexportBEY.csv









      share|improve this question















      I have created an application that adds inbound adaptors at run time for ftp servers and registers them for removing at a certain stage if needed, this app will pull a csv file from ftp server(s) and place it in my local in a folder having the name of the ftp server, so every server I add will have a separate local folder created and the csv file is saved in it, now this is accomplished smoothly, the second part is I want to change the format of that file and then send it back to the respective server, so basically I need to use outbound adaptor, in this case I would need to create outbound adaptors at run time at the same time when creating inbound adaptor or adding a server, this should be done through controller same as the inbound, I searched for possible solutions and tried a one that is below but did not work or did not perform any sending of files to destination, any solution on how I can accomplish this?
      In the configuration class I added the below:



      public IntegrationFlow ftpOutboundFlow(Branch myBranch){

      return IntegrationFlows.from(OUTBOUND_CHANNEL)
      .handle(Ftp.outboundAdapter(createNewFtpSessionFactory(myBranch), FileExistsMode.FAIL)
      .useTemporaryFileName(true)
      .remoteFileSeparator("/")
      //.fileNameExpression("BEY/FEFOexportBEY.csv")
      .remoteDirectory(myBranch.getFolderPath()))
      .get();

      }

      @MessagingGateway
      public interface MyGateway {

      @Gateway(requestChannel = OUTBOUND_CHANNEL)
      void sendToFtp(File file);

      }

      @Bean
      public IntegrationFlow ftpOutboundChannel() {

      return IntegrationFlows.from(OUTBOUND_CHANNEL)
      .transform(p -> {
      LOG.info("Outbound intermediate Channel, message=rename file:" + p);
      return p;
      })
      .channel(new NullChannel())
      .get();
      }


      And in the Controller class



      @RequestMapping("/branch/showbranch/{id}")
      public String getBranch (@PathVariable String id, Model model){
      model.addAttribute("branch", branchService.getById(Long.valueOf(id)));
      addFlowftp(id);
      addFlowftpOutbound(id);
      return "/branch/showbranch";

      }

      private void addFlowftpOutbound(String name) {
      branch = branchService.getById(Long.valueOf(name));
      System.out.println(branch.getBranchCode());
      myGateway.sendToFtp(new File("BEY/FEFOexportBEY.csv"));
      IntegrationFlow flow = ftIntegration.ftpOutboundFlow(branch);
      //this.flowContext.registration(flow).id(name).register();
      }


      When I run the app and add a new branch with name BEY for example it does not send the file to the FTP server, not sure if I'm doing anything wrong here or if I have the methods written incorrectly.



      Here is what I get in the consol



      BEY
      2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : Adding {transformer} as a subscriber to the '94.channel#0' channel
      2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.integration.channel.DirectChannel : Channel 'application.94.channel#0' has 1 subscriber(s).
      2018-11-19 15:07:11.621 INFO 7212 --- [nio-8081-exec-6] o.s.i.endpoint.EventDrivenConsumer : started 94.org.springframework.integration.config.ConsumerEndpointFactoryBean#0
      2018-11-19 15:07:11.631 INFO 7212 --- [nio-8081-exec-6] o.s.i.e.SourcePollingChannelAdapter : started stockInboundPoller
      BEY
      2018-11-19 15:07:11.640 INFO 7212 --- [nio-8081-exec-6] f.s.s.configuration.FTIntegration : Outbound intermediate Channel, message=rename file:BEYFEFOexportBEY.csv
      2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockInboundFlowFromAFT, message=incoming file: BEYFEFOexportBEY.csv
      2018-11-19 15:07:11.642 INFO 7212 --- [ask-scheduler-1] f.s.s.configuration.FTIntegration : flow=stockIntermediateStageChannel, message=rename file: BEYFEFOexportBEY.csv






      spring spring-integration






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 36 mins ago

























      asked 5 hours ago









      Elias Khattar

      116




      116





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370579%2fjava-outbound-adaptor-processing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370579%2fjava-outbound-adaptor-processing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Volksrepublik China

          How to test boost logger output in unit testing?

          Write to the output between two pipeline