/** * Used for calling the connect handler when the server replies to the request * * @param msg connection response message */ private void handleConnack(MqttConnAckMessage msg) { synchronized (this) { this.isConnected = msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED; } Handler<AsyncResult<MqttConnAckMessage>> handler = connectHandler(); if (handler != null) { if (msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED) { handler.handle(Future.succeededFuture(msg)); } else { MqttConnectionException exception = new MqttConnectionException(msg.code()); log.error(String.format("Connection refused by the server - code: %s", msg.code())); handler.handle(Future.failedFuture(exception)); } } }
private static MqttConnectReturnCode getConnectReturnCode(final Throwable e) { if (e instanceof MqttConnectionException) { return ((MqttConnectionException) e).code(); } else if (e instanceof ServiceInvocationException) { switch (((ServiceInvocationException) e).getErrorCode()) { case HttpURLConnection.HTTP_UNAUTHORIZED: case HttpURLConnection.HTTP_NOT_FOUND: return MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD; case HttpURLConnection.HTTP_UNAVAILABLE: return MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE; default: return MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; } } else { return MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; } } }
private static MqttConnectReturnCode getConnectReturnCode(final Throwable e) { if (e instanceof MqttConnectionException) { return ((MqttConnectionException) e).code(); } else if (e instanceof ServiceInvocationException) { switch (((ServiceInvocationException) e).getErrorCode()) { case HttpURLConnection.HTTP_UNAUTHORIZED: case HttpURLConnection.HTTP_NOT_FOUND: return MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD; case HttpURLConnection.HTTP_UNAVAILABLE: return MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE; default: return MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; } } else { return MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; } } }
/** * Used for calling the connect handler when the server replies to the request * * @param msg connection response message */ private void handleConnack(MqttConnAckMessage msg) { synchronized (this) { this.isConnected = msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED; } Handler<AsyncResult<MqttConnAckMessage>> handler = connectHandler(); if (handler != null) { if (msg.code() == MqttConnectReturnCode.CONNECTION_ACCEPTED) { handler.handle(Future.succeededFuture(msg)); } else { MqttConnectionException exception = new MqttConnectionException(msg.code()); log.error(String.format("Connection refused by the server - code: %s", msg.code())); handler.handle(Future.failedFuture(exception)); } } }
assertTrue(c.cause() instanceof MqttConnectionException); MqttConnectionException connEx = (MqttConnectionException) c.cause(); assertEquals(connEx.code(), MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE); assertFalse(client.isConnected()); async.complete();
private Future<Device> handleConnectionRequest(final MqttEndpoint endpoint, final Span currentSpan) { if (isConnectionLimitExceeded()) { LOG.debug("Connection limit ({}) exceeded, reject connection request", getConnectionLimit()); currentSpan.log(String.format("connection limit (%d) exceeded", getConnectionLimit())); return Future.failedFuture(new MqttConnectionException( MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE)); } if (getConfig().isAuthenticationRequired()) { return handleEndpointConnectionWithAuthentication(endpoint, currentSpan); } else { return handleEndpointConnectionWithoutAuthentication(endpoint); } }
assertTrue(c.cause() instanceof MqttConnectionException); MqttConnectionException connEx = (MqttConnectionException) c.cause(); assertEquals(connEx.code(), MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE); assertFalse(client.isConnected()); async.complete();