当前位置: 首页>>代码示例>>Java>>正文


Java MQTT.setSslContext方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:17,代码来源:MQTTTestSupport.java

示例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);
	}
}
 
开发者ID:openQCM,项目名称:openQCM2,代码行数:31,代码来源:BiobrightClient.java

示例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;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:MqttCrlEnabledExample.java

示例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;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:MQTTSecurityCRLTest.java


注:本文中的org.fusesource.mqtt.client.MQTT.setSslContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。