url, clientId, tmpDir);
client = new MqttClient(url, clientId, dataStore);
client.setCallback(this);
}
MqttConnectOptions options = new MqttConnectOptions();
if (!StringUtils.isBlank(user)) {
options.setUserName(user);
}
if (!StringUtils.isBlank(password)) {
options.setPassword(password.toCharArray());
}
if (url.toLowerCase().contains("ssl")) {
if (StringUtils.isNotBlank(System
.getProperty("com.ibm.ssl.protocol"))) {
// get all com.ibm.ssl properties from the system properties
// and set them as the SSL properties to use.
Properties sslProps = new Properties();
addSystemProperty("com.ibm.ssl.protocol", sslProps);
addSystemProperty("com.ibm.ssl.contextProvider", sslProps);
addSystemProperty("com.ibm.ssl.keyStore", sslProps);
addSystemProperty("com.ibm.ssl.keyStorePassword", sslProps);
addSystemProperty("com.ibm.ssl.keyStoreType", sslProps);
addSystemProperty("com.ibm.ssl.keyStoreProvider", sslProps);
addSystemProperty("com.ibm.ssl.trustStore", sslProps);
addSystemProperty("com.ibm.ssl.trustStorePassword", sslProps);
addSystemProperty("com.ibm.ssl.trustStoreType", sslProps);
addSystemProperty("com.ibm.ssl.trustStoreProvider", sslProps);
addSystemProperty("com.ibm.ssl.enabledCipherSuites", sslProps);
addSystemProperty("com.ibm.ssl.keyManager", sslProps);
addSystemProperty("com.ibm.ssl.trustManager", sslProps);
options.setSSLProperties(sslProps);
} else {
// use standard JSSE available in the runtime and
// use TLSv1.2 which is the default for a secured mosquitto
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null,
new TrustManager[] { getVeryTrustingTrustManager() },
new java.security.SecureRandom());
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
options.setSocketFactory(socketFactory);
}
}
if (lastWill != null) {
options.setWill(lastWill.getTopic(), lastWill.getPayload(),
lastWill.getQos(), lastWill.isRetain());
}
options.setKeepAliveInterval(keepAliveInterval);
client.connect(options);
}