Skip to content

Commit effca14

Browse files
committed
Issue #478 - Connection properties needs to use Mqtt Variable properties correctly.
Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent 9992867 commit effca14

6 files changed

Lines changed: 32 additions & 54 deletions

File tree

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/MqttConnectionOptions.java

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,21 @@ enum UriType {
6868
private int maxInflight = 10; // Max inflight messages
6969
private int connectionTimeout = 30; // Connection timeout in seconds
7070

71-
MqttProperties connectionProperties = new MqttProperties();
71+
7272
public MqttProperties getConnectionProperties() {
73+
MqttProperties connectionProperties = new MqttProperties();
74+
connectionProperties.setSessionExpiryInterval(sessionExpiryInterval);
75+
connectionProperties.setReceiveMaximum(receiveMaximum);
76+
connectionProperties.setMaximumPacketSize(maximumPacketSize);
77+
connectionProperties.setTopicAliasMaximum(topicAliasMaximum);
78+
connectionProperties.setRequestResponseInfo(requestResponseInfo);
79+
connectionProperties.setRequestProblemInfo(requestProblemInfo);
80+
connectionProperties.setUserProperties(userProperties);
81+
connectionProperties.setAuthenticationMethod(authMethod);
82+
connectionProperties.setAuthenticationData(authData);
7383
return connectionProperties;
7484
}
7585

76-
public void setConnectionProperties(MqttProperties connectionProperties) {
77-
this.connectionProperties = connectionProperties;
78-
}
7986

8087
public MqttProperties getWillMessageProperties() {
8188
return willMessageProperties;
@@ -94,11 +101,10 @@ public void setWillMessageProperties(MqttProperties willMessageProperties) {
94101
private MqttMessage willMessage = null; // Will Message
95102
private String userName; // Username
96103
private byte[] password; // Password
97-
private Integer sessionExpiryInterval = null; // The Session expiry Interval in seconds, null is the default of
104+
private Long sessionExpiryInterval = null; // The Session expiry Interval in seconds, null is the default of
98105
// never.
99-
private Integer willDelayInterval = null; // The Will Delay Interval in seconds, null is the default of 0.
100106
private Integer receiveMaximum = null; // The Receive Maximum, null defaults to 65,535, cannot be 0.
101-
private Integer maximumPacketSize = null; // The Maximum packet size, null defaults to no limit.
107+
private Long maximumPacketSize = null; // The Maximum packet size, null defaults to no limit.
102108
private Integer topicAliasMaximum = null; // The Topic Alias Maximum, null defaults to 0.
103109
private Boolean requestResponseInfo = null; // Request Response Information, null defaults to false.
104110
private Boolean requestProblemInfo = null; // Request Problem Information, null defaults to true.
@@ -476,7 +482,7 @@ public int getAutomaticReconnectMaxDelay() {
476482
*
477483
* @return the Session Expiry Interval in seconds.
478484
*/
479-
public Integer getSessionExpiryInterval() {
485+
public Long getSessionExpiryInterval() {
480486
return sessionExpiryInterval;
481487
}
482488

@@ -499,45 +505,16 @@ public Integer getSessionExpiryInterval() {
499505
* @param sessionExpiryInterval
500506
* The Session Expiry Interval in seconds.
501507
*/
502-
public void setSessionExpiryInterval(Integer sessionExpiryInterval) {
508+
public void setSessionExpiryInterval(Long sessionExpiryInterval) {
503509
this.sessionExpiryInterval = sessionExpiryInterval;
504510
}
505511

506-
/**
507-
* Returns the Will Delay Interval. If <code>null</code>, it will default to 0
508-
* and there is no will delay before the will message is published.
509-
*
510-
* @return The Will Delay Interval in seconds.
511-
*/
512-
public Integer getWillDelayInterval() {
513-
return willDelayInterval;
514-
}
515-
516-
/**
517-
* Sets the Will Delay Interval. This value, measured in seconds, defines the
518-
* time that the server will wait to send the Client's will message after it has
519-
* disconnected.
520-
* <ul>
521-
* <li>By default this value is null and so will not be sent, in this case, the
522-
* default value is 0.</li>
523-
* <li>If a 0 is sent, the will message will be sent immediately.</li>
524-
* </ul>
525-
*
526-
* The Server delays publishing the Client's Will Message until the Will Delay
527-
* Interval has passed or the Session ends, whichever happens first.
528-
*
529-
* @param willDelayInterval
530-
* The will delay interval
531-
*/
532-
public void setWillDelayInterval(Integer willDelayInterval) {
533-
this.willDelayInterval = willDelayInterval;
534-
}
535512

536513
/**
537514
* Returns the Receive Maximum value. If <code>null</code>, it will default to
538515
* 65,535.
539516
*
540-
* @return the Receive Maxumum
517+
* @return the Receive Maximum
541518
*/
542519
public Integer getReceiveMaximum() {
543520
return receiveMaximum;
@@ -569,7 +546,7 @@ public void setReceiveMaximum(Integer receiveMaximum) {
569546
*
570547
* @return the Maximum Packet Size in bytes.
571548
*/
572-
public Integer getMaximumPacketSize() {
549+
public Long getMaximumPacketSize() {
573550
return maximumPacketSize;
574551
}
575552

@@ -587,7 +564,7 @@ public Integer getMaximumPacketSize() {
587564
* @param maximumPacketSize
588565
* The Maximum packet size.
589566
*/
590-
public void setMaximumPacketSize(Integer maximumPacketSize) {
567+
public void setMaximumPacketSize(Long maximumPacketSize) {
591568
this.maximumPacketSize = maximumPacketSize;
592569
}
593570

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/MqttConnectionOptionsBuilder.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,12 @@ public MqttConnectionOptionsBuilder will(String topic, MqttMessage message) {
6767
return this;
6868
}
6969

70-
public MqttConnectionOptionsBuilder sessionExpiryInterval(Integer sessionExpiryInterval) {
70+
public MqttConnectionOptionsBuilder sessionExpiryInterval(Long sessionExpiryInterval) {
7171
mqttConnectionOptions.setSessionExpiryInterval(sessionExpiryInterval);
7272
return this;
7373
}
7474

75-
public MqttConnectionOptionsBuilder willDelayInterval(Integer willDelayInterval) {
76-
mqttConnectionOptions.setWillDelayInterval(willDelayInterval);
77-
return this;
78-
}
79-
80-
public MqttConnectionOptionsBuilder maximumPacketSize(Integer maximumPacketSize) {
75+
public MqttConnectionOptionsBuilder maximumPacketSize(Long maximumPacketSize) {
8176
mqttConnectionOptions.setMaximumPacketSize(maximumPacketSize);
8277
return this;
8378
}

org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/internal/CommsSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void run() {
177177
private void handleRunException(MqttWireMessage message, Exception ex) {
178178
final String methodName = "handleRunException";
179179
//@TRACE 804=exception
180-
log.fine(CLASS_NAME,methodName,"804",null, ex);
180+
log.severe(CLASS_NAME,methodName,"804",null, ex);
181181
MqttException mex;
182182
if ( !(ex instanceof MqttException)) {
183183
mex = new MqttException(MqttClientException.REASON_CODE_CONNECTION_LOST, ex);

org.eclipse.paho.mqttv5.common/src/main/java/org/eclipse/paho/mqttv5/common/packet/MqttDataTypes.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ public MqttDataTypes() throws IllegalAccessException {
1919
throw new IllegalAccessException("Utility Class");
2020
}
2121

22-
public static void validateTwoByteInt(int value) throws IllegalArgumentException {
22+
public static void validateTwoByteInt(Integer value) throws IllegalArgumentException {
23+
if(value == null) {
24+
return;
25+
}
2326
if (value >= 0 && value <= TWO_BYTE_INT_MAX) {
2427
return;
2528
} else {
2629
throw new IllegalArgumentException("This property must be a number between 0 and " + TWO_BYTE_INT_MAX);
2730
}
2831
}
2932

30-
public static void validateFourByteInt(long value) throws IllegalArgumentException {
33+
public static void validateFourByteInt(Long value) throws IllegalArgumentException {
34+
if(value == null) {
35+
return;
36+
}
3137
if (value >= 0 && value <= FOUR_BYTE_INT_MAX) {
3238
return;
3339
} else {

org.eclipse.paho.mqttv5.common/src/main/java/org/eclipse/paho/mqttv5/common/packet/MqttProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public byte[] encodeProperties() throws MqttException {
344344
}
345345

346346
// User Defined Properties
347-
if (!userProperties.isEmpty() && validProperties.contains(USER_DEFINED_PAIR_IDENTIFIER)) {
347+
if (userProperties != null && !userProperties.isEmpty() && validProperties.contains(USER_DEFINED_PAIR_IDENTIFIER)) {
348348
for (UserProperty property : userProperties) {
349349
// outputStream.write(USER_DEFINED_PAIR_IDENTIFIER);
350350
outputStream.writeByte(USER_DEFINED_PAIR_IDENTIFIER);
@@ -1359,7 +1359,7 @@ public String toString() {
13591359
if (reasonString != null) {
13601360
sb.append(", reasonString=" + reasonString);
13611361
}
1362-
if (userProperties.size() != 0) {
1362+
if (userProperties != null && userProperties.size() != 0) {
13631363
sb.append(", userProperties=" + userProperties);
13641364
}
13651365
if (payloadFormat) {

org.eclipse.paho.mqttv5.testclient/src/main/java/org/eclipse/paho/mqttv5/testclient/V5Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public V5Client() throws InterruptedException {
3535
// Lets build our Connection Options:
3636
MqttConnectionOptionsBuilder conOptsBuilder = new MqttConnectionOptionsBuilder();
3737
MqttConnectionOptions conOpts = conOptsBuilder.serverURI(broker).cleanSession(true)
38-
.sessionExpiryInterval(120).automaticReconnect(true)
38+
.sessionExpiryInterval(120L).automaticReconnect(true)
3939
.will(topic, new MqttMessage(willContent.getBytes(), qos, false, null)).topicAliasMaximum(1000).build();
4040
asyncClient.setCallback(this);
4141

0 commit comments

Comments
 (0)