7 Replies Latest reply on Jul 8, 2014 2:56 AM by tadayosi

    File Binding Reference - Dynamic File Name

    fenoloco

      Hi,

      How can I define the generated file name at runtime of the Camel file binding. I try to redefine the properties on a previous step but I couldn't achieve that.

       

      Thanks.

        • 1. Re: File Binding Reference - Dynamic File Name
          kcbabo

          By "at runtime" do you mean:

           

          1) Replace the value in the application with something different at startup.

          2) Replace the value in the application with something different per message.

           

          For (1), you can use property substitution.  For (2), I assume we are talking about a producer endpoint.  I have not tested this, but if you have a CamelFileName context property in your SY message and configure the context mapper on the binding to propagate that property, then that should end up in the Camel message passed to the Camel file component.

          1 of 1 people found this helpful
          • 2. Re: Re: File Binding Reference - Dynamic File Name
            fenoloco

            Hi,

            Thank for the reply.

            I'm in the case number 2.

             

            I managed to change the fileName but I can not make the same with the directory. I imagine that the directory property is get in a different way, can you give me a clue?

             

            I add my code maybe someone else need it or want to leave a comment.

             

              @Override
                public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception
                {
                  ..............     
                        org.apache.camel.Message msg = target.getMessage();
                        
                        // Define file name
                        String fileName = "";
                        msg.setHeader(org.apache.camel.Exchange.FILE_NAME, fileName);
                .............
            


            Thanks in advance.

            1 of 1 people found this helpful
            • 3. Re: File Binding Reference - Dynamic File Name
              kcbabo

              I don't think you can change the root directory name, but you could use sub-directories in your filename path to put messages in separate folders within the root directory.  More info available in the Camel File component documentation:

              http://camel.apache.org/file2.html

              • 4. Re: File Binding Reference - Dynamic File Name
                jdestef

                Hi,

                 

                Trying to do the same thing that your code outlines. grab the message from the target and set the headers. Still the file name is the switchyard messageId. Would have a working sample that you could share? I must have something set incorrectly. I'm using the supplied switchyard file binding.

                 

                Thanks

                • 5. Re: File Binding Reference - Dynamic File Name
                  fenoloco

                  Hi,

                  Which version are you using, it works for me on 1.1.0 Final. I can´t share my example; is a comercial product.

                  If you have an small example, share it and I will give it a look.-

                  • 6. Re: File Binding Reference - Dynamic File Name
                    jdestef

                    Thanks,

                     

                    I think I have it working by using the ReferenceInvoker and setting the property CamelFileName to the name of the file I want produced. This seems to work as long as there is no fileName element in the switch producer configuration. Thanks for your offer.

                    • 7. Re: File Binding Reference - Dynamic File Name
                      tadayosi

                      For anyone who is interested, I created a working dynamic filename example project:

                      samples-switchyard/ftp-filename at master · tadayosi/samples-switchyard · GitHub