Announcement Announcement Module
Collapse
No announcement yet.
Help needed with Spring Integration modelling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help needed with Spring Integration modelling

    Hi there,

    I was trying to model an integration system that polls regularly a web page (Directory Listing) using an HTTP outbound gateway, but if HTTP fails for some reason triggers a request to an FTP outbound adapter. both output should be channeled into a single channel that will process the list of files, filters already seen files, retrieve the rest and processes them further.

    I found the first part not easy to model, can someone help me here?

    Cheers,
    Kai

  • #2
    Can you throw some light on the use case you are trying to model here?

    If i understand you correctly, you are using an http outbound gateway to send a request to some server, whose response will be an html, which you would parse to get the directory listings on a particular path on the server (provided directory listing is enabled on it)?

    Say if it fails for some reason and the server is not available , what do you want to achieve with the outbound FTP adapter?

    Comment


    • #3
      I think for a start you can do the following:
      Code:
      <int:gateway . . . default-request-channel="httpRequest" error-channel="httpErrorChannel"/>
      
      <int:channel id="httpRequest"/>
      
      <int:channel id="httpErrorChannel"/>
      
      <int-http:outbound-gateway request-channel="httpRequest" . . . reply-channel="httpReply"/>
      
      <int:channel id="httpReply"/>
      Now when you make a request via the <gateway> two things will happen.
      1. If HTTP request is successful, the result message will go to 'httpReply' channel
      2. If HTTP request is un-successful than the Exception will be encapsulated into the ErrorMessage and sent back to the caller's error-channel (in this case 'httpErrorChannel'). You can add a subscriber to 'httpErrorChannel' the normal way and do whatever you need for error-processing. You can also bridge 'httpReply' and 'httpErrorChannel' to a single channel and than add a router that will route based on the type of the Message (Error vs success)
      For example:
      Code:
      <int:bridge input-channel="httpReply" output-channel="resultProcessingChannel"/>
      
      <int:bridge input-channel="httpErrorChannel" output-channel="resultProcessingChannel"/>
      
      <int:router input-channel="resultProcessingChannel". . ./>
      Now, regardless of error or no error everything will go to the 'resultProcessingChannel'

      Hop that helps

      Comment


      • #4
        Originally posted by Amol Nayak View Post
        If i understand you correctly, you are using an http outbound gateway to send a request to some server, whose response will be an html, which you would parse to get the directory listings on a particular path on the server (provided directory listing is enabled on it)?

        Say if it fails for some reason and the server is not available , what do you want to achieve with the outbound FTP adapter?
        You got the first part of my use case right. In case of a web server outage we should fall back to an FTP source as backup - we are not allowed to poll it in other cases. Same files there, just different protocol to receive them.

        Problem 1 for me is, how can I use the outbound FTP adapter in a nonpolling way, triggered by the errormessage or a transformed message ?

        Cheers,
        Kai

        Comment


        • #5
          Hi, Oleg,

          Thanks for the first pieces. How would I model the nonpolling FTP adapter then? Is there a component ready for this?

          Cheers,
          Kai

          Comment


          • #6
            There is a new feature - ftp outbound-gateway in 2.1 (Release Candidate 1 was released last week, GA shortly). Update your POMs to 2.1.0.RC1.

            The gateway supports commands ls, get, and rm.

            The results of 'ls' can be a list of file names, or a list of FileInfo objects containing file metadata.

            Here is a snippet from the reference manual...

            The FTP Outbound Gateway provides a limited set of commands to interact with a remote FTP/FTPS
            server.

            Commands supported are:
            ls (list files)
            get (retrieve file(s))
            rm (remove file(s))

            ls supports the following options:

            -1 - just retrieve a list of filenames, default is to retrieve a list of FileInfo objects.
            -a - include all files (including those starting with '.')
            -f - do not sort the list
            -dirs - include directories (excluded by default)
            -links - include symbolic links (excluded by default)

            In addition, filename filtering is provided, in the same manner as the inbound-channel-adapter.
            The message payload resulting from an ls operation is a list of file names, or a list of FileInfo objects.
            These objects provide information such as modified time, permissions etc.

            The remote directory that the ls command acted on is provided in the file_remoteDirectory
            header.

            get supports the following option:

            -P - preserve the timestamp of the remote file

            The message payload resulting from a get operation is a File object representing the retrieved file.
            The remote directory is provided in the file_remoteDirectory header, and the filename is
            provided in the file_remoteFile header.

            The rm command has no options.

            Note: Filters are not supported with the rm command.

            The message payload resulting from an rm operation is Boolean.TRUE if the remove was successful,
            Boolean.FALSE otherwise. The remote directory is provided in the file_remoteDirectory
            header, and the filename is provided in the file_remoteFile header.

            In each case, the PATH that these commands act on is provided by the 'expression' property of the
            gateway.

            Here is an example of a gateway configured for an ls command...

            Code:
            <int-ftp:outbound-gateway id="gateway1"
                session-factory="ftpSessionFactory"
                request-channel="inbound1"
                command="ls"
                command-options="-1"
                expression="payload"
                reply-channel="toSplitter"/>
            The payload of the message sent to the toSplitter channel is a list of String objects containing the filename
            of each file. If the command-options was omitted, it would be a list of FileInfo objects. Options
            are provided space-delimited, e.g. command-options="-1 -dirs -links".
            There is sample code here https://github.com/SpringSource/spri...ster/basic/ftp.

            Comment


            • #7
              Thanks, Gary,

              I think that is exactly what I was missing in 2.0.5.
              Is there a way to recourse into folders to get FileInfo objects of deeper levels in one go?

              Cheers,
              Kai

              Comment


              • #8
                No; it only supports fetching a single level.

                Comment

                Working...
                X