3 Replies Latest reply: Jan 15, 2013 4:01 AM by LukeStudley RSS

    OPA custome function

    924724
      Hi,

      I have created custom function for opa and added extensions.xml and jar file in the rulebase extensions folder but am getting below error.

      My custom java class

      package com.opa.customefunction.examples;

      import com.oracle.determinations.engine.CustomFunction;
      import com.oracle.determinations.engine.EntityInstance;

      public class AddNumbers extends CustomFunction {

           public AddNumbers() {

           }

           @Override
           public Object evaluate(EntityInstance arg0, Object[] arg1) {
                String number1 = arg1[0].toString();
                String number2= arg1[1].toString();
                int result = Integer.parseInt(number1) + Integer.parseInt(number2);
                return result;
           }

      }

      extension.xml file

      <extension>
      <functions>
      <function name="AddTwoNumbers" return-type="number">
      <arg name="value1" type="number"/>
      <arg name="value2" type="number"/>

      <handler platform="java"
      class="com.opa.customefunction.examples.AddNumbers"/>
      </function>
                <function name="Capitalize" return-type="text">
      <arg name="entered-name" type="text"/>

      <handler platform="java"
      class="com.oracle.determinations.examples.CapitalizeFunction"/>

      </function>

      <function name="DefaultNumber" return-type="number">
      <arg name="value" type="number"/>
      <arg name="default" type="number"/>

      <handler platform="java"
      class="com.oracle.determinations.examples.DefaultFunction"/>

      </function>
      </functions>
      </extension>



      Caused by: com.oracle.determinations.engine.local.CustomComponentException: Unable to create instance of com.opa.customefunction.examples.AddNumbers
           at com.oracle.determinations.engine.local.RulebaseLoader.loadCustomFunctions(RulebaseLoader.java:269)
           at com.oracle.determinations.engine.local.RulebaseLoader.loadRulebase(RulebaseLoader.java:178)
           at com.oracle.determinations.interview.engine.InterviewRulebase.<init>(InterviewRulebase.java:137)
           ... 23 more
      Caused by: java.lang.ClassNotFoundException: com.opa.customefunction.examples.AddNumbers
           at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
           at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
           at java.lang.ClassLoader.findSystemClass(ClassLoader.java:916)
           at com.oracle.determinations.engine.local.CustomResourceClassLoader.findClass(CustomResourceClassLoader.java:117)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Class.java:247)
           at com.oracle.determinations.util.PlatformClassLoader.newInstance(PlatformClassLoader.java:61)
           at com.oracle.determinations.engine.local.RulebaseLoader.loadCustomFunctions(RulebaseLoader.java:267)
           ... 25 more