Announcement Announcement Module
Collapse
No announcement yet.
SpEL in session-factory of ftp inbound/outbopund-channel-adapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SpEL in session-factory of ftp inbound/outbopund-channel-adapter

    Hi,
    I have a requirement to read FTP connection information from DB - create instance of
    org.springframework.integration.ftp.session.Defaul tFtpSessionFactory and cache this instance. In my implmentation of FtpSourceFactory is method getFtpDataSource(ftpname) which returns mentioned DefaultFtpSessionFactory.
    Then in aplication-context I would like to do using SpEL something like this:

    Code:
    <bean id="ftpClientFactory" 
    	class="com.trtrtr.platform.FtpSourceFactory">
    		<property name="dbJdbcTemplate" value="jdbctemplate"/>
    </bean>
    .
    .
    .
    <int-ftp:inbound-channel-adapter id="ftpInbound"
    				channel="ftpChannel" 
    				session-factory="#{ftpClientFactory.getFtpDataSource('ftp1')}"
    				charset="UTF-8"
    				auto-create-local-directory="true"
    				delete-remote-files="true"
    				filename-pattern="*.txt"
    				remote-directory="some/remote/path"
    				remote-file-separator="/"
    				local-filename-generator-expression="#this.toUpperCase() + '.a'"
    				local-directory=".">
    			<int:poller fixed-rate="1000"/>
    </int-ftp:inbound-channel-adapter>
    but session-factory property does not support SpEL. Do you know any other mechanism how to achive it?

    Thank you,
    Jakub

  • #2
    See this thread http://forum.springsource.org/showth...apter-creation

    Comment


    • #3
      Thank you for quick reply Gary. I don't want to be ungrateful but it seems to us as quite complicated - to have parent->child application-context but maybe I misunderstood the main benefit of this solution.
      Isn't it for example possible to define inbound-channel-adapter via its java class (where I can use SpEL) or something similar?

      Thank you,
      Jakub

      Comment


      • #4
        Sorry; I misunderstood your question; I thought you were looking for dynamically generating factories.

        In this case, you could simply have your FtpSourceFactory implement SessionFactory<FTPFile> and have it delegate to the factory you create from the database...

        Code:
        
        public class FF implements SessionFactory<FTPFile> {
        
        	private DefaultFtpSessionFactory factory;
        
        	public Session<FTPFile> getSession() {
        		if (factory == null) {
        			buildFactory();
        		}
        		return factory.getSession();
        	}
        
        	public void buildFactory() {
        		// build factory
        	}
        
        }

        Comment


        • #5
          Actaully I am not sure whether what I want I can call dynamically generating factories or dynamic behaviour. I would like to create aplication context only once. In this contextl should be declared several adapters:
          Code:
          <int-ftp:inbound-channel-adapter id="ftpInbound1"
          				session-factory="ftp1"
          				...
          </int-ftp:inbound-channel-adapter>
          .
          .
          .
          <int-ftp:inbound-channel-adapter id="ftpInbound2"
          				session-factory="ftp2"
          				...
          </int-ftp:inbound-channel-adapter>
          .
          .
          .
          <int-ftp:inbound-channel-adapter id="ftpInbound3"
          				session-factory="ftp2"
          				...
          </int-ftp:inbound-channel-adapter>
          each of this adapters shoudl be connected with one instance of DefaultFtpSessionFactory ("ftp1","ftp2") and also they can use the same instance of DefaultFtpSessionFactory like ftpInbound2 and ftpInbound3.
          Now, the classic way is to have:
          Code:
          <bean id="ftp1" 
          	class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
          		<property name="host" value="bbb"/>
          		<property name="username" value="kermit"/>
          		<property name="password" value="frog"/>
          </bean>
          
          <bean id="ftp2" 
          	class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
          		<property name="host" value="aaa"/>		
          		<property name="username" value="kermit"/>
          		<property name="password" value="frog"/>
          </bean>
          But I have (in shorctuc) this class:
          Code:
          public class FtpSourceFactory{
          
             public DefaultFtpSessionFactory getFtpDataSource(ftpname){
          	//obtaining data from DB + pushing created instanceOfDFSF into cache
          	return instanceOfDFSF
             }
          }
          So finally I would like to do this:
          Code:
          <bean id="ftpClientFactory" 
          	class="com.trtrtr.platform.FtpSourceFactory">
          </bean>
          
          
          <int-ftp:inbound-channel-adapter id="ftpInbound1"
          				session-factory="#{ftpClientFactory.getFtpDataSource('ftp1')}"
          				...
          </int-ftp:inbound-channel-adapter>
          .
          .
          .
          <int-ftp:inbound-channel-adapter id="ftpInbound2"
          				session-factory="#{ftpClientFactory.getFtpDataSource('ftp2')}"
          				...
          </int-ftp:inbound-channel-adapter>
          .
          .
          .
          <int-ftp:inbound-channel-adapter id="ftpInbound3"
          				session-factory="#{ftpClientFactory.getFtpDataSource('ftp2')}"
          				...
          </int-ftp:inbound-channel-adapter>
          But this context will be created/started only once without any changes in the future (The only change I will/could do is e.g. change of the password of concrete instanceOfDFSF but it will be directly in my cache and this part should be troublefree.) As I said I face difficulties because this implementation is not supported.Since I am not so expirienced in spring-integration I actually cant connect you solution with my problem.

          Thank you,
          Jakub
          Last edited by jakub.kettner; Jul 17th, 2012, 11:45 AM. Reason: wrong formating

          Comment


          • #6
            I am not saying we couldn't support SpEL, but there are lots of ways to do what you want; for example...

            Code:
            public class MyFactory implements SessionFactory<FTPFile> {
            
            	private DefaultFtpSessionFactory factory;
            
            	public MyFactory(FactoryCache cache, String ftpName) {
            		this.factory = cache.getFactory();
            	}
            
            	public Session<FTPFile> getSession() {
            		return this.factory.getSession();
            	}
            }
            ...
            
            <bean id="cache" class="foo.FactoryCache" />
            
            <bean id="ftp1" class="foo.MyFactory">
                <constructor-arg ref="cache" />
                <constructor-arg value="ftp1" />
            </bean>
            
            <bean id="ftp2" class="foo.MyFactory">
                <constructor-arg ref="cache" />
                <constructor-arg value="ftp2" />
            </bean>
            
            ... etc
            Or, create a static factory method on your cache and use

            Code:
            <bean id="ftp1" class="org.springframework.integration.samples.ftp.MyFactory" factory-method="getFactory">
            	<constructor-arg value="ftp1" />
            </bean>

            Or, ...

            Comment


            • #7
              Thank you Garry! Factory-method did the trick - I must confess that I had only weak idea of what can I do with factory-method.

              Bye,
              Jakub

              Comment

              Working...
              X