Layer7 API Management

 View Only
  • 1.  Custom Assertion: ClassNotFoundException - JDBC Driver

    Posted Aug 15, 2018 10:46 AM



    I'm developing a Custom Assertion for the CA API Gateway that uses the jdbc Driver to connect to a database. The first version of the Custom Assertion did not has a custom UI. I just used the default one, that is created by the Gateway.


    The current version should have its' own custom UI. I want to collect and check the database parameters in this UI. When I try to establish the connection i get the following Exception:



    Message: com.mysql.jdbc.Driver


    com.l7tech.console.util.CustomAssertionClassLoader.findClass(Unknown Source)



    java.lang.Class.forName()(Native Method)


    com.l7tech.custom.xmlassertion.Database.<init>(Unknown Source)

    com.l7tech.custom.xmlassertion.Database.getInstance(Unknown Source)

    com.l7tech.custom.xmlassertion.MainWindow$2.actionPerformed(Unknown Source)





    Obviously the jdbc Driver cannot be loaded. I tried to add the mysql-jdbc-connector to the ANT Buildfile of the project without success. Here is my code:


    btn_test_connection.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

    String ip = jT_db_ip.getText();
    String port = jT_db_port.getText();
    String user = jT_db_user.getText();
    char[] password = jP_password.getPassword();
    String name = jT_db_name.getText();

    if (
    ip.length() == 0 ||
    port.length() == 0 ||
    user.length() == 0 ||
    password.length == 0 ||
    name.length() == 0
    ) {
    JOptionPane.showMessageDialog(MainWindow.this, "All fields must be filled!", "Warning", HEIGHT);
    } else {
    try {
    Database.getInstance(ip, port, name, user, new String(password));
    jL_status.setText("Connection successfully established.");
    catch (Exception ex) {
    jL_status.setText("Connection could not be established.");
    String stack = "";
    for (int i = 0; i < ex.getStackTrace().length; i++) {
    stack += ex.getStackTrace()[i] + "\n";
    JOptionPane.showMessageDialog(MainWindow.this, "Error Message:\n" + ex.getMessage() + "\nStacktrace:\n" + stack, ex.getClass().toString(), HEIGHT);



    public class Database {

    private static Connection connection = null;

    private Database(String databaseIP, String databasePort, String databaseName, String databaseUser, String databasePassword) throws SQLException, ClassNotFoundException {
    XML_AssertionServiceInvocation.logger.config("CUSTOM ASSERTION [XML_Assertion]: Loading JDBC driver");
    Class.forName("com.mysql.jdbc.Driver"); // Datenbanktreiber fuer JDBC Schnittstellen laden.
    Properties connectionProperties = new Properties();
    connectionProperties.put("autoReconnect", "true");

    // Verbindung zur JDBC-Datenbank herstellen.
    connection = DriverManager.getConnection("jdbc:mysql://" + databaseIP + ":" + databasePort + "/" + databaseName + "?" + "user="
    + databaseUser + "&" + "password=" + databasePassword, connectionProperties);

    public static Connection getInstance(String databaseIP, String databasePort, String databaseName, String databaseUser, String databasePassword) throws SQLException, ClassNotFoundException {
    if (connection == null) {
    new Database(databaseIP, databasePort, databaseName, databaseUser, databasePassword);
    return connection;



    As i mentioned, before the UI was added everything worked just fine.


    I hope you guys have any ideas.


    Best Regards


  • 2.  Re: Custom Assertion: ClassNotFoundException - JDBC Driver
    Best Answer

    Broadcom Employee
    Posted Aug 22, 2018 01:58 AM

    Hello Lucas,


    I believe the jdbc Driver class shouldn't be used in the CustomAssertion bean side (custom UI side).
    It is instantiated on the Policy Manager, not on the API Gateway nodes.
    The DB connection parameters need to be stored in context variables or somewhere else on the Policy Manager and actual DB connection(s) should be established at the runtime.


    Best regards,

  • 3.  Re: Custom Assertion: ClassNotFoundException - JDBC Driver

    Posted Aug 22, 2018 03:36 AM

    Hello Seiji,


    i tried to insantiate the connection in the ServiceInvocation part and that worked. Thank You for that.


    The idea why i wanted to instantiate the connection in the UI part is that i want to check the connection before you can go on. Any ideas how i should do that in the UI?


    Best regards,


  • 4.  Re: Custom Assertion: ClassNotFoundException - JDBC Driver

    Broadcom Employee
    Posted Aug 22, 2018 05:04 AM

    I took a quick look at sample code (Salesforce Connector) and found the CustomExtensionInterfaceBinding class could be used for the purpose.

    It is described in the javadoc like this:


    CustomExtensionInterfaceBinding (Layer 7 External API)

    • public class CustomExtensionInterfaceBinding<T>extends Object
      Describes an available implementation of an custom extension interface. These are interfaces that the custom assertion can register on the Gateway, and the corresponding Policy Manager code can invoke server side methods of these interfaces via the Console Context.

      For example, a Custom Assertion connector may have its GUI classes invoke methods on an extension interface in order to test the configuration settings to an external system.


    Does it work for you?


    Best regards,


  • 5.  Re: Custom Assertion: ClassNotFoundException - JDBC Driver

    Posted Sep 05, 2018 03:47 AM

    This is working so far and i guess it is the solution.

    I'm now struggling with registering the CustomExtensionInterface. It always says that there is no ExtensionInterface registered although i did all the steps that are listed here: Using the CustomExtensionInterfaceFinder Object - CA API Gateway - 9.2 - CA Technologies Documentation 

    I also checked the SalesForce Sample Custom Assertion and did like that. But it does not work.