3 Replies Latest reply on Jul 7, 2008 3:13 AM by John McClain

    how to inject into components.xml?

    John McClain Newbie

      I want to do something like this in components.xml


      <drools:rule-agent name="isDealRuleBase" 
         url="http://#{webServerUrl}/jbrms/org.drools.brms.JBRMS/package/com.homeq.cam.deal.domain.isDeal/LATEST"
         local-cache-dir="/var/data/cam"
         poll="30">
        </drools:rule-agent>
        
         <drools:rule-agent name="isFastTrackRuleBase"
         url="http://#{webServerUrl}/jbrms/org.drools.brms.JBRMS/package/com.homeq.cam.deal.domain.isFastTrack/LATEST"
         local-cache-dir="/var/data/cam"
         poll="30">
        </drools:rule-agent>
      
        <drools:rule-agent name="generalRuleBase"
         url="http://#{webServerUrl}/jbrms/org.drools.brms.JBRMS/package/com.homeq.cam.deal.domain.generalDealRules/LATEST"
         local-cache-dir="/var/data/cam"
         poll="30">
        </drools:rule-agent>
      



      #{webServerUrl} comes from a system property as in the following


      @Name("serverInfo")
      @Scope(ScopeType.APPLICATION)
      public class ServerInfo implements Serializable {
      .
      .
      @Factory
              public String getWebServerURL(){
                      webServerUrl = System.getProperty("Cam.Server.Url");
                      return webServerUrl;
              }
      


      I want 1 ear file that I can deploy to 3 different servers where each server has in its classpath a server specific properties file from which to get its own #{webServerURL}. How can I ge system properties (from a property file) into components.xml????

        • 1. Re: how to inject into components.xml?
          Vitaly Masterov Newbie

          Could not you use this one ?:

          #{serverInfo.webServerURL}


          @Factory annotation is not required here...

          • 2. Re: how to inject into components.xml?
            John McClain Newbie

            Have tried this already  here is code


            @Name("serverInfo")
            @Scope(ScopeType.APPLICATION)
            @Startup
            public class ServerInfo implements Serializable {
            
                 private static final long serialVersionUID = 1L;
            
                 String serverName = "Ukn."; // Unknown server name (short, for small
                                                                                       // display)
            
                 private String webServerURL = null;
            
                 public ServerInfoTest() {
                      try {
                           InetAddress addr = InetAddress.getLocalHost();
                           serverName = addr.getHostName();
                           webServerURL = System.getProperty("CAM.Server.Url");
                      } catch (Exception e) {
                           System.out.println(e.toString());
                      }
                      
                      
            
                 }
            
                 public String getServerName() {
                      return this.serverName;
                 }
                 
            
                 public String getWebServerURL(){
                      return webServerURL;
                 }
            
            }
            



            Here is the error


            18:05:35,083 ERROR [STDERR] RuleAgent(default) INFO (Sun Jul 06 18:05:35 PDT 2008): Configuring with newInstance=false, secondsToRefresh=30
            18:05:35,099 ERROR [STDERR] RuleAgent(default) INFO (Sun Jul 06 18:05:35 PDT 2008): Configuring package provider : URLScanner monitoring URLs:  http://#{serverInfo.webServerURL}#{serverInfo.webServerURL}/drools-jbrms/org.drools.brms.JBRMS/package/com.homeq.cam.deal.domain.isDeal/LATEST with local cache dir of \var\data\cam
            18:05:50,317 ERROR [STDERR] RuleAgent(default) WARNING (Sun Jul 06 18:05:50 PDT 2008): Was an error contacting http://#{serverInfo.webServerURL}#{serverInfo.webServerURL}/drools-jbrms/org.drools.brms.JBRMS/package/com.homeq.cam.deal.domain.isDeal/LATEST. Reponse header: {}
            18:05:50,317 ERROR [STDERR] RuleAgent(default) EXCEPTION (Sun Jul 06 18:05:50 PDT 2008): Was unable to reach server.. Stack trace should follow.
            18:05:50,317 ERROR [STDERR] java.io.IOException: Was unable to reach server.
            18:05:50,317 ERROR [STDERR]      at org.drools.agent.URLScanner.hasChanged(URLScanner.java:145)
            18:05:50,317 ERROR [STDERR]      at org.drools.agent.URLScanner.getChangeSet(URLScanner.java:109)
            18:05:50,317 ERROR [STDERR]      at org.drools.agent.URLScanner.loadPackageChanges(URLScanner.java:88)
            18:05:50,317 ERROR [STDERR]      at org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:330)
            18:05:50,317 ERROR [STDERR]      at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:298)
            18:05:50,317 ERROR [STDERR]      at org.drools.agent.RuleAgent.configure(Ru
            .
            .
            



            It seems interpolation is not happening as I have a breakpoint in the getWebServerURL function and it never gets in there during execution. In addition, I dont know why the duplication of the el expression, i.e., #{serverInfo.webServerURL}#{serverInfo.webServerURL}


            Any Ideas???

            • 3. Re: how to inject into components.xml?
              John McClain Newbie

              Please ignore reference to serverInfoTest - it is actually correct as serverInfo