Reputation: 55957
The simple problem is: how do I make a Java Resource bundle available to code in Java JAR that is accessed from a Worklight adapter? I think that this amounts to: what is the classpath used by the Java beneath a Worklight adapter?
Reason: we use a third-party Java library that communicates with a particular enterprise service, it has it's own configuration mechanism to determine that service's location, that mechanism uses resource bundles.
We put the library JARs in the server/lib folder and successfully can invoke the library code from the adapter:
manager = com.third.party.manager.getInstance();
// manager is correctly obtained
token = manager.talkToServer();
// this fails with an error indicating that the server location is unknown
We see that the third party code attempts to use exactly this pattern, in particular the3 varient of getBundle() is as shown here:
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("ThirdParty");
Enumeration<String> enumeration = bundle.getKeys();
while (enumeration.hasMoreElements()){
String str = enumeration.nextElement();
System.out.println("property " + str);
//etc
Now, I was expecting to package my resource bundle in the base of a new JAR file and add it to the server/lib and have it picked up. I created that resource JAR file, containing
ThirdParty.properties
and as a test created a little Java application containing the above code, and added the resource JAR to that application's classpath; the bundle we loaded as expected.
I then converted that Java to adapter code:
var bundle = java.util.ResourceBundle.getBundle("ThirdParty");
var enumeration = bundle.getKeys();
while (enumeration.hasMoreElements())
{
var str = enumeration.nextElement();
var val = bundle.getString(str);
}
Add my property JAR file to server/lib and get an exception telling me the bundle cannot be found.
Suggestions for a better classpath?
Upvotes: 0
Views: 571
Reputation: 3166
I've just tried it and everything worked just fine. Steps I tried to recreate the issue:
Created adapter, added following procedure
function test(){
return {
data: com.anton.PropGetter.getProp("name")
};
}
Created PropGetter.java class under com.anton package with following code
package com.anton;
import java.util.ResourceBundle;
public class PropGetter {
public static String getProp(String propName){
ResourceBundle bundle = ResourceBundle.getBundle("props");
return propName + " :: " + bundle.getString(propName);
}
}
Tested adapter procedure, got following output:
{
"data": "name :: anton",
"isSuccessful": true
}
Upvotes: 2