Skip to content

Commit ce7c413

Browse files
authored
Update rest messages, part 1 (#62)
1 parent eb50304 commit ce7c413

File tree

44 files changed

+798
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+798
-480
lines changed

core-service/src/main/java/javasabr/mqtt/service/message/handler/impl/ConnectInMqttInMessageHandler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package javasabr.mqtt.service.message.handler.impl;
22

33
import static javasabr.mqtt.base.util.ReactorUtils.ifTrue;
4-
import static javasabr.mqtt.model.MqttProperties.MAXIMUM_MESSAGE_SIZE_UNDEFINED;
5-
import static javasabr.mqtt.model.MqttProperties.RECEIVE_MAXIMUM_PUBLISHES_UNDEFINED;
4+
import static javasabr.mqtt.model.MqttProperties.MAXIMUM_MESSAGE_SIZE_IS_NOT_SET;
5+
import static javasabr.mqtt.model.MqttProperties.RECEIVE_MAXIMUM_PUBLISHES_IS_NOT_SET;
66
import static javasabr.mqtt.model.MqttProperties.SERVER_KEEP_ALIVE_DISABLED;
77
import static javasabr.mqtt.model.MqttProperties.SESSION_EXPIRY_INTERVAL_DISABLED;
8-
import static javasabr.mqtt.model.MqttProperties.SESSION_EXPIRY_INTERVAL_UNDEFINED;
8+
import static javasabr.mqtt.model.MqttProperties.SESSION_EXPIRY_INTERVAL_IS_NOT_SET;
99
import static javasabr.mqtt.model.MqttProperties.TOPIC_ALIAS_MAXIMUM_DISABLED;
10-
import static javasabr.mqtt.model.MqttProperties.TOPIC_ALIAS_MAXIMUM_UNDEFINED;
10+
import static javasabr.mqtt.model.MqttProperties.TOPIC_ALIAS_MAXIMUM_IS_NOT_SET;
1111
import static javasabr.mqtt.model.reason.code.ConnectAckReasonCode.BAD_USER_NAME_OR_PASSWORD;
1212
import static javasabr.mqtt.model.reason.code.ConnectAckReasonCode.CLIENT_IDENTIFIER_NOT_VALID;
1313

@@ -143,22 +143,22 @@ private void resolveClientConnectionConfig(MqttClient.UnsafeMqttClient client, C
143143
? packet.sessionExpiryInterval()
144144
: SESSION_EXPIRY_INTERVAL_DISABLED;
145145

146-
if (sessionExpiryInterval == SESSION_EXPIRY_INTERVAL_UNDEFINED) {
146+
if (sessionExpiryInterval == SESSION_EXPIRY_INTERVAL_IS_NOT_SET) {
147147
sessionExpiryInterval = serverConfig.defaultSessionExpiryInterval();
148148
}
149149

150150
// select result receive max
151-
int receiveMaxPublishes = packet.receiveMaxPublishes() == RECEIVE_MAXIMUM_PUBLISHES_UNDEFINED
151+
int receiveMaxPublishes = packet.receiveMaxPublishes() == RECEIVE_MAXIMUM_PUBLISHES_IS_NOT_SET
152152
? serverConfig.receiveMaxPublishes()
153153
: Math.min(packet.receiveMaxPublishes(), serverConfig.receiveMaxPublishes());
154154

155155
// select result maximum packet size
156-
var maximumPacketSize = packet.maxPacketSize() == MAXIMUM_MESSAGE_SIZE_UNDEFINED
156+
var maximumPacketSize = packet.maxPacketSize() == MAXIMUM_MESSAGE_SIZE_IS_NOT_SET
157157
? serverConfig.maxMessageSize()
158158
: Math.min(packet.maxPacketSize(), serverConfig.maxMessageSize());
159159

160160
// select result topic alias maximum
161-
var topicAliasMaxValue = packet.topicAliasMaxValue() == TOPIC_ALIAS_MAXIMUM_UNDEFINED
161+
var topicAliasMaxValue = packet.topicAliasMaxValue() == TOPIC_ALIAS_MAXIMUM_IS_NOT_SET
162162
? TOPIC_ALIAS_MAXIMUM_DISABLED
163163
: Math.min(packet.topicAliasMaxValue(), serverConfig.topicAliasMaxValue());
164164

core-service/src/main/java/javasabr/mqtt/service/message/handler/impl/PublishMqttInMessageHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private void handleInvalidTopicAlias(ExternalMqttClient client) {
204204
private void handleInvalidPayloadFormat(ExternalMqttClient client) {
205205
MqttOutMessage response = messageOutFactoryService
206206
.resolveFactory(client)
207-
.newDisconnect(client, DisconnectReasonCode.PROTOCOL_ERROR, MqttProtocolErrors.INVALID_PAYLOAD_FORMAT);
207+
.newDisconnect(client, DisconnectReasonCode.PROTOCOL_ERROR, MqttProtocolErrors.PROVIDED_INVALID_PAYLOAD_FORMAT);
208208
client.closeWithReason(response);
209209
}
210210

@@ -218,7 +218,7 @@ private void handleInvalidResponseTopicName(ExternalMqttClient client) {
218218
private void handleInvalidMessageExpiryInterval(ExternalMqttClient client) {
219219
MqttOutMessage response = messageOutFactoryService
220220
.resolveFactory(client)
221-
.newDisconnect(client, DisconnectReasonCode.PROTOCOL_ERROR, MqttProtocolErrors.INVALID_MESSAGE_EXPIRY_INTERVAL);
221+
.newDisconnect(client, DisconnectReasonCode.PROTOCOL_ERROR, MqttProtocolErrors.PROVIDED_INVALID_MESSAGE_EXPIRY_INTERVAL);
222222
client.closeWithReason(response);
223223
}
224224

core-service/src/main/java/javasabr/mqtt/service/message/out/factory/Mqtt311MessageOutFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ public MqttOutMessage newDisconnect(
111111
@Override
112112
public MqttOutMessage newAuthenticate(
113113
AuthenticateReasonCode reasonCode,
114-
String authenticateMethod,
115-
byte[] authenticateData,
116-
Array<StringPair> userProperties,
117-
String reason) {
114+
@Nullable String reason,
115+
@Nullable String authenticateMethod,
116+
byte @Nullable [] authenticateData,
117+
Array<StringPair> userProperties) {
118118
throw new UnsupportedOperationException();
119119
}
120120

core-service/src/main/java/javasabr/mqtt/service/message/out/factory/Mqtt5MessageOutFactory.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,16 @@ public MqttOutMessage newDisconnect(
141141
@Override
142142
public MqttOutMessage newAuthenticate(
143143
AuthenticateReasonCode reasonCode,
144-
String authenticateMethod,
145-
byte[] authenticateData,
146-
Array<StringPair> userProperties,
147-
String reason) {
148-
return new AuthenticationMqtt5OutMessage(userProperties, reasonCode, reason, authenticateMethod, authenticateData);
144+
@Nullable String reason,
145+
@Nullable String authenticateMethod,
146+
byte @Nullable [] authenticateData,
147+
Array<StringPair> userProperties) {
148+
return new AuthenticationMqtt5OutMessage(
149+
reasonCode,
150+
reason,
151+
authenticateMethod,
152+
authenticateData,
153+
userProperties);
149154
}
150155

151156
@Override

core-service/src/main/java/javasabr/mqtt/service/message/out/factory/MqttMessageOutFactory.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,21 @@ public MqttOutMessage newDisconnect(
201201

202202
public abstract MqttOutMessage newAuthenticate(
203203
AuthenticateReasonCode reasonCode,
204-
String authenticateMethod,
205-
byte[] authenticateData,
206-
Array<StringPair> userProperties,
207-
String reason);
204+
@Nullable String reason,
205+
@Nullable String authenticateMethod,
206+
byte @Nullable [] authenticateData,
207+
Array<StringPair> userProperties);
208208

209209
public MqttOutMessage newAuthenticate(
210210
AuthenticateReasonCode reasonCode,
211-
String authenticateMethod,
212-
byte[] authenticateData) {
211+
@Nullable String authenticateMethod,
212+
byte @Nullable [] authenticateData) {
213213
return newAuthenticate(
214214
reasonCode,
215+
null,
215216
authenticateMethod,
216-
authenticateData, EMPTY_USER_PROPERTIES,
217-
StringUtils.EMPTY);
217+
authenticateData,
218+
EMPTY_USER_PROPERTIES);
218219
}
219220

220221
public abstract MqttOutMessage newPingRequest();

core-service/src/test/groovy/javasabr/mqtt/service/message/handler/impl/PublishMqttInMessageHandlerTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class PublishMqttInMessageHandlerTest extends IntegrationServiceSpecification {
221221
then:
222222
def disconnectReason = mqttClient.nextSentMessage(DisconnectMqtt5OutMessage)
223223
disconnectReason.reasonCode() == DisconnectReasonCode.PROTOCOL_ERROR
224-
disconnectReason.reason() == MqttProtocolErrors.INVALID_PAYLOAD_FORMAT
224+
disconnectReason.reason() == MqttProtocolErrors.PROVIDED_INVALID_PAYLOAD_FORMAT
225225
disconnectReason.serverReference() == null
226226
}
227227

@@ -244,7 +244,7 @@ class PublishMqttInMessageHandlerTest extends IntegrationServiceSpecification {
244244
then:
245245
def disconnectReason = mqttClient.nextSentMessage(DisconnectMqtt5OutMessage)
246246
disconnectReason.reasonCode() == DisconnectReasonCode.PROTOCOL_ERROR
247-
disconnectReason.reason() == MqttProtocolErrors.INVALID_MESSAGE_EXPIRY_INTERVAL
247+
disconnectReason.reason() == MqttProtocolErrors.PROVIDED_INVALID_MESSAGE_EXPIRY_INTERVAL
248248
disconnectReason.serverReference() == null
249249
}
250250

model/src/main/java/javasabr/mqtt/model/MqttProperties.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ public interface MqttProperties {
1111
long SESSION_EXPIRY_INTERVAL_DEFAULT = 120;
1212
long SESSION_EXPIRY_INTERVAL_MIN = 0;
1313
long SESSION_EXPIRY_INTERVAL_INFINITY = 0xFFFFFFFFL;
14-
long SESSION_EXPIRY_INTERVAL_UNDEFINED = -1;
14+
long SESSION_EXPIRY_INTERVAL_IS_NOT_SET = -1;
1515

16-
int RECEIVE_MAXIMUM_PUBLISHES_UNDEFINED = -1;
16+
int RECEIVE_MAXIMUM_PUBLISHES_IS_NOT_SET = 0;
1717
int RECEIVE_MAXIMUM_PUBLISHES_MIN = 1;
18-
int RECEIVE_MAXIMUM_PUBLISHES_DEFAULT = 10;
1918
int RECEIVE_MAXIMUM_PUBLISHES_MAX = 0xFFFF;
19+
int RECEIVE_MAXIMUM_PUBLISHES_DEFAULT = RECEIVE_MAXIMUM_PUBLISHES_MAX;
2020

21-
int MAXIMUM_MESSAGE_SIZE_UNDEFINED = -1;
21+
int MAXIMUM_MESSAGE_SIZE_IS_NOT_SET = -1;
2222
int MAXIMUM_MESSAGE_SIZE_DEFAULT = 3074;
23-
int MAXIMUM_MESSAGE_SIZE_MIN = 128;
23+
int MAXIMUM_MESSAGE_SIZE_MIN = 64;
2424
int MAXIMUM_MESSAGE_SIZE_MAX = MAXIMUM_PROTOCOL_MESSAGE_SIZE;
2525

2626
int MAXIMUM_STRING_LENGTH = 1024;
@@ -31,10 +31,10 @@ public interface MqttProperties {
3131
long MESSAGE_EXPIRY_INTERVAL_INFINITY = 0;
3232
long MESSAGE_EXPIRY_INTERVAL_MIN = 0;
3333

34-
int TOPIC_ALIAS_MAXIMUM_UNDEFINED = -1;
34+
int TOPIC_ALIAS_MAXIMUM_IS_NOT_SET = 0;
3535
int TOPIC_ALIAS_MAXIMUM_DISABLED = 0;
3636

37-
int SERVER_KEEP_ALIVE_UNDEFINED = -1;
37+
int SERVER_KEEP_ALIVE_IS_NOT_SET = -1;
3838
int SERVER_KEEP_ALIVE_DISABLED = 0;
3939
int SERVER_KEEP_ALIVE_DEFAULT = 0;
4040
int SERVER_KEEP_ALIVE_MIN = 0;
@@ -52,12 +52,18 @@ public interface MqttProperties {
5252

5353
int MESSAGE_ID_IS_NOT_SET = 0;
5454

55-
boolean SESSIONS_ENABLED_DEFAULT = true;
56-
boolean KEEP_ALIVE_ENABLED_DEFAULT = false;
57-
boolean RETAIN_AVAILABLE_DEFAULT = false;
58-
boolean WILDCARD_SUBSCRIPTION_AVAILABLE_DEFAULT = false;
59-
boolean SHARED_SUBSCRIPTION_AVAILABLE_DEFAULT = false;
55+
boolean RETAIN_AVAILABLE_DEFAULT = true;
56+
int RETAIN_AVAILABLE_IS_NOT_SET = -1;
57+
58+
boolean WILDCARD_SUBSCRIPTION_AVAILABLE_DEFAULT = true;
59+
int WILDCARD_SUBSCRIPTION_AVAILABLE_IS_NOT_SET = -1;
60+
6061
boolean SUBSCRIPTION_IDENTIFIER_AVAILABLE_DEFAULT = true;
62+
int SUBSCRIPTION_IDENTIFIER_AVAILABLE_IS_NOT_SET = -1;
6163

62-
int PACKET_ID_FOR_QOS_0 = 0;
64+
boolean SHARED_SUBSCRIPTION_AVAILABLE_DEFAULT = true;
65+
int SHARED_SUBSCRIPTION_AVAILABLE_IS_NOT_SET = -1;
66+
67+
boolean SESSIONS_ENABLED_DEFAULT = true;
68+
boolean KEEP_ALIVE_ENABLED_DEFAULT = false;
6369
}

model/src/main/java/javasabr/mqtt/model/MqttProtocolErrors.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ public interface MqttProtocolErrors {
44
String NO_ANY_TOPIC_FILTERS = "Not provided any information about 'Topic Filters'";
55
String NO_ANY_TOPIC_NANE = "Not provided any information about TopicName";
66
//String INVALID_TOPIC_ALIAS = "Provided invalid TopicAlias";
7-
String INVALID_PAYLOAD_FORMAT = "Provided invalid PayloadFormat";
8-
String INVALID_MESSAGE_EXPIRY_INTERVAL = "Provided invalid MessageExpiryInterval";
7+
8+
String PROVIDED_INVALID_PAYLOAD_FORMAT = "Provided invalid PayloadFormat";
9+
String PROVIDED_INVALID_MESSAGE_EXPIRY_INTERVAL = "Provided invalid MessageExpiryInterval";
10+
String PROVIDED_INVALID_SESSION_EXPIRY_INTERVAL = "Provided invalid 'Session Expiry Interval'";
11+
String PROVIDED_INVALID_RECEIVED_MAX_PUBLISHES = "Provided invalid 'Receive Maximum'";
12+
String PROVIDED_INVALID_MAX_QOS = "Provided invalid 'Maximum QoS'";
13+
String PROVIDED_INVALID_RETAIN_AVAILABLE = "Provided invalid 'Retain Available'";
14+
String PROVIDED_INVALID_MAX_MESSAGE_SIZE = "Provided invalid 'Maximum Packet Size'";
15+
String PROVIDED_INVALID_TOPIC_ALIAS_MAX = "Provided invalid 'Topic Alias Maximum'";
16+
String PROVIDED_INVALID_WILDCARD_SUBSCRIPTION_AVAILABLE = "Provided invalid 'Wildcard Subscription Available'";
17+
String PROVIDED_INVALID_SUBSCRIPTION_IDENTIFIERS_AVAILABLE = "Provided invalid 'Subscription Identifiers Available'";
18+
String PROVIDED_INVALID_SHARED_SUBSCRIPTION_AVAILABLE = "Provided invalid 'Shared Subscription Available'";
19+
String PROVIDED_INVALID_SERVER_KEEP_ALIVE = "Provided invalid 'Server Keep Alive'";
20+
921
String INVALID_RESPONSE_TOPIC_NAME = "Provided invalid ResponseTopicName";
1022
String UNSUPPORTED_QOS_OR_RETAIN_HANDLING = "Provided unsupported 'QoS' or 'RetainHandling'";
1123
String MISSED_REQUIRED_MESSAGE_ID = "'Packet Identifier' must be presented'";
Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,40 @@
11
package javasabr.mqtt.model.reason.code;
22

3-
import java.util.stream.Stream;
4-
import javasabr.rlib.common.util.ObjectUtils;
3+
import javasabr.rlib.common.util.NumberedEnum;
4+
import javasabr.rlib.common.util.NumberedEnumMap;
55
import lombok.Getter;
66
import lombok.RequiredArgsConstructor;
7+
import lombok.experimental.Accessors;
78

9+
@Getter
10+
@Accessors
811
@RequiredArgsConstructor
9-
public enum AuthenticateReasonCode {
12+
public enum AuthenticateReasonCode implements NumberedEnum<AuthenticateReasonCode>, ReasonCode {
1013

1114
/**
1215
* Authentication is successful. Server.
1316
*/
14-
SUCCESS((byte) 0x00),
17+
SUCCESS(0x00),
1518
/**
1619
* Continue the authentication with another step. Client or Server.
1720
*/
18-
CONTINUE_AUTHENTICATION((byte) 0x18),
21+
CONTINUE_AUTHENTICATION(0x18),
1922
/**
2023
* Initiate a re-authentication. Client.
2124
*/
22-
RE_AUTHENTICATE((byte) 0x19);
25+
RE_AUTHENTICATE(0x19);
2326

24-
private static final AuthenticateReasonCode[] VALUES;
27+
private static final NumberedEnumMap<AuthenticateReasonCode> NUMBERED_MAP =
28+
new NumberedEnumMap<>(AuthenticateReasonCode.class);
2529

26-
static {
27-
28-
var maxId = Stream
29-
.of(values())
30-
.mapToInt(AuthenticateReasonCode::value)
31-
.max()
32-
.orElse(0);
33-
34-
var values = new AuthenticateReasonCode[maxId + 1];
35-
36-
for (var value : values()) {
37-
values[value.value] = value;
38-
}
39-
40-
VALUES = values;
30+
public static AuthenticateReasonCode ofCode(int code) {
31+
return NUMBERED_MAP.require(code);
4132
}
4233

43-
public static AuthenticateReasonCode of(int index) {
44-
return ObjectUtils.notNull(
45-
VALUES[index],
46-
index,
47-
arg -> new IndexOutOfBoundsException("Doesn't support reason code: " + arg));
48-
}
34+
private final int code;
4935

50-
private @Getter
51-
final byte value;
36+
@Override
37+
public int number() {
38+
return code;
39+
}
5240
}

0 commit comments

Comments
 (0)