2 Replies Latest reply on May 8, 2013 9:39 AM by Tinie Sluijter

    Can't change property for file binding

    Tinie Sluijter Newbie

      Hello,

       

      I'm working with SwitchYard 0.8.

      I'd like to output an e-mail attachment to a file on the file system in a custom directory and the attachment filename as filename.

      Therefore i've created the switchyard.xml as following

       

      <?xml version="1.0" encoding="UTF-8"?>
      <switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:bean="urn:switchyard-component-bean:config:1.0" xmlns:file="urn:switchyard-component-camel-file:config:1.0" xmlns:jpa="urn:switchyard-component-camel-jpa:config:1.0" xmlns:mail="urn:switchyard-component-camel-mail:config:1.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="DocumentHandler" targetNamespace="urn:nl.caci:DocumentHandler:1.0">
        <sca:composite name="DocumentHandler" targetNamespace="urn:nl.caci:DocumentHandler:1.0">
          <sca:component name="ConsumeEmailBean">
            <bean:implementation.bean class="nl.caci.document.handler.ConsumeEmailBean"/>
            <sca:service name="ConsumeEmail">
              <sca:interface.java interface="nl.caci.document.handler.ConsumeEmail"/>
            </sca:service>
            <sca:reference name="StoreFile">
              <sca:interface.java interface="nl.caci.document.handler.StoreFile"/>
            </sca:reference>
          </sca:component>
          <sca:reference name="StoreFile" multiplicity="0..1" promote="ConsumeEmailBean/StoreFile">
            <sca:interface.java interface="nl.caci.document.handler.StoreFile"/>
            <file:binding.file>
              <file:contextMapper/>
              <file:directory>${file.directory:/}</file:directory>
              <file:fileName>${file.name:test.txt}</file:fileName>
              <file:produce/>
            </file:binding.file>
          </sca:reference>
          <sca:service name="ConsumeEmail" promote="ConsumeEmailBean/ConsumeEmail">
            <sca:interface.java interface="nl.caci.document.handler.ConsumeEmail"/>
            <mail:binding.mail>
              <mail:contextMapper/>
              <mail:host>mail.caci.nl</mail:host>
              <mail:username>poccarfin</mail:username>
              <mail:password>QAplzx12</mail:password>
              <mail:consume accountType="imap">
                <mail:folderName>INBOX</mail:folderName>
              </mail:consume>
            </mail:binding.mail>
          </sca:service>
          <sca:property name="file.directory" value="/temp" />
          <sca:property name="file.name" value="test.docx" />
        </sca:composite>
      </switchyard>
      
      

       

      I want to set the properties in the ConsumeEmailBean class

      I've tried different way to set the properties (i only show the file.name as example)

       

      @Inject
      private Contect context;
      
      @Inject
      @Reference("StoreFile")
      private StoreFile _storeFile
      
      @Property("file.name")
      private String fileName
      
      public void consume(MimeMultiPart msg) {
        // first try 
        fileName = msg.getBodyPart(i).getFileName();
      
        // next try
        System.setProperty("file.name", msg.getBodyPart(i).getFileName());
      
        // next try
        context.setProperty("file.name", msg.getBodyPart(i).getFileName());
      
        // next try
        context.setProperty("file.name", msg.getBodyPart(i).getFileName(), Scope.Exchange);
      
        // next try
        from("switchyard://StoreFile").to("file:".concat(dirname).concat("?fileName=").concat(msg.getBodyPart(i).getFileName()));
      
      
        _storeFile.store(attachment);
      }
      

       

      Nothing seems to work.

      The only thing i see, is if i used the System.setProperty the property is changed after i redeploy the project.

       

      I've read through numerous document pages and discussions, but haven't found the answer to my problem yet.