The UserDefined configurable service is only accessible via a Java compute node. It cannot be accessed directly in ESQL. If you want to use ESQL, you need to create the code in Java and then use a function call to the Java code.
To set up the ESQL function call:
CREATE PROCEDURE getUserDefinedConfigServProp( IN P1 CHARACTER )
LANGUAGE JAVA
EXTERNAL NAME "com.ibm.broker.test.MyClass.getUserDefinedConfigServProp";
To call this procuedure:
DECLARE result CHARACTER getUserDefinedConfigServProp('test');
And the Java code could look something like this:
public static String getUserDefinedConfigServProp(String cs){
String rs = "exception occurred: ";
try{
BrokerProxy bp = BrokerProxy.getLocalInstance();
short c = 0;
while(!bp.hasBeenPopulatedByBroker()){
try{
c++; //loop count, in the rare case it fails, we need to leave the loop
Thread.sleep(100);
}catch(InterruptedException e){
return rs+e.toString();
}
if(c > 4)
return rs+"timed out";
}
try{
ConfigurableService udcs = bp.getConfigurableService("UserDefined", cs);
Properties props = udcs.getProperties();
String out = "";
for(String key : props.stringPropertyNames()){
out = out+key+"="+props.getProperty(key)+",";
}
if(out.length > 0)
rs=out.substring(0,out.length()-1);
else
rs=rs+"no properties returned"
}catch(ConfigManagerProxyPropertyNotInitializedException e){
return rs+e.toString();
}
}catch(ConfigManagerProxyLoggedException e){
return rs+e.toString();
}
return rs;
}
package bpmfacade.subflows;
import java.util.HashMap;
import java.util.Properties;
import com.ibm.broker.config.proxy.BrokerProxy;
import com.ibm.broker.config.proxy.ConfigManagerProxyLoggedException;
import com.ibm.broker.config.proxy.ConfigManagerProxyPropertyNotInitializedException;
import com.ibm.broker.config.proxy.ConfigurableService;
import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbOutputTerminal;
import com.ibm.broker.plugin.MbUserException;
public class ReadConfiguration extends MbJavaComputeNode {
public HashMap<String,String> getUserDefinedConfigServProp(String[] keys){
String rs = "exception occurred: ";
BrokerProxy bp =null;
HashMap<String,String> properties = new HashMap<String,String>();
boolean cacheExists =false;
try{
for (String key : keys) {
if((rs = CacheManager.readFromCache("BPMConfigCache", key)) != null)
{
cacheExists = true;
properties.put(key, rs);
}
}
if(cacheExists == false)
{
// If it does not exist in the cache get it from config service
bp = BrokerProxy.getLocalInstance();
while(!bp.hasBeenPopulatedByBroker()) { Thread.sleep(100); }
for (String key : keys) {
// Check cache
if((rs = CacheManager.readFromCache("BPMConfigCache", key)) != null)
{
properties.put(key, rs);
}
else
{
try{
ConfigurableService udcs = bp.getConfigurableService("UserDefined",
"BPMFacadeConfiguration");
Properties props = udcs.getProperties();
String out = "";
out = props.getProperty(key);
if(out == "")
{
rs=rs + "no property returned";
}
else
{
rs = out;
}
// Insert into Cache
CacheManager.insertIntoCache("BPMConfigCache", key, rs);
}
catch(ConfigManagerProxyPropertyNotInitializedException e){
//return rs+e.toString();
}
properties.put(key, rs);
}
}
}
}
catch(ConfigManagerProxyLoggedException e){
//return rs+e.toString();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if(bp != null)
{
bp.disconnect();
}
}
return properties;
}
public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");
MbMessage inMessage = inAssembly.getMessage();
MbMessageAssembly outAssembly = null;
try {
// create new message as a copy of the input
MbMessage outMessage = new MbMessage(inMessage);
outAssembly = new MbMessageAssembly(inAssembly, outMessage);
// ----------------------------------------------------------
// Add user code below
String[] keys = {"Process_Server_URL", "User_Identity","User_Password", "Max_Users"};
HashMap<String,String> properties = getUserDefinedConfigServProp(keys);
String process_Server_URL = properties.get("Process_Server_URL");
String user_Identity = properties.get("User_Identity");
String user_Password = properties.get("User_Password");
String max_Users = properties.get("Max_Users");
MbMessage env = inAssembly.getGlobalEnvironment();
MbMessage lenv = inAssembly.getLocalEnvironment();
//MbMessage newEnv = new MbMessage(env);
env.getRootElement().createElementAsFirstChild(
MbElement.TYPE_NAME_VALUE,
"Process_Server_URL",
process_Server_URL);
env.getRootElement().createElementAsFirstChild(
MbElement.TYPE_NAME_VALUE,
"User_Identity",
user_Identity);
env.getRootElement().createElementAsFirstChild(
MbElement.TYPE_NAME_VALUE,
"User_Password",
user_Password);
env.getRootElement().createElementAsFirstChild(
MbElement.TYPE_NAME_VALUE,
"Max_Users",
max_Users);
outAssembly = new MbMessageAssembly(
inAssembly,
lenv,
inAssembly.getExceptionList(),
inAssembly.getMessage());
// End of user code
// ----------------------------------------------------------
} catch (MbException e) {
// Re-throw to allow Broker handling of MbException
throw e;
} catch (RuntimeException e) {
// Re-throw to allow Broker handling of RuntimeException
throw e;
} catch (Exception e) {
// Consider replacing Exception with type(s) thrown by user code
// Example handling ensures all exceptions are re-thrown to be handled in the flow
throw new MbUserException(this, "evaluate()", "", "", e.toString(),
null);
}
// The following should only be changed
// if not propagating message to the 'out' terminal
out.propagate(outAssembly);
}
}