9 Replies Latest reply on Apr 16, 2014 11:44 AM by Jorge Morales

    Loading environment properties from file

    Jorge Morales Master

      Hi,

      I would like to have properties loaded from properties file to configure my endpoints.

      I have declared a module:

       

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <module xmlns="urn:jboss:module:1.0" name="com.examples.switchyard.properties">
          <resources>
            <resource-root path="props"/>
          </resources>
      </module>
      

       

      In this path, I have a properties file, called ftp.properties:

      ftp_server.host=localhost
      ftp_server.port=22
      ftp_server.username=user
      ftp_server.password=xxxx
      ftp_server.default_share=/opt/data/
      

       

      I would like my binding to use this properties:

      <ftp:binding.sftp>
              <ftp:directory>${ftp_server.default_share}</ftp:directory>
              <ftp:autoCreate>false</ftp:autoCreate>
              <ftp:fileName>dummy</ftp:fileName>
              <ftp:host>${ftp_server.host}</ftp:host>
              <ftp:port>${ftp_server.port}</ftp:port>
              <ftp:username>${ftp_server.username}</ftp:username>
              <ftp:password>${ftp_server.password}</ftp:password>
              <ftp:produce/>
            </ftp:binding.sftp>
      

       

      And would love to have something like composite properties or domain properties loading this file, so instead of:

      <sca:property value="ftp_server.host" name="localhost"/>
      

       

      Have something like:

      <sca:properties file="ftp.properties"/>
      

       

      Is this possible in any way?

        • 1. Re: Loading environment properties from file
          Tomohisa igarashi Master

          Hi Jorge,

           

          We don't support loading environment properties from file right now, but it looks good to have. Could you raise a enhancement JIRA?

           

          For now, you can use system environment variables to separate the property definition from switchyard.xml.

          https://docs.jboss.org/author/display/SWITCHYARD/Properties

           

          You can have properties file like this (say ftp.properties)

          export ftp_server.host=localhost 

          export ftp_server.port=22 

          ...

           

          load above file from standalone.sh

          . path/to/ftp.properties

           

          and specify it from switchyard.xml with env. prefix

          <ftp:host>${env.ftp_server.host}</ftp:host> 

          <ftp:port>${env.ftp_server.port}</ftp:port>

           

          Thanks,

          Tomo

          1 of 1 people found this helpful
          • 2. Re: Loading environment properties from file
            David Ward Master

            This is not currently possible. Please feel free to add a Feature Request in our jira issue tracker.  Thanks!

            • 3. Re: Re: Loading environment properties from file
              Jorge Morales Master

              What is the difference in defining this property as environment property or using a module to define properties? Shouldn't the later also work?

              <?xml version="1.0" encoding="UTF-8" standalone="no"?>
              <module xmlns="urn:jboss:module:1.0" name="com.examples.switchyard.properties">
                  <properties>
                      <property name="ftp_server.host" value="localhost"/>
                      <property name="ftp_server.port" value="22"/>
                      <property name="ftp_server.username" value="user"/>
                      <property name="ftp_server.password" value="xxxxx"/>
                      <property name="ftp_server.default_share" value="/opt/tmp"/>
                  </properties>
              </module>
              
              

               

              Right now, I'm getting an exception, and per the documentation this should be possible.

              ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."order-management-sim-stock.jar".SwitchYardService: org.jboss.msc.service.StartException in service jboss.deployment.unit."order-management-sim-stock.jar".SwitchYardService: java.lang.NumberFormatException: For input string: "${ftp_server.port}"
                at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:81)
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
                at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
              Caused by: java.lang.NumberFormatException: For input string: "${ftp_server.port}"
                at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) [rt.jar:1.7.0_45]
                at java.lang.Integer.parseInt(Integer.java:481) [rt.jar:1.7.0_45]
                at java.lang.Integer.parseInt(Integer.java:527) [rt.jar:1.7.0_45]
                at org.switchyard.component.camel.common.model.v1.V1BaseCamelBindingModel.getIntegerConfig(V1BaseCamelBindingModel.java:197)
                at org.switchyard.component.camel.common.model.remote.v1.V1CamelRemoteFileBindingModel.getPort(V1CamelRemoteFileBindingModel.java:159)
                at org.switchyard.component.camel.common.model.remote.v1.V1CamelRemoteFileBindingModel.getComponentURI(V1CamelRemoteFileBindingModel.java:332)
                at org.switchyard.component.camel.common.handler.OutboundHandler.<init>(OutboundHandler.java:91)
                at org.switchyard.component.camel.common.handler.OutboundHandler.<init>(OutboundHandler.java:71)
                at org.switchyard.component.camel.common.deploy.BaseBindingActivator.activateBinding(BaseBindingActivator.java:45)
                at org.switchyard.deploy.internal.Deployment.deployReferenceBindings(Deployment.java:300)
                at org.switchyard.deploy.internal.Deployment.start(Deployment.java:143)
                at org.switchyard.as7.extension.deployment.SwitchYardDeployment.start(SwitchYardDeployment.java:121)
                at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:74)
                ... 5 more
              
              

               

               

              I've raised the JIRA ([SWITCHYARD-2048] Loading environment properties from file - JBoss Issue Tracker), and it would be nice to have an advice on this other topic, as using environment properties is not very nice :-(

              • 4. Re: Re: Loading environment properties from file
                David Ward Master

                I'm not very familiar with the module properties, but you don't have to use environment properties.  You can pass system properties as a command line option when starting up jboss.

                • 5. Re: Re: Loading environment properties from file
                  David Ward Master

                  You can pass in a file of properties at command line like so (see -P option 2.1.6):

                  https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/html/Administration_and_Con…

                  1 of 1 people found this helpful
                  • 6. Re: Loading environment properties from file
                    Jorge Morales Master

                    Hi David,

                    It seems that there is a way to define a custom PropertiesResolver, and register it within the Switchyard xml element:

                    https://github.com/jboss-switchyard/core/blob/master/config/src/main/java/org/switchyard/config/DOMConfiguration.java#L685

                     

                    Could you please give advice on how to declare a new PropertyResolver, so we can test it ourselves and if it works, provide with a patch, as would like to also provide PropertyResolvers that gets configruation from ISPN cache.

                    • 7. Re: Loading environment properties from file
                      David Ward Master

                      PropertyResolvers are only set programmatically. They cannot be set/registered in the switchyard.xml file.

                       

                      The recommended way of adding the capability you seek is by extending the switchyard xml schema in the correct way, and have the back-end configuration handling add to the compound property resolution. I'm sorry I don't have the bandwidth right now to explain it in step-by-step detail.

                      • 8. Re: Loading environment properties from file
                        Rob Cernich Master

                        Another option is to add these as system properties to your EAP configuration file (e.g. standalone.xml).  These properties can be added through the EAP console and management layer.  Documentation link (for AS7): JBoss AS7 System Properties

                         

                        Hope that helps,

                        Rob

                        • 9. Re: Loading environment properties from file
                          Jorge Morales Master

                          dward

                          Don't worry. It seems rather complex as to being a supported solution :-(

                          We'll have to wait until more extensibility is provided in this area.

                           

                          rcernich

                          Thanks, good point. Although not of any value for properties that are set at deployment time, can be of much value for those that are set per request.