Trying to get a JavaScript CBR rule function to instatiate a

Posted by Admin on 18-Sep-2009 11:15

Trying to get a JavaScript CBR rule function to instatiate a custom class in Sonic 7.5.2. I've added the jar for the class to the classpath of the container.

function rule () {

...

paramsHashMap = new java.util.HashMap(); // Works

...

java.lang.System.out.println("Trying to create an instance of MyFirstCustomService");   // Works

firstCustomService = new com.cerner.hie.raj.MyFirstCustomService();   // Fails - Exception trace follows

...

}

Exception trace:------------------------------------------------------------------------------------------------

Trying to create an instance of MyFirstCustomService
[09/09/18 10:57:00] ID=dev_ESBCore (severe) [Dispatch] Exception calling service dev.Transform: message rejected
[09/09/18 10:57:00] ID=dev_ESBCore (severe) Trace follows...
com.ibm.bsf.BSFException: JavaScript Error: Internal Error: ReferenceError: "com" is not defined.
at com.ibm.bsf.engines.javascript.JavaScriptEngine.handleError(JavaScriptEngine.java:182)
at com.ibm.bsf.engines.javascript.JavaScriptEngine.eval(JavaScriptEngine.java:87)
at com.sonicsw.xq.service.common.ScriptEvaluator.evaluateRule(Unknown Source)
at com.sonicsw.xq.service.common.RulesProcessor.evaluate(Unknown Source)
at com.sonicsw.xq.service.common.RulesProcessor.processRules(Unknown Source)
at com.sonicsw.xq.service.xform.Xformer.processRules(Unknown Source)
at com.sonicsw.xq.service.xform.TransformationService.service(Unknown Source)
at com.sonicsw.xqimpl.service.debug.DebugServiceInterceptor.intercept(Unknown Source)
at com.sonicsw.xqimpl.service.XQServiceChain$XQInterceptorServiceWrapper.intercept(Unknown Source)
at com.sonicsw.xqimpl.service.XQServiceChain$XQInterceptorServiceWrapper.service(Unknown Source)
at com.sonicsw.xqimpl.service.XQServiceChain.service(Unknown Source)
at com.sonicsw.xqimpl.service.ServiceMessageHandler.callService(Unknown Source)
at com.sonicsw.xqimpl.service.ServiceMessageHandler.handleMessage(Unknown Source)
at com.sonicsw.xqimpl.service.ProcessMessageHandler.doHandleMessage(Unknown Source)
at com.sonicsw.xqimpl.service.ProcessMessageHandler.handleMessage(Unknown Source)
at com.sonicsw.xqimpl.service.XQDispatcher.onMessage(Unknown Source)
at com.sonicsw.xqimpl.endpoint.container.EndpointContextContainer.onMessage(Unknown Source)
at com.sonicsw.xq.connector.jms.JMSEndpoint$JMSEndpointListener.onMessage(Unknown Source)
at progress.message.jimpl.Session.deliver(Session.java:2952)
at progress.message.jimpl.Session.run(Session.java:2358)
at progress.message.jimpl.Session$SessionThread.run(Session.java:2743)
com.sonicsw.xq.rules.EvaluatorException: Desired evaluation could not be performed: JavaScript Error: Internal Error: ReferenceError: "com" is not defined. (JavaScript Error: Internal Error: ReferenceError: "com" is not defined.) (JavaScript Error: Internal Error: ReferenceError: "com" is not defined.)
at com.sonicsw.xq.service.common.ScriptEvaluator.evaluateRule(Unknown Source)
at com.sonicsw.xq.service.common.RulesProcessor.evaluate(Unknown Source)
at com.sonicsw.xq.service.common.RulesProcessor.processRules(Unknown Source)
at com.sonicsw.xq.service.xform.Xformer.processRules(Unknown Source)
at com.sonicsw.xq.service.xform.TransformationService.service(Unknown Source)
at com.sonicsw.xqimpl.service.debug.DebugServiceInterceptor.intercept(Unknown Source)
at com.sonicsw.xqimpl.service.XQServiceChain$XQInterceptorServiceWrapper.intercept(Unknown Source)
at com.sonicsw.xqimpl.service.XQServiceChain$XQInterceptorServiceWrapper.service(Unknown Source)
at com.sonicsw.xqimpl.service.XQServiceChain.service(Unknown Source)
at com.sonicsw.xqimpl.service.ServiceMessageHandler.callService(Unknown Source)
at com.sonicsw.xqimpl.service.ServiceMessageHandler.handleMessage(Unknown Source)
at com.sonicsw.xqimpl.service.ProcessMessageHandler.doHandleMessage(Unknown Source)
at com.sonicsw.xqimpl.service.ProcessMessageHandler.handleMessage(Unknown Source)
at com.sonicsw.xqimpl.service.XQDispatcher.onMessage(Unknown Source)
at com.sonicsw.xqimpl.endpoint.container.EndpointContextContainer.onMessage(Unknown Source)
at com.sonicsw.xq.connector.jms.JMSEndpoint$JMSEndpointListener.onMessage(Unknown Source)
at progress.message.jimpl.Session.deliver(Session.java:2952)
at progress.message.jimpl.Session.run(Session.java:2358)

All Replies

Posted by Admin on 21-Sep-2009 08:39

firstCustomService = new Packages.com.cerner.hie.raj.MyFirstCustomService();

will do the trick. The magic is the Packages. prefix in front of the real package definition.

regards,

--- Margus

Posted by Admin on 21-Sep-2009 08:52

Thanks. That was the solution that Sonic support came up with after trying different things.

Posted by Bill Wood on 13-Oct-2009 07:43

A variation on this is to use the JavaScript function importPackage.  This will allow you to import all classes within a particular pkg and not have to fully qualify your name every time, if that is desirable to you.

importPackage(Packages.foo.bar.name)

// "Name" is a class within package foo.bar.name.

function whatever() {

     name = new Name();

}

Posted by Admin on 14-Oct-2009 10:16

Thanks. This will be helpful.

This thread is closed