Skip to content

Commit

Permalink
fix Deprecated Warning.
Browse files Browse the repository at this point in the history
* messageId
* password
* willMessage
  • Loading branch information
dushibaiyu committed Jun 15, 2018
1 parent 93c88e1 commit 12ab54f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/main/java/io/vertx/mqtt/MqttAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.vertx.mqtt;

import io.netty.util.CharsetUtil;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;

Expand All @@ -39,6 +40,16 @@ public MqttAuth(String userName, String password) {
this.password = password;
}

/**
* Constructor
*
* @param userName MQTT client username
* @param passwordBytes MQTT client password
*/
public MqttAuth(String userName, byte[] passwordBytes) {
this.userName = userName;
this.password = (passwordBytes == null ? null : new String(passwordBytes, CharsetUtil.UTF_8));;
}
/**
* Create instance from JSON
*
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/vertx/mqtt/MqttWill.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.vertx.mqtt;

import io.netty.util.CharsetUtil;
import io.vertx.codegen.annotations.CacheReturn;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -49,6 +50,23 @@ public MqttWill(boolean isWillFlag, String willTopic, String willMessage, int wi
this.isWillRetain = isWillRetain;
}

/**
* Constructor
*
* @param isWillFlag indicates will message presence
* @param willTopic topic to publish the will
* @param willMessageBytes payload of the will
* @param willQos qos level for the will
* @param isWillRetain if the will message must be retained
*/
public MqttWill(boolean isWillFlag, String willTopic, byte[] willMessageBytes, int willQos, boolean isWillRetain) {
this.isWillFlag = isWillFlag;
this.willTopic = willTopic;
this.willMessage = (willMessageBytes == null ? null : new String(willMessageBytes, CharsetUtil.UTF_8));
this.willQos = willQos;
this.isWillRetain = isWillRetain;
}

/**
* Create instance from JSON
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/mqtt/impl/MqttClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void handleMessage(Object msg) {
ByteBuf newBuf = VertxHandler.safeBuffer(publish.payload(), chctx.alloc());

MqttPublishMessage mqttPublishMessage = MqttPublishMessage.create(
publish.variableHeader().messageId(),
publish.variableHeader().packetId(),
publish.fixedHeader().qosLevel(),
publish.fixedHeader().isDup(),
publish.fixedHeader().isRetain(),
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/mqtt/impl/MqttClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,19 @@ public MqttClient publish(String topic, Buffer payload, MqttQoS qosLevel, boolea

switch (qosLevel) {
case AT_LEAST_ONCE:
qos1outbound.put(variableHeader.messageId(), publish);
qos1outbound.put(variableHeader.packetId(), publish);
countInflightQueue++;
break;
case EXACTLY_ONCE:
qos2outbound.put(variableHeader.messageId(), publish);
qos2outbound.put(variableHeader.packetId(), publish);
countInflightQueue++;
break;
}

this.write(publish);

if (publishSentHandler != null) {
publishSentHandler.handle(Future.succeededFuture(variableHeader.messageId()));
publishSentHandler.handle(Future.succeededFuture(variableHeader.packetId()));
}

return this;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/mqtt/impl/MqttEndpointImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public MqttEndpointImpl publish(String topic, Buffer payload, MqttQoS qosLevel,
this.write(publish);

if (publishSentHandler != null) {
publishSentHandler.handle(Future.succeededFuture(variableHeader.messageId()));
publishSentHandler.handle(Future.succeededFuture(variableHeader.packetId()));
}

return this;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/mqtt/impl/MqttServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ synchronized void handleMessage(Object msg) {
ByteBuf newBuf = VertxHandler.safeBuffer(publish.payload(), this.chctx.alloc());

MqttPublishMessage mqttPublishMessage = MqttPublishMessage.create(
publish.variableHeader().messageId(),
publish.variableHeader().packetId(),
publish.fixedHeader().qosLevel(),
publish.fixedHeader().isDup(),
publish.fixedHeader().isRetain(),
Expand Down Expand Up @@ -206,7 +206,7 @@ private void handleConnect(MqttConnectMessage msg) {
MqttWill will =
new MqttWill(msg.variableHeader().isWillFlag(),
msg.payload().willTopic(),
msg.payload().willMessage(),
msg.payload().willMessageInBytes(),
msg.variableHeader().willQos(),
msg.variableHeader().isWillRetain());

Expand All @@ -215,7 +215,7 @@ private void handleConnect(MqttConnectMessage msg) {
msg.variableHeader().hasPassword()) ?
new MqttAuth(
msg.payload().userName(),
msg.payload().password()) : null;
msg.payload().passwordInBytes()) : null;

// check if remote MQTT client didn't specify a client-id
boolean isZeroBytes = (msg.payload().clientIdentifier() == null) ||
Expand Down

0 comments on commit 12ab54f

Please sign in to comment.