This content has been marked as final. Show 3 replies
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/22.214.171.124/myproperties.properties or cp://myproperties.properties
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
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.