org.eclipse.paho.client.mqttv3.MqttSecurityException Java Examples
The following examples show how to use
org.eclipse.paho.client.mqttv3.MqttSecurityException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MQTTInputConnector.java From mqtt-client-connector with Eclipse Public License 1.0 | 6 votes |
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"); } }
Example #2
Source File: MqttMain.java From Ardulink-1 with Apache License 2.0 | 6 votes |
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(); } }
Example #3
Source File: MqttClientIntegrationSend.java From Ardulink-1 with Apache License 2.0 | 6 votes |
@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)))); }
Example #4
Source File: MqttClientIntegrationSend.java From Ardulink-1 with Apache License 2.0 | 6 votes |
@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)))); }
Example #5
Source File: MqttClientReconnectsToRestartedBrokerIntegrationTest.java From Ardulink-1 with Apache License 2.0 | 6 votes |
@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(); }
Example #6
Source File: MqttClientIntegrationReceive.java From Ardulink-1 with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: MqttClientIntegrationReceive.java From Ardulink-1 with Apache License 2.0 | 6 votes |
@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); }
Example #8
Source File: MqttAndroidClient.java From Sparkplug with Eclipse Public License 1.0 | 6 votes |
/** * 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); } }
Example #9
Source File: TestMqttAppender.java From karaf-decanter with Apache License 2.0 | 6 votes |
private MqttClient receive(final List<MqttMessage> received) throws MqttException, MqttSecurityException { MqttClient client = new MqttClient(SERVER, "test"); MqttCallback callback = new MqttCallback() { @Override public void messageArrived(String topic, MqttMessage message) throws Exception { received.add(message); System.out.println(message); } @Override public void deliveryComplete(IMqttDeliveryToken token) { } @Override public void connectionLost(Throwable cause) { cause.printStackTrace(); } }; client.connect(); client.subscribe(TOPIC); client.setCallback(callback); return client; }
Example #10
Source File: MqttTokenAndroid.java From Sparkplug with Eclipse Public License 1.0 | 6 votes |
/** * @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; } } }
Example #11
Source File: MqttExporter.java From neoscada with Eclipse Public License 1.0 | 6 votes |
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; } } ); }
Example #12
Source File: MqttAsyncClientEx.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public IMqttToken connect(MqttConnectOptions options, Object userContext, IMqttActionListener callback) throws MqttException, MqttSecurityException { if (!connection.connectTimeout) { connection.connectionStateOverwrite = MqttConnectionState.CONNECTED; if (connection.connectSuccess) { callback.onSuccess(getToken(userContext, callback, null)); } else { callback.onFailure(getToken(userContext, callback, null), new MqttException(0)); } } else { connection.connectionStateOverwrite = MqttConnectionState.DISCONNECTED; } return getToken(userContext, callback, null); }
Example #13
Source File: MqttTokenAndroid.java From Sparkplug with Eclipse Public License 1.0 | 5 votes |
/** * @see org.eclipse.paho.client.mqttv3.IMqttToken#waitForCompletion() */ @Override public void waitForCompletion() throws MqttException, MqttSecurityException { synchronized (waitObject) { try { waitObject.wait(); } catch (InterruptedException e) { // do nothing } } if (pendingException != null) { throw pendingException; } }
Example #14
Source File: MqttAsyncClientEx.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public IMqttToken connect(MqttConnectOptions options, Object userContext, IMqttActionListener callback) throws MqttException, MqttSecurityException { if (!connection.connectTimeout) { connection.connectionStateOverwrite = MqttConnectionState.CONNECTED; if (connection.connectSuccess) { callback.onSuccess(getToken(userContext, callback, null)); } else { callback.onFailure(getToken(userContext, callback, null), new MqttException(0)); } } else { connection.connectionStateOverwrite = MqttConnectionState.DISCONNECTED; } return getToken(userContext, callback, null); }
Example #15
Source File: MqttMain.java From Ardulink-1 with Apache License 2.0 | 5 votes |
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(); }
Example #16
Source File: AlMqttClient.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
public IMqttToken connectWithResult(MqttConnectOptions options, IMqttActionListener callback) throws MqttSecurityException, MqttException { IMqttToken tok = aClient.connect(options, null, callback); tok.waitForCompletion(getTimeToWait()); return tok; }
Example #17
Source File: AnotherMqttClient.java From Ardulink-1 with Apache License 2.0 | 4 votes |
public AnotherMqttClient connect() throws MqttSecurityException, MqttException { mqttClient.connect(); mqttClient.subscribe("#"); return this; }
Example #18
Source File: TestUtil.java From Ardulink-1 with Apache License 2.0 | 4 votes |
public static MqttMain startAsync(MqttMain mqttMain) throws InterruptedException, MqttSecurityException, MqttException { mqttMain.connectToMqttBroker(); return waitUntilIsConnected(mqttMain, 5, SECONDS); }
Example #19
Source File: MqttTestClient.java From nifi with Apache License 2.0 | 4 votes |
@Override public void connect() throws MqttSecurityException, MqttException { connected.set(true); }
Example #20
Source File: MqttClientIntegrationReceive.java From Ardulink-1 with Apache License 2.0 | 4 votes |
@Before public void setup() throws IOException, InterruptedException, MqttSecurityException, MqttException { broker = startBroker(); amc = new AnotherMqttClient(TOPIC).connect(); }
Example #21
Source File: MqttTestClient.java From nifi with Apache License 2.0 | 4 votes |
@Override public void connect(MqttConnectOptions options) throws MqttSecurityException, MqttException { connected.set(true); }
Example #22
Source File: MqttClientReconnectsToRestartedBrokerIntegrationTest.java From Ardulink-1 with Apache License 2.0 | 4 votes |
@Before public void setup() throws IOException, InterruptedException, MqttSecurityException, MqttException { broker = startBroker(); }
Example #23
Source File: MqttTestClient.java From nifi with Apache License 2.0 | 4 votes |
@Override public IMqttToken connectWithResult(MqttConnectOptions options) throws MqttSecurityException, MqttException { return null; }
Example #24
Source File: MqttTestClient.java From nifi with Apache License 2.0 | 4 votes |
@Override public void subscribe(String topicFilter) throws MqttException, MqttSecurityException { subscribedTopic = topicFilter; subscribedQos = -1; }
Example #25
Source File: MqttMain.java From Ardulink-1 with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws MqttSecurityException, MqttException, InterruptedException { new MqttMain().doMain(args); }
Example #26
Source File: MqttClientFactory.java From enmasse with Apache License 2.0 | 4 votes |
@Override public IMqttToken connect() throws MqttException, MqttSecurityException { return this.mqttClient.connect(this.options); }
Example #27
Source File: MqttTestClient.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void connect() throws MqttSecurityException, MqttException { connected.set(true); }
Example #28
Source File: MqttTestClient.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void connect(MqttConnectOptions options) throws MqttSecurityException, MqttException { connected.set(true); }
Example #29
Source File: MqttTestClient.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public IMqttToken connectWithResult(MqttConnectOptions options) throws MqttSecurityException, MqttException { return null; }
Example #30
Source File: MqttTestClient.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void subscribe(String topicFilter) throws MqttException, MqttSecurityException { subscribedTopic = topicFilter; subscribedQos = -1; }