Skip to content

Commit

Permalink
Refresh mqtt connect option for invalid arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshu42 committed Jul 25, 2023
1 parent 4c003e9 commit 2eb7778
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ internal class MqttExceptionHandlerImpl(
MqttException.REASON_CODE_FAILED_AUTHENTICATION -> {
runnableScheduler.scheduleAuthFailureRunnable()
}
MqttException.REASON_CODE_NOT_AUTHORIZED -> {
runnableScheduler.scheduleAuthFailureRunnable()
}
MqttException.REASON_CODE_INVALID_CONNECT_OPTIONS -> {
runnableScheduler.scheduleAuthFailureRunnable()
}
MqttException.REASON_CODE_INVALID_CLIENT_ID -> {
}
MqttException.REASON_CODE_INVALID_MESSAGE -> {
Expand All @@ -130,9 +136,6 @@ internal class MqttExceptionHandlerImpl(
}
MqttException.REASON_CODE_NO_MESSAGE_IDS_AVAILABLE -> {
}
MqttException.REASON_CODE_NOT_AUTHORIZED -> {
runnableScheduler.scheduleAuthFailureRunnable()
}
MqttException.REASON_CODE_SOCKET_FACTORY_MISMATCH -> {
}
MqttException.REASON_CODE_SSL_CONFIG_ERROR -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;

import static org.eclipse.paho.client.mqttv3.MqttException.REASON_CODE_INVALID_CONNECT_OPTIONS;

/**
* Holds the set of options that control how the client connects to a server.
*/
Expand Down Expand Up @@ -158,11 +160,11 @@ public String getUserName()
* @throws IllegalArgumentException
* if the user name is blank or only contains whitespace characters.
*/
public void setUserName(String userName)
public void setUserName(String userName) throws MqttException
{
if ((userName != null) && (userName.trim().equals("")))
{
throw new IllegalArgumentException("Username is empty");
throw new MqttException(REASON_CODE_INVALID_CONNECT_OPTIONS, new IllegalArgumentException("Username is empty"));
}
this.userName = userName;
}
Expand Down Expand Up @@ -260,23 +262,23 @@ public int getKeepAliveIntervalServer()
* @param keepAliveInterval
* the interval, measured in seconds, must be >= 0.
*/
public void setKeepAliveInterval(int keepAliveInterval) throws IllegalArgumentException
public void setKeepAliveInterval(int keepAliveInterval) throws MqttException
{
if (keepAliveInterval < 0)
{
throw new IllegalArgumentException();
throw new MqttException(REASON_CODE_INVALID_CONNECT_OPTIONS);
}
this.keepAliveInterval = keepAliveInterval;
}

/*
* This interval is used for sending to server in connect packet.
*/
public void setKeepAliveIntervalServer(int keepAliveInterval) throws IllegalArgumentException
public void setKeepAliveIntervalServer(int keepAliveInterval) throws MqttException
{
if (keepAliveInterval < 0)
{
throw new IllegalArgumentException();
throw new MqttException(REASON_CODE_INVALID_CONNECT_OPTIONS);
}
this.keepAliveIntervalServer = keepAliveInterval;
}
Expand Down Expand Up @@ -353,11 +355,11 @@ public void setHandshakeTimeout(int handshakeTimeout)
* @param readTimeout
* the timeout value, measured in seconds. It must be >0;
*/
public void setReadTimeout(int readTimeout)
public void setReadTimeout(int readTimeout) throws MqttException
{
if (readTimeout < 0)
{
throw new IllegalArgumentException();
throw new MqttException(REASON_CODE_INVALID_CONNECT_OPTIONS);
}
this.readTimeout = readTimeout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public class MqttException extends Exception
*/
public static final short REASON_CODE_INVALID_SUBSCRIPTION = 32204;

/**
* The Client has attempted to connect with invalid arguments.
*/
public static final short REASON_CODE_INVALID_CONNECT_OPTIONS = 32205;

private int reasonCode;

private Throwable cause;
Expand Down

0 comments on commit 2eb7778

Please sign in to comment.