Examples of MqttConnectOptions


Examples of org.eclipse.paho.client.mqttv3.MqttConnectOptions

      logger.warn("Failure while disconecting the mqtt client", e); //$NON-NLS-1$
    }
  }

  private void initClient() {
    mqttConnectOptions = new MqttConnectOptions();
    String serverURI = PreferenceHelper.getString(ServerConstants.CONFIG_EVENT_HOST, null);
    String clientId = PreferenceHelper.getString(ServerConstants.CONFIG_EVENT_CLIENT_ID, MqttClient.generateClientId());
    if (serverURI == null) {
      //no MQTT message broker host defined
      if (logger.isWarnEnabled()) {
View Full Code Here

Examples of org.eclipse.paho.client.mqttv3.MqttConnectOptions

          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);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.