3 Replies Latest reply on Jun 10, 2012 8:40 AM by Brian.Dueck-Oracle

    [OSM] Reading a .properties file with Xquery

      Hello experts!

      I need to read a .properties file using xquery (implemented in an automated task) so that I can put together an URL, which is the endpoint of a webservice.
      The first thing that came to my mind was to write a class in java since I really don't know of any nice way of reading a .properties file with xquery itself.
      I know you can invoke a method of a java class by declaring the class first like this:

      declare namespace math = "java:java.lang.Math"

      And then you can simply write, for example:


      What I would like to know now is what do I have to do so that instead of the Math class, I can use my own class.
      I tried (but failed) by writing a simple class (test.java), under the /src folder in the cartridge, which extendes java.lang.Object and putting it in the xquery like this:

      declare namespace test = "java:java.lang.Object.test"

      I get this error:

      <06-Jun-2012 10:33:46,747 PDT AM> <ERROR> <rule.XQueryHelper> <ExecuteThread: '14' for queue: 'oms.automation'> <Cannot find a matching 1-argument function named {java:java.lang.Object.test}method1(). . File[null (actual location resolved to [])] Line[9] Column[-1]

      Any help is more than welcomed!
        • 1. Re: [OSM] Reading a .properties file with Xquery
          The easiest way to access a .properties file from XQuery inside OSM is to use a Data Provider entity with the Property File adapter. A Data Provider lets you access data through a variety of mechanisms (SOAP, JDBC, XML Files on a URL, Properties files, etc.) in a declarative way with support for caching etc.

          You can write your own adapters but we also provide a built in one for .properties files. You can use the Data Provider wizard to create a new Data Provider entity and choose the "Property File" provider type. On the interface tab, just enter the URL for the .properties file you wish to reference (and remember that the URL will be transformed using any XML Catalogs you have defined in your cartridge as well).

          Once you have done that you can declare a Data Instance on your XQuery (wherever that is in the model) which references the Data Provider you just created.

          The property type adapter returns a properties file in the following format:

          <properties> <comment>myprops.properties</comment> <entry key="mykey">myvalue</entry> <entry key="myotherkey">myothervalue</entry>

          So from within your XQuery, you would just do the following:


          Hope this helps. Also, given your original scenario involves calling a SOAP WS adapter, you should probably look into using the built in SOAP Adapter as well.

          BTW, if you really do want to just call a Java class then all you have to do is put your Java class an any jars it depends upon within the resources folder of your cartridge and redeploy. The contents of the resources folder are automatically added to the classpath of anything that is within your cartridge. So it would be available to any XQuery trying to load Java.

          You could also put your web service .properties file in the resources dir and reference it using the following url: osmmodel://myCartridgeNamespace/ or cp://myproperties.properties

          • 2. Re: [OSM] Reading a .properties file with Xquery
            Excellent info, Brian! This really helps!

            First of all, let me tell you (and anyone interested in the answer to my original post) that I have managed to call a java method by writting a java class (in a .java file) and putting it under the /src folder in the cartridge. The method you invoke from xquery (myclass:method()) must be a method of the class you wrote and must be a "public static" method. That did the trick.

            Now I have a couple of doubts regarding the Data Provider. I managed creating one in DS. Now I want to know how to declare a data instance of that data provider in my xquery.
            I mean, when you write:


            I asume that 'MyProperties' is the declared instance. I want to know how to declare this instance in an xquery that's a "xquery automator" in an automated task. I've seen you can declare Data Instances in DS in other elements where you use xquery and have a "Data Instance" tab (i.e Order Data Rule under Order Recognition Rule). But this "Data Instance" tab isn't present in the properties of the automation. So, I'm assuming you would have to declare the instance in the xquery code.

            The same would apply for the Data Provider using the SOAP type. If you have any example on how to use this with an xquery, it would be awesome!
            Thanks for everything! :)


            Edited by: Fernando_arg on Jun 7, 2012 2:36 PM
            • 3. Re: [OSM] Reading a .properties file with Xquery
              Hi Fernando;

              Glad you are making progress. Yes, putting your custom class in the src folder would cause that class to be compiled by Design Studio and automatically added to the deployed version of the resources folder (and therefore on the classpath for any automation plugins).

              OSM uses XQuery in a variety of situations as you are probably well aware and also supports Data Providers in all areas where XQuery is enabled, save one - Automation Plugins.

              So, for Automation Plugins that are XQuery or non-XQuery based you can not access a Data Provider from these plugins. Please file an SR with Oracle to request this enhancement if you would like to see this enhanced.