Skip to content

Commit

Permalink
Fixed error messages
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Feb 23, 2023
1 parent e7df447 commit 7d55685
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class MqttClientConnectException extends MqttClientException {
/**
* Constructor.
*
* @param uri The {@link URI} of the server which the {@link MqttClient} was connecting to.
* @param clientId The clientId of the {@link org.eclipse.kapua.transport.mqtt.MqttClient} that produced this {@link MqttClientConnectException}.
* @param username The username used to authenticate into the server.
* @param uri The {@link URI} of the server which the {@link MqttClient} was connecting to.
* @since 1.2.0
*/
public MqttClientConnectException(String clientId, String username, URI uri) {
Expand All @@ -43,16 +43,16 @@ public MqttClientConnectException(String clientId, String username, URI uri) {
* Constructor.
*
* @param cause The root {@link Throwable} that caused the error.
* @param uri The {@link URI} of the server which the {@link MqttClient} was connecting to.
* @param clientId The clientId of the {@link org.eclipse.kapua.transport.mqtt.MqttClient} that produced this {@link MqttClientConnectException}.
* @param username The username used to authenticate into the server.
* @param uri The {@link URI} of the server which the {@link MqttClient} was connecting to.
* @since 1.2.0
*/
public MqttClientConnectException(Throwable cause, String clientId, String username, URI uri) {
super(MqttClientErrorCodes.CONNECT_ERROR, cause, clientId, username, uri);

this.uri = uri;
this.username = username;
this.uri = uri;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public enum MqttClientErrorCodes implements KapuaErrorCode {
*
* @since 1.0.0
*/
PUBLISH_EXCEPTION,
PUBLISH_ERROR,

/**
* Error while subscribing to a topic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import org.eclipse.kapua.KapuaException;

import java.util.Arrays;
import java.util.stream.Stream;

/**
* Class that extends {@link KapuaException} with a specialized set of exceptions
* for the {@link org.eclipse.kapua.transport.mqtt} implementation.
Expand Down Expand Up @@ -43,7 +46,9 @@ public class MqttClientException extends KapuaException {
* @since 1.0.0
*/
public MqttClientException(MqttClientErrorCodes code, String clientId) {
this(code, clientId, (Object) null);
super(code, clientId);

this.clientId = clientId;
}

/**
Expand All @@ -54,7 +59,9 @@ public MqttClientException(MqttClientErrorCodes code, String clientId) {
* @since 1.0.0
*/
public MqttClientException(MqttClientErrorCodes code, String clientId, Object... arguments) {
this(code, null, clientId, arguments);
super(code, clientId, arguments);

this.clientId = clientId;
}

/**
Expand All @@ -66,7 +73,7 @@ public MqttClientException(MqttClientErrorCodes code, String clientId, Object...
* @since 1.0.0
*/
public MqttClientException(MqttClientErrorCodes code, Throwable cause, String clientId, Object... arguments) {
super(code, cause, clientId, arguments);
super(code, cause, Stream.concat(Stream.of((Object) clientId), Arrays.stream(arguments)).toArray());

this.clientId = clientId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
package org.eclipse.kapua.transport.mqtt.exception;

import org.eclipse.kapua.transport.message.mqtt.MqttMessage;
import org.eclipse.kapua.transport.message.mqtt.MqttTopic;
import org.eclipse.kapua.transport.mqtt.MqttClient;

/**
* {@link Exception} to {@code throw} when the {@link MqttClient} cannot publish the {@link org.eclipse.kapua.transport.message.mqtt.MqttMessage}.
* {@link Exception} to {@code throw} when the {@link MqttClient} cannot publish the {@link MqttMessage}.
*
* @since 1.2.0
*/
public class MqttClientPublishException extends MqttClientException {

/**
* The {@link org.eclipse.kapua.transport.message.mqtt.MqttTopic} where the {@link MqttMessage} that was meant to be published.
* The {@link MqttTopic} where the {@link MqttMessage} that was meant to be published.
*
* @since 1.2.0
*/
Expand All @@ -40,22 +41,35 @@ public class MqttClientPublishException extends MqttClientException {
* Constructor.
*
* @param cause The root {@link Throwable} that caused the error.
* @param clientId The clientId of the {@link org.eclipse.kapua.transport.mqtt.MqttClient} that produced this {@link MqttClientPublishException}.
* @param topic The {@link org.eclipse.kapua.transport.message.mqtt.MqttTopic} where the {@link MqttMessage} that was meant to be published.
* @param clientId The clientId of the {@link MqttClient} that produced this {@link MqttClientPublishException}.
* @param topic The {@link MqttTopic} where the {@link MqttMessage} that was meant to be published.
* @param mqttMessage The {@link MqttMessage} was meant to be published.
* @since 2.0.0
*/
public MqttClientPublishException(Throwable cause, String clientId, MqttTopic topic, MqttMessage mqttMessage) {
this(cause, clientId, topic.toString(), mqttMessage);
}

/**
* Constructor.
*
* @param cause The root {@link Throwable} that caused the error.
* @param clientId The clientId of the {@link MqttClient} that produced this {@link MqttClientPublishException}.
* @param topic The {@link MqttTopic} in {@link String} form where the {@link MqttMessage} that was meant to be published.
* @param mqttMessage The {@link MqttMessage} was meant to be published.
* @since 1.2.0
*/
public MqttClientPublishException(Throwable cause, String clientId, String topic, MqttMessage mqttMessage) {
super(MqttClientErrorCodes.PUBLISH_EXCEPTION, cause, clientId, topic, mqttMessage.getPayload().hasBody() ? mqttMessage.getPayload().getBody().length : null);
super(MqttClientErrorCodes.PUBLISH_ERROR, cause, clientId, topic, mqttMessage.getPayload().hasBody() ? mqttMessage.getPayload().getBody().length : null);

this.topic = topic;
this.mqttMessage = mqttMessage;
}

/**
* Gets the {@link org.eclipse.kapua.transport.message.mqtt.MqttTopic} where the {@link MqttMessage} that was meant to be published.
* Gets the {@link MqttTopic} where the {@link MqttMessage} that was meant to be published.
*
* @return The {@link org.eclipse.kapua.transport.message.mqtt.MqttTopic} where the {@link MqttMessage} that was meant to be published.
* @return The {@link MqttTopic} where the {@link MqttMessage} that was meant to be published.
* @since 1.2.0
*/
public String getTopic() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ ALREADY_CONNECTED=MqttClient {0} is already connected.
CALLBACK_SET_ERROR=MqttClient {0} cannot set response callback on topic: {1}
CLEAN_ERROR=MqttClient {0} cannot be terminated properly. This can lead to resource leaks.
CONNECT_ERROR=MqttClient {0} cannot connect to {2} with username {1}
DISCONNECT_EXCEPTION=MqttClient {0} cannot be disconnected properly.
DISCONNECT_ERROR=MqttClient {0} cannot be disconnected properly.
NOT_CONNECTED=MqttClient {0} is not connected.
PUBLISH_EXCEPTION=MqttClient {0} cannot publish MqttMessage({2} bytes) to topic: {1}
SUBSCRIBE_EXCEPTION=MqttClient {0} cannot subscribe to topic: {1}
TERMINATE_EXCEPTION=MqttClient {0} cannot be terminated properly. This can lead to resource leaks.
UNSUBSCRIBE_EXCEPTION=MqttClient {0} cannot subscribe from topic: {1}
PUBLISH_ERROR=MqttClient {0} cannot publish MqttMessage({2} bytes) to topic: {1}
SUBSCRIBE_ERROR=MqttClient {0} cannot subscribe to topic: {1}
TERMINATE_ERROR=MqttClient {0} cannot be terminated properly. This can lead to resource leaks.
UNSUBSCRIBE_ERROR=MqttClient {0} cannot unsubscribe from topic: {1}

0 comments on commit 7d55685

Please sign in to comment.