App Connect

Expand all | Collapse all

Query a user defined policy in esql

  • 1.  Query a user defined policy in esql

    Posted Wed November 25, 2020 12:36 PM
    As per IBM knowledge centre as shown the link below that we are able to create a esql function to get the user defined policy.
    ​https://www.ibm.com/support/knowledgecenter/SSTTDS_11.0.0/com.ibm.etools.mft.doc/ac06008_.html


    CREATE FUNCTION getPolicyProperty( IN policyName CHARACTER, IN propertyName CHARACTER )
      RETURNS CHARACTER
      LANGUAGE JAVA
      EXTERNAL NAME "MyPolicyAccessClass.getPolicyProperty";

    DECLARE Property2 CHARACTER:
    SET Property2=getPolicyProperty('{PP1}:MyUDCS', 'prop2');


    I couldn't figure out how to create a java class MyPolicyAccessClass that has a static method getPolicyProperty, which java class in the run time library MyPolicyAccessClass extends, I don't think it should be MbJavaComputeNode or MbNode, any advise?

    Thanks,
    andy

    ------------------------------
    Andy Mao
    ------------------------------


  • 2.  RE: Query a user defined policy in esql

    Posted Wed November 25, 2020 01:38 PM
    Edited by Martin Citron Wed November 25, 2020 01:39 PM
    Hi Andy,

    I would try to create custom JAVA class which will retrive policy property.

    For writing JAVA see https://www.ibm.com/support/knowledgecenter/SSTTDS_11.0.0/com.ibm.etools.mft.doc/ak04970_.html

    Mapping of ESQL and JAVA types can be found here https://www.ibm.com/support/knowledgecenter/SSTTDS_11.0.0/com.ibm.etools.mft.doc/ak20708_.html

    JAVA class itself might look like this:
    package test;
    
    import com.ibm.broker.plugin;
    
    class PolicyReader{
     public static String getPolicyProperty(String policyName, String propertyName) {  
      MbPolicy myPol = MbPolicy.getPolicy("UserDefined", policyName);
      return myPol.getPropertyValueAsString(propertyName);
     }
    }
    
    
       ​

    And ESQL:
    CREATE FUNCTION getPolicyProperty( IN policyName CHARACTER, IN propertyName CHARACTER )
      RETURNS CHARACTER
      LANGUAGE JAVA
      EXTERNAL NAME "test.PolicyReader.getPolicyProperty";
    
    DECLARE Property2 CHARACTER:
    SET Property2=getPolicyProperty('{PP1}:MyUDCS', 'prop2');​


    ------------------------------
    Martin Citron
    Prague
    ------------------------------



  • 3.  RE: Query a user defined policy in esql

    Posted Wed November 25, 2020 05:04 PM
    Hi Martin,

    Thanks for your input, your code works like a charm. I really appreciate it. 

    Best Regards,

    andy

    ------------------------------
    Andy Mao
    ------------------------------



  • 4.  RE: Query a user defined policy in esql

    Posted Thu December 24, 2020 06:39 AM

    Hi Martin and Andy.

    In order to reuse this procedure, I tried to put JavaComputeNode in a sharedlib and use it using an eSQL code in an API project, but I couldn't. I get errors that the java class cannot be found. Do you know how to solve this? I saw that it has to do with classloader, but I didn't find anything of reference to solve this.

    I used it in API projects and it works very well.

    Thanks,
    Dantas



    ------------------------------
    Márcio Dantas
    ------------------------------



  • 5.  RE: Query a user defined policy in esql

    Posted 29 days ago

    Hi Márcio

    In chapter Shared libraries and Java files it is explained like this:

    "ESQL code in applications or shared libraries can also call static Java methods in referenced shared libraries by using the shared library qualifier in the CLASSLOADER clause. For more information, see Java routine example 4 in CREATE PROCEDURE statement."

    Regards
    Daniel



    ------------------------------
    Daniel Steinmann
    ------------------------------



  • 6.  RE: Query a user defined policy in esql

    Posted 28 days ago

    Hi Márcio

    The chapter Shared libraries and Java files has following info:

    "ESQL code in applications or shared libraries can also call static Java methods in referenced shared libraries by using the shared library qualifier in the CLASSLOADER clause. For more information, see Java routine example 4 in CREATE PROCEDURE statement."

    Regards,
    Daniel



    ------------------------------
    Daniel Steinmann
    ------------------------------



  • 7.  RE: Query a user defined policy in esql

    Posted 21 days ago
    Hi Marcio,

    I have the esql function defined in the shared Lib and then creating a java project to have the static java method.  In the shared Lib, make a project reference to this java project.  Give it a try. thx.

    ------------------------------
    Andy Mao
    ------------------------------