spring – read certificate from java trust store in connection mqtt with springboot

I have a question. I have to connect my spring application with a broker mqtt throught an ssl connection. I have inserted the certificate of the broker in my java trust store. the method I use to connect to the broker is this:

public MqttClient mqttClient() throws Exception {
MqttClient client = new MqttClient(BROKER_URL, CLIENT_ID);

    MqttConnectOptions options = new MqttConnectOptions();
    options.setCleanSession(true);

    // configure SSL
    SSLContext sslContext = getSSLContext();
    options.setSocketFactory(sslContext.getSocketFactory());

    client.connect(options);
    return client;
}```

now I have to write the getSslContext() method to read the certificte from the keystore. Someone can help me on how i can do this? thanks you very much!

Someone can help me to write the getSslContext?

Read more here: Source link