Announcement Announcement Module
Collapse
No announcement yet.
File copy not working as expected Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • File copy not working as expected

    I'm trying to build a file processing integration using the fileCopy-file example as my inspiration.

    Ive tried the example with Spring Integration 1.0-RELEASE and 1.0.1 in SVN (can't wait!), but the behavior doesn't seem correct and given its simialarity to the example fileCopy application, I don't know where I'm going wrong.

    Here's the code for the application context:
    Code:
     <?xml version="1.0" encoding="UTF-8"?>
    
    <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns="http://www.springframework.org/schema/integration"
                 xmlns:context="http://www.springframework.org/schema/context"
                 xmlns:file="http://www.springframework.org/schema/integration/file"
                 xmlns:mail="http://www.springframework.org/schema/integration/mail"
                 xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
            http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd
            http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd
            ">
     
        <beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
      
    
    
        <poller max-messages-per-poll="1" id="defaultPoller" default="true">
            <interval-trigger interval="1000"/>
        </poller>
    
           <beans:bean id="newBlogPublishingServiceActivator" class="com.joshlong.lazyblogger.integrations.NewBlogPublishingServiceActivator">
            <beans:property name="blogService" ref="blogService"/>
            <beans:property name="utilities" ref="utils"/>
        </beans:bean>
    
    
    	<file:inbound-channel-adapter id="filesIn"    
                         filename-pattern="^blog.*html$"
    	                              directory="file:${user.home}/blogs/inbound" />
    
    	<service-activator input-channel="filesIn"
    	                               output-channel="filesOut"
                                       ref="newBlogPublishingServiceActivator" method="publishIncomingBlogEntry"/>
    
    	<file:outbound-channel-adapter id="filesOut"       directory="file:/home/jlong/blogs/published" />
    
     
    </beans:beans>
    Here's the code for the Java code (which is blessedly simple (thanks for that!))

    Code:
    // package ...
    // bunch of imports none of which have anytyhing to do with a spring API (huzzah!)
    public class NewBlogPublishingServiceActivator {
        public File  publishIncomingBlogEntry( File content ) {
            try {
                InputStream inStream = null;
                inStream =new FileInputStream(content) ;
                String inStreamString = IOUtils.toString(inStream) ;
                IOUtils.closeQuietly(inStream);
                blogService.publish( null, new Date(), null, inStreamString ) ;  
            } catch (Throwable e) {
                utilities.log(ExceptionUtils.getFullStackTrace(e));
            }
            return null;
        }
    
        private Utilities utilities;
        private IBlogService blogService; 
    
        public Utilities getUtilities() {
            return utilities;
        }
    
        public void setUtilities(Utilities utilities) {
            this.utilities = utilities;
        }
    
        public IBlogService getBlogService() {
            return blogService;
        }
    
        public void setBlogService(IBlogService blogService) {
            this.blogService = blogService;
        } 
    }
    Any ideas would be very appreciated

  • #2
    I should clarify: I can see that Spring Integration is picking up the file in the inbound directory and I can scrutinize the payload (a File object) in the method in the service activator. It doesnt, however, see to do anything beyond that. the service activator class returns the File (the payload) and my understanding was that would be sent on the reply (the outbound-channel in the service activator.).

    Thanks again!

    Comment


    • #3
      I put it under the debugger. The value for the directory is being set in the Spring confguration on the inbound-file-adapter as follows:
      Code:
        directory="file:${user.home}/blogs/inbound"
      The directory in the Spring configuration for the outbound-file-adapter is being set as follows:

      Code:
       directory="file:${user.home}/blogs/published"
      The value o the directory attribute on the FileWritingMessagingHandler class is equal to "file:/home/jlong/blogs/published" for the outbound file directory, which is not a valid java.io.File url! I change the attribute on the outbound to be just ${user.home}/blogs/published, and sure enough, it worked! This I think is because the inbound adapter is using a Spring framework Resource under the hood, which knows how to deal wiht file: prefixes, and the FileWritingMessagingHandler instead uses a plain jane java.io.File object. So much for symmetry! I just went back and noticed that the sample is doing the right thing, as well, by using file: on the inbound but not on the outbound.

      It might prove useful to change that or at least note in big bold letters that they're not the same, because it's hard to tell from the birds eye view that the XML schema affords us.

      Thanks again

      Comment


      • #4
        Josh,

        Please file a JIRA issue for this. We should be consistent or at least well-documented as you pointed out. In this case, if possible, perhaps the system should fail-fast with a meaningful error message.

        On a somewhat related note, I think it might be nice to have the "file:" prefix automatically prepended if no other prefix has been provided. The Resource usage here is convenient, but I'm sure most of the time it will be "file:" anyways.

        Thank you for providing so much detail in your posts.

        -Mark

        Comment


        • #5
          Mark,

          Thanks as usual for the quick response. I added a JIRA item at http://jira.springframework.org/browse/INT-518

          What do you think the resolution for this would be? I can kind of see why the attribute was a java.io.File... afterall, I doubt the FileCopyUtil class supports writing to all the possible URIs addressable by the Spring Resource URL format, so it makes more sense to limit it to a File. On the other hand, it does make sense to support the flexibility in the inbound connector because a file on the classpath is just as good as a file on the filesystem wrt to reads (but definitely wrt to writes).

          Your point about the default being file: is also very valid. Changing either attribute would alter a now public interface (though, i rather suspect most people are using the xml schema, so they needn't see the underlying change.)

          Assuming you're willing to break the class public interface, perhaps you could expose both as Resource and just test for the value being one of a few types supportable (ie, classpath:, file:, or regular old file without prefix for inbound, file:, regular file for outbound)? Semantically, a inbound file adapter shouldn't be reading http: urls anyway :-)

          Anyway, thanks again

          Comment


          • #6
            File FTP Upload on Remote Machine

            Hi,

            I have a requirment like reding the message xml file message from MQ Q and construct the text file xml message and upload the text file on remote machine. preferabally by FTP connection. Can I use the file outbound adapter and are there any sampls for this in spring

            Comment

            Working...
            X