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


Java MqttSecurityException类代码示例

本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttSecurityException的典型用法代码示例。如果您正苦于以下问题:Java MqttSecurityException类的具体用法?Java MqttSecurityException怎么用?Java MqttSecurityException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MqttSecurityException类属于org.eclipse.paho.client.mqttv3包,在下文中一共展示了MqttSecurityException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subscribe

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
private void subscribe ( final Session session, final MqttItemToTopic itemToTopic ) throws InvalidSessionException, InvalidItemException, MqttSecurityException, MqttException
{
    this.executor.submit ( new Callable<Void> () {
        @Override
        public Void call () throws Exception
        {
            logger.trace ( "subscribe () called with {}", itemToTopic );
            if ( itemToTopic.isWritable () )
            {
                logger.trace ( "subscribe () called on topic '{}'", makeWriteTopicName ( itemToTopic ) );
                MqttExporter.this.client.subscribe ( makeWriteTopicName ( itemToTopic ) );
                MqttExporter.this.itemsToWriteTopics.put ( itemToTopic.getItemId (), makeWriteTopicName ( itemToTopic ) );
            }
            if ( itemToTopic.isReadable () )
            {
                MqttExporter.this.hive.subscribeItem ( session, itemToTopic.getItemId () );
                MqttExporter.this.itemsToReadTopics.put ( itemToTopic.getItemId (), makeReadTopicName ( itemToTopic ) );
            }
            return null;
        }
    } );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:MqttExporter.java

示例2: waitForCompletion

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
/**
 * @see org.eclipse.paho.client.mqttv3.IMqttToken#waitForCompletion(long)
 */
@Override
public void waitForCompletion(long timeout) throws MqttException,
    MqttSecurityException {
  synchronized (waitObject) {
    try {
      waitObject.wait(timeout);
    }
    catch (InterruptedException e) {
      // do nothing
    }
    if (!isComplete) {
      throw new MqttException(MqttException.REASON_CODE_CLIENT_TIMEOUT);
    }
    if (pendingException != null) {
      throw pendingException;
    }
  }
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:22,代码来源:MqttTokenAndroid.java

示例3: getSSLSocketFactory

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
/**
 * Get the SSLSocketFactory using SSL key store and password
 * <p>
 * A convenience method, which will help user to create a SSLSocketFactory
 * object
 * </p>
 * 
 * @param keyStore
 *            the SSL key store which is generated by some SSL key tool,
 *            such as keytool in Java JDK
 * @param password
 *            the password of the key store which is set when the key store
 *            is generated
 * @return SSLSocketFactory used to connect to the server with SSL
 *         authentication
 * @throws MqttSecurityException
 *             if there was any error when getting the SSLSocketFactory
 */
public SSLSocketFactory getSSLSocketFactory (InputStream keyStore, String password) throws MqttSecurityException {
 try{
	 SSLContext ctx = null;
	 SSLSocketFactory sslSockFactory=null;
	 KeyStore ts;
	 ts = KeyStore.getInstance("BKS");			
	 ts.load(keyStore, password.toCharArray());
	 TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
	 tmf.init(ts);
	 TrustManager[] tm = tmf.getTrustManagers();
	 ctx = SSLContext.getInstance("TLSv1");
	 ctx.init(null, tm, null);
	 
	 sslSockFactory=ctx.getSocketFactory();
	 return sslSockFactory;
	 
	} catch (KeyStoreException | CertificateException | IOException | NoSuchAlgorithmException | KeyManagementException e) {
		throw new MqttSecurityException(e);
	}
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:39,代码来源:MqttAndroidClient.java

示例4: doMain

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
public void doMain(String... args) throws MqttSecurityException,
		MqttException, InterruptedException {
	CmdLineParser cmdLineParser = new CmdLineParser(this);
	try {
		cmdLineParser.parseArgument(args);
	} catch (CmdLineException e) {
		System.err.println(e.getMessage());
		cmdLineParser.printUsage(System.err);
		return;
	}

	connectToMqttBroker();
	try {
		wait4ever();
	} finally {
		close();
	}

}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:20,代码来源:MqttMain.java

示例5: generatesBrokerEventOnDigitalPinChange

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void generatesBrokerEventOnDigitalPinChange()
		throws InterruptedException, MqttSecurityException, MqttException,
		IOException {

	int pin = 1;
	this.client.setThrottleMillis(0);
	this.client.setAnalogs();
	this.client.setDigitals(pin);

	startAsync(client);
	simulateArduinoToMqtt(alpProtocolMessage(DIGITAL_PIN_READ).forPin(pin)
			.withValue(1));

	tearDown();

	assertThat(this.amc.hasReceived(),
			is(listWithSameOrder(MqttMessageBuilder
					.mqttMessageWithBasicTopic(TOPIC).digitalPin(pin)
					.hasValue(1))));
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:22,代码来源:MqttClientIntegrationSend.java

示例6: generatesBrokerEventOnAnalogPinChange

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void generatesBrokerEventOnAnalogPinChange()
		throws InterruptedException, MqttSecurityException, MqttException,
		IOException {

	int pin = 1;
	int value = 45;
	this.client.setThrottleMillis(0);
	this.client.setAnalogs(pin);
	this.client.setDigitals();

	startAsync(this.client);
	simulateArduinoToMqtt(alpProtocolMessage(ANALOG_PIN_READ).forPin(pin)
			.withValue(value));

	tearDown();

	assertThat(this.amc.hasReceived(),
			is(listWithSameOrder(MqttMessageBuilder
					.mqttMessageWithBasicTopic(TOPIC).analogPin(pin)
					.hasValue(value))));
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:23,代码来源:MqttClientIntegrationSend.java

示例7: clientConnectsWhenAfterBrokerRestartet

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void clientConnectsWhenAfterBrokerRestartet()
		throws InterruptedException, MqttSecurityException, MqttException,
		IOException {

	doNotListenForAnything(client);
	startAsync(client);

	MILLISECONDS.sleep(250);
	broker.stopServer();
	MILLISECONDS.sleep(250);
	assertThat(client.isConnected(), is(false));
	
	broker = startBroker();
	waitUntilIsConnected(client, 3, SECONDS);
	assertThat(client.isConnected(), is(true));

	tearDown();
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:20,代码来源:MqttClientReconnectsToRestartedBrokerIntegrationTest.java

示例8: processesBrokerEventPowerOnDigitalPin

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void processesBrokerEventPowerOnDigitalPin()
		throws InterruptedException, MqttSecurityException, MqttException,
		IOException {

	int pin = 1;
	int value = 1;

	doNotListenForAnything(client);
	startAsync(client);
	amc.switchDigitalPin(pin, true);

	tearDown();

	verify(link).getPortList();
	verify(link).connect(PORT, SPEED);
	verify(link).sendPowerPinSwitch(pin, value);
	verify(link).isConnected();
	verify(link).disconnect();
	verifyNoMoreInteractions(link);
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:22,代码来源:MqttClientIntegrationReceive.java

示例9: processesBrokerEventPowerOnAnalogPin

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void processesBrokerEventPowerOnAnalogPin()
		throws InterruptedException, MqttSecurityException, MqttException,
		IOException {

	int pin = 1;
	int value = 123;

	doNotListenForAnything(client);
	startAsync(client);
	amc.switchAnalogPin(pin, value);

	tearDown();

	verify(link).getPortList();
	verify(link).connect(PORT, SPEED);
	verify(link).sendPowerPinIntensity(pin, value);
	verify(link).isConnected();
	verify(link).disconnect();
	verifyNoMoreInteractions(link);
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:22,代码来源:MqttClientIntegrationReceive.java

示例10: initClient

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
private static void initClient() throws MqttException, MqttSecurityException {
	if (client == null || !client.isConnected()) {

		UUID uuid = UUID.randomUUID();
		String randomUUIDString = uuid.toString();

		client = new MqttClient("tcp://localhost:1883", "HomeAutomation/" + randomUUIDString);

		MqttConnectOptions connOpt = new MqttConnectOptions();
		connOpt.setAutomaticReconnect(true);
		connOpt.setCleanSession(true);
		connOpt.setKeepAliveInterval(60);
		connOpt.setConnectionTimeout(30);
		connOpt.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
		// connOpt.setUserName(M2MIO_USERNAME);
		// connOpt.setPassword(M2MIO_PASSWORD_MD5.toCharArray());

		client.connect(connOpt);
	}
}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:21,代码来源:MQTTSender.java

示例11: connect

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
private void connect() throws MqttException, MqttSecurityException {

		UUID uuid = UUID.randomUUID();
		String randomUUIDString = uuid.toString();

		client = new MqttClient("tcp://localhost:1883", "HomeAutomation/" + randomUUIDString, memoryPersistence);
		client.setCallback(this);

		MqttConnectOptions connOpt = new MqttConnectOptions();
		connOpt.setAutomaticReconnect(true);
		// connOpt.setCleanSession(true);
		connOpt.setKeepAliveInterval(60);
		connOpt.setConnectionTimeout(60);
		connOpt.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
		// connOpt.setUserName(M2MIO_USERNAME);
		// connOpt.setPassword(M2MIO_PASSWORD_MD5.toCharArray());

		client.connect(connOpt);

		client.subscribe("/sensordata");
		client.subscribe("/sensorState");
		client.subscribe("/distanceSensor");
		client.subscribe("/switch");
		LogManager.getLogger(this.getClass()).info("Started MQTT client");
	}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:26,代码来源:MQTTReceiverClient.java

示例12: connectClient

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
private void connectClient() throws MqttSecurityException, MqttException {
       writeServiceTraceEntry(clsName, "connectClient", "Entry");
	try {
		writeServiceTraceData(clsName, "connectClient",	"Attempting to connect ...");
		client.connect();
		writeActivityLog("12063", new String[] { connectionUrl },
				activityLogTag);
		// QoS defaults to 0.
		// int qos = getMQTTFactory().getQos(getProperties());
		int qos = 0;
		client.subscribe(getProperties().getProperty("topicName"), qos);
		failedToConnect = false;
		writeServiceTraceData(clsName, "connectClient", "Connected OK.");
		writeActivityLog("12066", new String[] {getProperties().getProperty("topicName"), "" + qos}, activityLogTag);
	} catch (MbException e) {
           try {
               getConnectorFactory().getContainerServices().writeSystemLogError("2111", 
               	new String[]{e.getLocalizedMessage()});
           } catch (MbException e1) {
           }
	}
	finally {
		writeServiceTraceExit(clsName, "connectClient", "Exit");
	}
}
 
开发者ID:ot4i,项目名称:mqtt-client-connector,代码行数:26,代码来源:MQTTInputConnector.java

示例13: doConnect

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
private void doConnect(MqttConnectOptions options) {

    if (options == null)
      options = buildOptions();

    try {
      IMqttToken token = socketClient.connect(options);
      token.waitForCompletion();
      System.out.println("Connected ;)");
      emit("socket::connected");
      for(int i = pubs.size();i>0;i--){
        PublishHolder pub= pubs.peekFirst();
        doPublish(pub);
      }
    } catch (MqttException e) {
      System.out.println("Failed to connect because;");
      e.printStackTrace();
      if (e.getReasonCode() == MqttSecurityException.REASON_CODE_NOT_AUTHORIZED
          || e.getReasonCode() == MqttSecurityException.REASON_CODE_SERVER_CONNECT_ERROR) {
        reconnect(false);
      } else if(e.getReasonCode() == MqttException.REASON_CODE_CLIENT_CLOSED
          || e.getReasonCode() == MqttException.REASON_CODE_CLIENT_CONNECTED) {
      }else {
        retryReconnect(options);
      }
    }
  }
 
开发者ID:SciSpike,项目名称:socket-api-java,代码行数:28,代码来源:MqttWrapper.java

示例14: connectToMqttBroker

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
public void connectToMqttBroker() throws MqttSecurityException,
		MqttException, InterruptedException {
	this.link = connect(createLink());
	SECONDS.sleep(this.sleepSecs);
	// ensure brokerTopic is normalized
	setBrokerTopic(this.brokerTopic);
	Config config = Config.withTopic(this.brokerTopic);
	this.mqttClient = new MqttClient(link,
			this.control ? config.withControlChannelEnabled() : config)
			.listenToMqttAndArduino();
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:12,代码来源:MqttMain.java

示例15: createSocketFactory

import org.eclipse.paho.client.mqttv3.MqttSecurityException; //导入依赖的package包/类
/**
 * Returns an SSL socket factory for the given configuration. If no
 * SSLProtocol is already set, uses DEFAULT_PROTOCOL. Throws
 * IllegalArgumentException if the socket factory could not be created due
 * to underlying configuration problems.
 *
 * @param configID The configuration identifier for selecting a configuration.
 * @return An SSLSocketFactory
 * @throws MqttDirectException
 * @see org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory#DEFAULT_PROTOCOL
 */
public SSLSocketFactory createSocketFactory(String configID)
        throws MqttSecurityException {
    final String METHOD_NAME = "createSocketFactory";
    SSLContext ctx = getSSLContext(configID);
    if (logger != null) {
        // 12020 "SSL initialization: configID = {0}, application-enabled cipher suites = {1}"
        logger.fine(CLASS_NAME, METHOD_NAME, "12020", new Object[]{configID != null ? configID : "null (broker defaults)",
                getEnabledCipherSuites(configID) != null ? getProperty(configID, CIPHERSUITES, null) : "null (using platform-enabled cipher suites)"});
    }

    return ctx.getSocketFactory();
}
 
开发者ID:longkerdandy,项目名称:chii2mqtt,代码行数:24,代码来源:SSLSocketFactoryFactory.java


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