本文整理汇总了Java中org.fusesource.mqtt.client.MQTT.setSslContext方法的典型用法代码示例。如果您正苦于以下问题:Java MQTT.setSslContext方法的具体用法?Java MQTT.setSslContext怎么用?Java MQTT.setSslContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fusesource.mqtt.client.MQTT
的用法示例。
在下文中一共展示了MQTT.setSslContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMQTTSslConnection
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private MQTT createMQTTSslConnection(String clientId, boolean clean) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setConnectAttemptsMax(1);
mqtt.setReconnectAttemptsMax(0);
mqtt.setTracer(createTracer());
mqtt.setHost("ssl://localhost:" + port);
if (clientId != null) {
mqtt.setClientId(clientId);
}
mqtt.setCleanSession(clean);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(new KeyManager[0], new TrustManager[]{new DefaultTrustManager()}, new SecureRandom());
mqtt.setSslContext(ctx);
return mqtt;
}
示例2: connect
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
public void connect() {
MQTT mqtt = new MQTT();
try {
mqtt.setHost(connectionInfo.getBiobrightUrl());
mqtt.setUserName(connectionInfo.getBiobrightUserName());
mqtt.setPassword(connectionInfo.getBiobrightPassword());
// TODO change security policy that is actually disabled with this code.
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
mqtt.setSslContext(sslContext);
logger.info("Opening MQTT socket.. ");
connection = mqtt.blockingConnection();
logger.info("Opened MQTT socket, connecting.. ");
connection.connect();
logger.info("Connected MQTT socket.. ");
} catch (Exception e) {
logger.error("connect()", e);
if(connection != null) {
connection = null;
}
throw new RuntimeException("Connection failed.", e);
}
}
示例3: retrieveMQTTConnection
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private static BlockingConnection retrieveMQTTConnection(String host, String truststorePath, String truststorePass, String keystorePath, String keystorePass) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setConnectAttemptsMax(0);
mqtt.setReconnectAttemptsMax(0);
mqtt.setHost(host);
mqtt.setSslContext(SSLSupport.createContext("JKS", keystorePath, keystorePass, "JKS", truststorePath, truststorePass));
mqtt.setCleanSession(true);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
return connection;
}
示例4: retrieveMQTTConnection
import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private BlockingConnection retrieveMQTTConnection(String host, String truststorePath, String truststorePass, String keystorePath, String keystorePass) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setConnectAttemptsMax(1);
mqtt.setReconnectAttemptsMax(0);
mqtt.setHost(host);
SSLContext sslContext = SSLSupport.createContext(TransportConstants.DEFAULT_KEYSTORE_PROVIDER, keystorePath, keystorePass, TransportConstants.DEFAULT_TRUSTSTORE_PROVIDER, truststorePath, truststorePass);
mqtt.setSslContext(sslContext);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
return connection;
}