Saturday, April 24, 2021

[Ballerina] ClassNotFoundException NoClassDefFoundError when upgrading ballerina distribution

I was working with a simple SQL query. The only change I did was upgrading the Ballerina distribution from slalpha3 to slalpha4. I got the following error.

[2021-04-20 18:15:15,527] SEVERE {b7a.log.crash} - ballerinax/mysql/0_7_0-alpha7/$ConfigurationMapper
java.lang.NoClassDefFoundError: ballerinax/mysql/0_7_0-alpha7/$ConfigurationMapper
    at suhan.expose_mysql_data.0_1_0.$ConfigurationMapper.$configureInit(Unknown Source)
    at suhan.expose_mysql_data.0_1_0.$_init.main(expose_mysql_data)
Caused by: java.lang.ClassNotFoundException: ballerinax.mysql.0_7_0-alpha7.$ConfigurationMapper
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 2 more


Reason on slack channel.
from slalpha4, packages like mysql, java.jdbc which are categorized as ballerinax are not coming with the ballerina distribution. if ballerina user needs such dependencies, user can always download those packages from the central. I think this particular issue is coming from either the caching mechanism we used which is not getting up to date dependencies or erroneous package pushed to ballerina central.

Workaround is as follows.
Answer on slack channel - Fixed.
Clear cache at location ~/.ballerina/repositories/central.ballerina.io


Friday, April 23, 2021

[Ballerina] [HTTPS Listener] Cannot use a Direct Certificate File for Service Listener Configuration - Fix

OS: macOS Big Sur 11.1

Ballerina Version: slalpha4

For the listener side to enable SSL via certs and keys, we should provide the configurations keyFile and certFile. Ballerina supports key files in the format of pkcs8

Commands:

1. openssl req -x509 -newkey rsa:4096 -out cert.pem 2. copy-paste the content appearing in the terminal starting with -----BEGIN ENCRYPTED PRIVATE KEY----- and ending with -----END ENCRYPTED PRIVATE KEY----- to a file named privkey.pem 3. openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out pkcs8_key.pem

Sample https_listener.bal file.

import ballerina/http; http:ListenerConfiguration helloWorldEPConfig = { secureSocket: { key: { certFile: "../path/to/cert.pem", keyFile: "../path/to/pkcs8_key.pem" } } }; listener http:Listener helloWorldEP = new (9095, helloWorldEPConfig); service /hello on helloWorldEP { resource function get .() returns string { return "Hello World!"; } }

Run the ballerina file as follows.

suhan@Suhan httpslistener % bal run https_listener.bal Compiling source https_listener.bal Running executable [ballerina/http] started HTTPS/WSS listener 0.0.0.0:9095

Issue a cURL command as follows.

suhan@Suhan httpslistener % curl -k https://localhost:9095/hello Hello World!%