Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26

Thread: Configuring at runtime

  1. #11
    Join Date
    Feb 2012
    Posts
    101

    Default

    Thanks for the clarification Cleric.Appreciate your help.


    Code:
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setBeanResolver(new sftpSessionFactory());  
    
    // This will end up calling resolve(context,"foo") on MyBeanResolver during evaluation
    Object bean = parser.parseExpression("@remoteDirectoryRequestBea n").getValue(context);
    In the above code do I have to use sftpSessionFactory or sendChannel.

    Also, please let me know if the scope= request for httpsession?

    thanks

  2. #12
    Join Date
    Feb 2012
    Posts
    101

    Default

    one more doubt,

    Is scoped annotation required in my class something like

    Code:
    @Scope(Request)
    Please give the sample code to set the attribute value if I'm doing it wrong.

    Thank You

  3. #13
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    Is scoped annotation required in my class something like
    This annotation is needed when you configure beans on Java-level, not XML. So, scope="request" and @Scope("request") do the same work for builded bean.

    About your code around ExpressionParser: why do you need this code? What are you doing with it?

    sample code to set the attribute value
    Sample about what? What don't you get?

  4. #14
    Join Date
    Feb 2012
    Posts
    101

    Default

    Now, that you have defined the sftpSessionFactory bean in the xml file with "scope=request"

    We also have the

    HTML Code:
    <sftp outbound-channel-adapter session-factory=sftpSessionFactory  remote-directory-expression=@remoteRequestBean>
    Somehow I should set the value of the attribute (remote-directory-expression) ,I'm not able to understand how that works.

    Thanks

  5. #15
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    remote-directory-expression="@remoteRequestBean"
    As I said at the begin, it is an expression which will be invoked on the each Message in the <sftp:outbound-channel-adapter/>
    And also we've decided to use here some request-scoped bean, which will be setuped by end-user in the GUI as properties of sftpSessionFactory bean.
    However, keep in mind: remote-directory-expression is a SpEL and it has an ability to access to Message properties.
    So, you can from GUI build a Message with some header with value about remote directory.

    And now I'm a bit sad, that you haven't read the article, I gave...

  6. #16
    Join Date
    Feb 2012
    Posts
    101

    Default

    I did read through the article mentioned in the link.I did not notice anything about constructing message with header.I'm Sorry,maybe I'm missing something here.

    If you see the section Bean References 7.5.12, it mentions
    7.5.12 Bean references

    If the evaluation context has been configured with a bean resolver it is possible to lookup beans from an expression using the (@) symbol.


    That is were I looked at the example.

    So is it enough to just use..



    Code:
    Message<File> message1 = MessageBuilder.withPayload(file1)
            .setHeader("remote-directory", "/dirname/")
            .build();
    Will that simply substitute the value of remote directory in the place of @remoteRequestBean.Don't we have to refer to @remoteRequestBEan in the code.

    Thank You for your help Cleric.

  7. #17
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    Following with your last sample, now you should configure remote-directory-expression like this:
    HTML Code:
    remote-directory-expression="headers['remote-directory']"

  8. #18
    Join Date
    Feb 2012
    Posts
    101

    Default

    Thank You Cleric

  9. #19
    Join Date
    Sep 2011
    Posts
    28

    Default

    Quote Originally Posted by newbie_24 View Post
    Thank You Cleric
    Why not write a class which returns you back the remote directory expression just a regular string and then use header enricher to set it ?. Much simpler..

  10. #20
    Join Date
    Feb 2012
    Posts
    101

    Default

    Hi ,

    Somebody please help.Please go through the email threads above and this is the error I see

    Error creating bean with name 'scopedTarget.sftpSessionFactory': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

    I'm not using any HttpRequest.

    HTML Code:
     <bean id="sftpSessionFactory"
        class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory" scope="request">
        <aop:scoped-proxy/>
      </bean>
    <sftp:outbound-channel-adapter channel="sendChannel"
        session-factory="sftpSessionFactory" id="sftpInboundAdapter"
        auto-create-directory="true"
        temporary-file-suffix = "temp"
        remote-directory-expression="headers['remote-directory']" />
    Code:
    	@Inject
    	private DefaultSftpSessionFactory sftpSessionFactory;
    
    	@Inject
    	@Named("sendChannel")
    	private MessageChannel sftpChannel;
            hostname = serverProp.getHostname();
            password = serverProp.getPassword();
            username = serverProp.getUsername();
            remoteDir = serverProp.getRemoteDir();
    
    	sftpSessionFactory.setHost(hostname);
    	sftpSessionFactory.setUser(username);
    	sftpSessionFactory.setPassword(password);
    
            Message<File[]> message = MessageBuilder
    			        .withPayload(zippedFilesList)
    			        .setHeader("remote-directory",remoteDir).build();
    			if(sftpChannel != null && message != null)
    				sftpChannel.send(message);
    The above error shown is thrown at the code which is underlined.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •