11 Replies Latest reply on May 30, 2008 8:18 AM by blep

    Custom action config file

    blep Newbie

      Hi!

      I'm actually trying to make my own custom action but it needs several configuration files to startup, so consider the following esb archive file schema:

      / - META-INF
      | |______ jboss-esb.xml
      | |______ deployment.xml
      |__ mypackage/MyCustomAction
      |__ cfg
       |__ cfg1.xml
       |__ cfg2.xml
      


      and in the jboss-esb.xml file :

      [...]
      <action name="myAction" class="mypackage.MyCustomAction">
       <property name="config1" value="/cfg/cfg1.xml" />
       <property name="config2" value="/cfg/cfg2.xml" />
      </action>
      [...]


      I can get the attributes from the config tree object during initialization but I'm not actually able to open these files to access content.

      Thanks for help!

        • 1. Re: Custom action config file
          Tom Fennelly Master

          How are you trying to open these resource? Does the actual .esb deployment contain these cfg resource in the location you identified?

          • 2. Re: Custom action config file
            blep Newbie

            Yes I try : of course, if I open a stream with "/cfg/cfg1.xml" as , it attempts to open a file in c:/cfg/cfg1.xml and if I try to get it from resources loaded by the context class loader, it returns a null object.

            I checked with an archive manager, the directory and the files are there.

            • 3. Re: Custom action config file
              Tom Fennelly Master

              Please show us the actual code you're using to open a stream to the resource.

              • 4. Re: Custom action config file
                blep Newbie

                My custom action is :

                public class WrapSxmlESB extends AbstractActionLifecycle{
                [...]
                //constructor
                 public WrapSxmlESB(ConfigTree cfg) throws Exception{
                 log.info("Entering WrapSxmlESB");
                
                 resourcesHref = cfg.getAttribute("resourceRef");
                
                 log.info("configHref = " + configHref);
                 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(configHref);
                 try{
                 log.info("available : " + is.available());
                 }catch (NullPointerException e) {
                 log.info("Is null by context class loader!!!!!");
                 }
                
                 try{
                 is = new FileInputStream(configHref);
                 log.info("available : " + is.available());
                 }catch (FileNotFoundException e) {
                 log.info("File not found by input stream!!!!!");
                 }
                
                 log.info("Outing WrapSxmlESB");
                 }
                [...]
                


                My jboss-esb.xml contains:

                [...]
                 <action name="action2" class="com.thales.poc.servingxml.WrapSxmlESB">
                 <property name="resourceRef" value="/cfg/fic-resource.xml"/>
                 <property name="configRef" value="/cfg/servingxml.xml"/>
                 </action>
                [...]
                


                The ESB archive :
                $ jar tf embed_servingxml.esb | grep cfg
                cfg/
                cfg/FIC00002.txt
                cfg/fic-resource.xml
                cfg/out.xml
                cfg/servingxml.xml
                


                The JBoss logs during deployment :

                13:23:44,682 INFO [JBoss4ESBDeployer] create esb service, embed_servingxml.esb
                13:23:44,776 INFO [embed_servingxml] Bound to JNDI name: queue/embed_servingxml
                13:23:44,823 WARN [ScheduleMapper] Attrubute 'poll-frequency-seconds' is DEPRECATED. Please change your configuration to use 'schedule-frequency'.
                13:23:44,823 INFO [AbstractFileGateway] No value specified for: max-millis-for-response - This will be an 'inbound-only' gateway
                13:23:44,854 INFO [WrapSxmlESB] Entering WrapSxmlESB
                13:23:44,854 INFO [WrapSxmlESB] configHref = /cfg/servingxml.xml
                13:23:44,854 INFO [WrapSxmlESB] Is null by context class loader!!!!!
                13:23:44,854 INFO [WrapSxmlESB] File not found by input stream!!!!!
                13:23:44,854 INFO [WrapSxmlESB] Outing WrapSxmlESB
                


                I'm quite sure it's a newbie issue!

                • 5. Re: Custom action config file
                  Tom Fennelly Master

                  Could be a scoping issue. Kev?

                  Have you tried using the class classloader i.e. just doing 'getClass().getResourceAsStream("/cfg/servingxml.xml")'?

                  • 6. Re: Custom action config file
                    blep Newbie

                    It works!!

                    Why did I look for a complex way instead of using a simple one??

                    Thank you very much for your help.

                    • 7. Re: Custom action config file
                      Kevin Conner Master

                      It shouldn't have been a scoping issue as the context classloader would have been initialised before the lifecycle was created.

                      Could you wrap this into a simple testcase and send it to me? I would like to understand what is going on.

                      • 8. Re: Custom action config file
                        Kevin Conner Master

                        Sorry, should have spotted the reason for this.

                        When asking a classloader for a resource it should not start with a leading '/'. If you change your resource from /cfg/servingxml.xml to cfg/servingxml.xml then it will work correctly with the context classloader.

                        • 9. Re: Custom action config file
                          blep Newbie

                          I just tried with the test case I sent you and it's exactly the same.

                          FYI

                          • 10. Re: Custom action config file
                            Kevin Conner Master

                            Your test case had a bug in it, it was using the wrong method from Classloader.

                            You need to change the method to use getResourceAsStream instead of getSystemResourceAsStream.

                            The code you pasted here was correct though.

                            • 11. Re: Custom action config file
                              blep Newbie

                              Right, I just checked.

                              Sorry for that!