private static ByteBuf encodeConnAckMessage( ByteBufAllocator byteBufAllocator, MqttConnAckMessage message) { ByteBuf buf = byteBufAllocator.buffer(4); buf.writeByte(getFixedHeaderByte1(message.fixedHeader())); buf.writeByte(2); buf.writeByte(message.variableHeader().isSessionPresent() ? 0x01 : 0x00); buf.writeByte(message.variableHeader().connectReturnCode().byteValue()); return buf; }
public static void assertEqualsConnAck(String msg, MqttConnectReturnCode expectedCode, Object connAck) { assertTrue("connAck is not an instance of ConnAckMessage", connAck instanceof MqttConnAckMessage); MqttConnAckMessage connAckMsg = (MqttConnAckMessage) connAck; if (msg == null) assertEquals(expectedCode, connAckMsg.variableHeader().connectReturnCode()); else assertEquals(msg, expectedCode, connAckMsg.variableHeader().connectReturnCode()); }
static void assertConnectAccepted(EmbeddedChannel channel) { MqttConnAckMessage connAck = channel.readOutbound(); final MqttConnectReturnCode connAckReturnCode = connAck.variableHeader().connectReturnCode(); assertEquals("Connect must be accepted", CONNECTION_ACCEPTED, connAckReturnCode); }
@Test public void testRejectConnectWithEmptyClientID() throws InterruptedException { LOG.info("*** testRejectConnectWithEmptyClientID ***"); m_client.clientId("").connect(); this.receivedMsg = this.m_client.lastReceivedMessage(); assertTrue(receivedMsg instanceof MqttConnAckMessage); MqttConnAckMessage connAck = (MqttConnAckMessage) receivedMsg; assertEquals(CONNECTION_REFUSED_IDENTIFIER_REJECTED, connAck.variableHeader().connectReturnCode()); }
protected void connect() { MqttConnectMessage connectMessage = MqttMessageBuilders.connect() .clientId(FAKE_CLIENT_ID) .build(); connection.processConnect(connectMessage); MqttConnAckMessage connAck = channel.readOutbound(); assertEquals("Connect must be accepted", CONNECTION_ACCEPTED, connAck.variableHeader().connectReturnCode()); }
public void connectBack(MqttConnAckMessage mqttConnAckMessage){ MqttConnAckVariableHeader mqttConnAckVariableHeader = mqttConnAckMessage.variableHeader(); switch ( mqttConnAckVariableHeader.connectReturnCode()){ case CONNECTION_ACCEPTED: countDownLatch.countDown(); break; case CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD: log.error("login error", new RuntimeException("用户名密码错误")); break; case CONNECTION_REFUSED_IDENTIFIER_REJECTED: log.error("login error", new RuntimeException("clientId 不允许链接")); break; case CONNECTION_REFUSED_SERVER_UNAVAILABLE: log.error("login error", new RuntimeException("服务不可用")); break; case CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION: log.error("login error", new RuntimeException("mqtt 版本不可用")); break; case CONNECTION_REFUSED_NOT_AUTHORIZED: log.error("login error", new RuntimeException("未授权登录")); break; } }
private static ByteBuf encodeConnAckMessage( ByteBufAllocator byteBufAllocator, MqttConnAckMessage message) { ByteBuf buf = byteBufAllocator.buffer(4); buf.writeByte(getFixedHeaderByte1(message.fixedHeader())); buf.writeByte(2); buf.writeByte(message.variableHeader().isSessionPresent() ? 0x01 : 0x00); buf.writeByte(message.variableHeader().connectReturnCode().byteValue()); return buf; }
private static ByteBuf encodeConnAckMessage( ByteBufAllocator byteBufAllocator, MqttConnAckMessage message) { ByteBuf buf = byteBufAllocator.buffer(4); buf.writeByte(getFixedHeaderByte1(message.fixedHeader())); buf.writeByte(2); buf.writeByte(message.variableHeader().sessionPresent() ? 0x01 : 0x00); buf.writeByte(message.variableHeader().returnCode().byteValue()); return buf; }
@Test public void testConnAckMessage() throws Exception { final MqttConnAckMessage message = createConnAckMessage(); ByteBuf byteBuf = MqttEncoder.doEncode(ALLOCATOR, message); final List<Object> out = new LinkedList<>(); mqttDecoder.decode(ctx, byteBuf, out); assertEquals("Expected one object bout got " + out.size(), 1, out.size()); final MqttConnAckMessage decodedMessage = (MqttConnAckMessage) out.get(0); validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader()); validateConnAckVariableHeader(message.variableHeader(), decodedMessage.variableHeader()); }
connack.variableHeader().connectReturnCode(), connack.variableHeader().isSessionPresent()); handleConnack(mqttConnAckMessage); break;
connack.variableHeader().connectReturnCode(), connack.variableHeader().isSessionPresent()); handleConnack(mqttConnAckMessage); break;