log.error("cause " + me.getCause()); log.error("excep " + me); me.printStackTrace(); me.printStackTrace(); System.exit(1);
log.error("cause " + me.getCause()); log.error("excep " + me); me.printStackTrace(); System.exit(1);
@Test(expected = MqttException.class) public void checkClientAuthenticationFail() throws Exception { LOG.info("*** checkClientAuthenticationFail ***"); SSLSocketFactory ssf = configureSSLSocketFactory("unsignedclientkeystore.jks"); MqttConnectOptions options = new MqttConnectOptions(); options.setSocketFactory(ssf); // actual a "Broken pipe" is thrown, this is not very specific. try { m_client.connect(options); } catch (MqttException e) { e.printStackTrace(); throw e; } }
public void subscribeToTopic(){ try { mqttAndroidClient.subscribe(subscriptionTopic, 0, null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { addToHistory("Subscribed!"); } @Override public void onFailure(IMqttToken asyncActionToken, Throwable exception) { addToHistory("Failed to subscribe"); } }); // THIS DOES NOT WORK! mqttAndroidClient.subscribe(subscriptionTopic, 0, new IMqttMessageListener() { @Override public void messageArrived(String topic, MqttMessage message) throws Exception { // message Arrived! System.out.println("Message: " + topic + " : " + new String(message.getPayload())); } }); } catch (MqttException ex){ System.err.println("Exception whilst subscribing"); ex.printStackTrace(); } }
public void publishMessage(){ try { MqttMessage message = new MqttMessage(); message.setPayload(publishMessage.getBytes()); mqttAndroidClient.publish(publishTopic, message); addToHistory("Message Published"); if(!mqttAndroidClient.isConnected()){ addToHistory(mqttAndroidClient.getBufferedMessageCount() + " messages in buffer."); } } catch (MqttException e) { System.err.println("Error Publishing: " + e.getMessage()); e.printStackTrace(); } }
@Override public void connectionLost(Throwable cause) { LOG.error("Onem2mMqttClient: lost connection to server"); try { Onem2mMqttAsyncClient.this.connectToMqttServer(mqttBroker); } catch (MqttException e) { e.printStackTrace(); } }
@Override protected void onDestroy() { super.onDestroy(); if(client!=null) try { client.disconnect(); } catch (MqttException e) { e.printStackTrace(); } } }
@Override public void onClick(View v) { String topic = subscribeTopic.getText().toString().trim(); if (!topic.isEmpty()) { try { pahoMqttClient.subscribe(client, topic, 1); } catch (MqttException e) { e.printStackTrace(); } } } });
private void subscribeToCommands() { try { mqttAsyncClient.subscribe("iot-2/cmd/+/fmt/+", 2); } catch (MqttException e) { e.printStackTrace(); } }
@Override public void onClick(View v) { String topic = unSubscribeTopic.getText().toString().trim(); if (!topic.isEmpty()) { try { pahoMqttClient.unSubscribe(client, topic); } catch (MqttException e) { e.printStackTrace(); } } } });
public void unSubscribe(BrokerEntity brokerEntity, String topic){ MqttAndroidClient mqttAndroidClient = clients.get(brokerEntity.getId()); if(mqttAndroidClient!=null){ try { mqttAndroidClient.unsubscribe(topic); } catch (MqttException e) { e.printStackTrace(); } } }
public void subscribeToTopic(final BrokerEntity brokerEntity, String topic, int qos){ MqttAndroidClient mqttAndroidClient = clients.get(brokerEntity.getId()); if(mqttAndroidClient!=null){ try { mqttAndroidClient.subscribe(topic, qos); } catch (MqttException e) { e.printStackTrace(); } } }
protected void reconnect() { try { super.connect(true); } catch (MqttException e) { // TODO Auto-generated catch block e.printStackTrace(); } subscribeToGatewayCommands(); }
protected void reconnect() { try { super.connect(true); } catch (MqttException e) { // TODO Auto-generated catch block e.printStackTrace(); } subscribeToGatewayCommands(); }
@Override public void connectionLost(Throwable cause) { System.err.println("Connection to MQTT server at "+client.getServerURI()+" lost. (" + location + ") " + cause); try { this.client = new MqttClient(this.uri, this.id); this.client.connect(this.options); } catch (MqttException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void subscribeToGatewayNotification() { String newTopic = "iot-2/type/"+this.getGWDeviceType() +"/id/" +this.getGWDeviceId() + "/notify"; subscriptions.put(newTopic, 0); try { mqttAsyncClient.subscribe(newTopic, 0); } catch (MqttException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void subscribeToCommands() throws MqttException{ try { mqttAsyncClient.subscribe("iot-2/cmd/+/fmt/+", 2).waitForCompletion(getActionTimeout()); } catch (MqttException e) { e.printStackTrace(); throw e; } }
@Test public void connected(TestContext context) { try { MemoryPersistence persistence = new MemoryPersistence(); MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence); client.connect(); context.assertTrue(client.isConnected() && this.endpoint.isConnected()); } catch (MqttException e) { context.assertTrue(false); e.printStackTrace(); } }
@Test public void connected(TestContext context) { try { MemoryPersistence persistence = new MemoryPersistence(); MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence); client.connect(); context.assertTrue(client.isConnected() && this.endpoint.isConnected()); } catch (MqttException e) { context.assertTrue(false); e.printStackTrace(); } }