System.exit(0); } catch (MqttException me) { log.error("reason " + me.getReasonCode()); log.error("msg " + me.getMessage()); log.error("loc " + me.getLocalizedMessage());
sampleClient.subscribe(topic, qos); } catch (MqttException me) { log.error("reason " + me.getReasonCode()); log.error("msg " + me.getMessage()); log.error("loc " + me.getLocalizedMessage());
assertThat(((MqttException) e.getCause()).getReasonCode(), equalTo((int) MqttException.REASON_CODE_SUBSCRIBE_FAILED));
switch (e.getReasonCode()) { case MqttException.REASON_CODE_CLIENT_CONNECTED: connectionState = MqttManagerConnectionState.Connected;
@Override public void unsubscribe(final Topic topic) { try { this.client.unsubscribe(topic.render(this.topicContext)); } catch (final MqttException e) { if (e.getReasonCode() != MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) { logger.warn("Failed to unsubscribe: {}", topic, e); } } }
@Override public void unsubscribe(final Topic topic) { try { this.client.unsubscribe(topic.render(this.topicContext)); } catch (final MqttException e) { if (e.getReasonCode() != MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) { logger.warn("Failed to unsubscribe: {}", topic, e); } } }
protected void respond(JsonObject payload) { final String METHOD = "respond"; try { DMAgentTopic topic = dmClient.getDMAgentTopic(); dmClient.publish(topic.getDMServerTopic(), payload); } catch (MqttException e) { LoggerUtility.severe(CLASS_NAME, METHOD, "Unexpected Mqtt Exception, code = " + e.getReasonCode()); } }
@Override public void unsubscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException { try { mqttClient.unsubscribe(message.getTopic(), message, messageListener); } catch (MqttException e) { if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) { throw new AwsIotRetryableException(e); } else { throw new AWSIotException(e); } } }
protected void notify(JsonObject payload) { final String METHOD = "notify"; try { DMAgentTopic topic = dmClient.getDMAgentTopic(); dmClient.publish(topic.getNotifyTopic(), payload); } catch (MqttException e) { LoggerUtility.severe(CLASS_NAME, METHOD, "Unexpected Mqtt Exception, code = " + e.getReasonCode()); } }
@Override public void unsubscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException { try { mqttClient.unsubscribe(message.getTopic(), message, messageListener); } catch (MqttException e) { if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) { throw new AwsIotRetryableException(e); } else { throw new AWSIotException(e); } } }
protected void respond(JsonObject payload) { final String METHOD = "respond"; try { DMAgentTopic topic = dmClient.getDMAgentTopic(); dmClient.publish(topic.getDMServerTopic(), payload); } catch (MqttException e) { LoggerUtility.severe(CLASS_NAME, METHOD, "Unexpected Mqtt Exception, code = " + e.getReasonCode()); } }
@Override public void subscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException { try { mqttClient.subscribe(message.getTopic(), message.getQos().getValue(), message, messageListener); } catch (MqttException e) { if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) { throw new AwsIotRetryableException(e); } else { throw new AWSIotException(e); } } }
@Override public void subscribeTopic(AWSIotMessage message) throws AWSIotException, AwsIotRetryableException { try { mqttClient.subscribe(message.getTopic(), message.getQos().getValue(), message, messageListener); } catch (MqttException e) { if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_NOT_CONNECTED) { throw new AwsIotRetryableException(e); } else { throw new AWSIotException(e); } } }
@Test public void refusedServerUnavailable(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE; 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.fail(); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_BROKER_UNAVAILABLE); } }
@Test public void refusedIdentifierRejected(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; 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.fail(); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_INVALID_CLIENT_ID); } }
@Test public void refusedNotAuthorized(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; 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.fail(); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_NOT_AUTHORIZED); } }
@Test public void refusedNotAuthorized(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; 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.fail(); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_NOT_AUTHORIZED); } }
@Test public void refusedIdentifierRejected(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; 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.fail(); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_INVALID_CLIENT_ID); } }
@Test public void refusedServerUnavailable(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE; 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.fail(); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_BROKER_UNAVAILABLE); } }
@Test public void bruteDisconnect(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(); client.close(); context.assertTrue(false); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_CLIENT_CONNECTED); e.printStackTrace(); } }