@Test public void testCompleteHeaderWIthUser_password() throws Exception { ConnectMessage msg = new ConnectMessage(); msg.setUserFlag(true); msg.setPasswordFlag(true); msg.setWillRetain(true); msg.setWillQos((byte)2); msg.setWillFlag(true); msg.setCleanSession(true); msg.setKeepAlive(512); msg.setClientID("ABCDEF"); msg.setWillTopic("Topic"); msg.setWillMessage("Message"); msg.setUsername("Pablo"); msg.setPassword("PBL"); m_encoder.encode(null, msg, m_mockProtoEncoder); assertEquals(0x10, m_mockProtoEncoder.getBuffer().get()); assertEquals(48, m_mockProtoEncoder.getBuffer().get()); verifyString("MQIsdp", m_mockProtoEncoder.getBuffer()); assertEquals(0x03, m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)0xF6, (byte)m_mockProtoEncoder.getBuffer().get()); assertEquals(2, m_mockProtoEncoder.getBuffer().get()); assertEquals(0, m_mockProtoEncoder.getBuffer().get()); verifyString("ABCDEF", m_mockProtoEncoder.getBuffer()); verifyString("Topic", m_mockProtoEncoder.getBuffer()); verifyString("Message", m_mockProtoEncoder.getBuffer()); verifyString("Pablo", m_mockProtoEncoder.getBuffer()); verifyString("PBL", m_mockProtoEncoder.getBuffer()); }
public void encode(IoSession session, ConnectMessage message, ProtocolEncoderOutput out) throws Exception { IoBuffer staticHeaderBuff = IoBuffer.allocate(12); staticHeaderBuff.put(Utils.encodeString("MQIsdp")); staticHeaderBuff.put((byte)0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.put(connectionFlags); Utils.writeWord(staticHeaderBuff, message.getKeepAlive()); staticHeaderBuff.flip(); IoBuffer variableHeaderBuff = IoBuffer.allocate(12).setAutoExpand(true); if (message.getClientID() != null) { variableHeaderBuff.put(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.put(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.put(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.put(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.put(Utils.encodeString(message.getPassword())); } } } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); IoBuffer buff = IoBuffer.allocate(14 + variableHeaderSize); buff.put((byte) (AbstractMessage.CONNECT << 4)); buff.put(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.put(staticHeaderBuff).put(variableHeaderBuff).flip(); out.write(buff); }
ConnectEncoder implements MessageEncoder<ConnectMessage> { public void encode(IoSession session, ConnectMessage message, ProtocolEncoderOutput out) throws Exception { IoBuffer staticHeaderBuff = IoBuffer.allocate(12); staticHeaderBuff.put(Utils.encodeString("MQIsdp")); staticHeaderBuff.put((byte)0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.put(connectionFlags); Utils.writeWord(staticHeaderBuff, message.getKeepAlive()); staticHeaderBuff.flip(); IoBuffer variableHeaderBuff = IoBuffer.allocate(12).setAutoExpand(true); if (message.getClientID() != null) { variableHeaderBuff.put(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.put(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.put(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.put(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.put(Utils.encodeString(message.getPassword())); } } } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); IoBuffer buff = IoBuffer.allocate(14 + variableHeaderSize); buff.put((byte) (AbstractMessage.CONNECT << 4)); buff.put(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.put(staticHeaderBuff).put(variableHeaderBuff).flip(); out.write(buff); } }
ConnectEncoder implements MessageEncoder<ConnectMessage> { public void encode(IoSession session, ConnectMessage message, ProtocolEncoderOutput out) throws Exception { IoBuffer staticHeaderBuff = IoBuffer.allocate(12); staticHeaderBuff.put(Utils.encodeString("MQIsdp")); staticHeaderBuff.put((byte)0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.put(connectionFlags); Utils.writeWord(staticHeaderBuff, message.getKeepAlive()); staticHeaderBuff.flip(); IoBuffer variableHeaderBuff = IoBuffer.allocate(12).setAutoExpand(true); if (message.getClientID() != null) { variableHeaderBuff.put(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.put(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.put(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.put(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.put(Utils.encodeString(message.getPassword())); } } } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); IoBuffer buff = IoBuffer.allocate(14 + variableHeaderSize); buff.put((byte) (AbstractMessage.CONNECT << 4)); buff.put(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.put(staticHeaderBuff).put(variableHeaderBuff).flip(); out.write(buff); }  }
ConnectEncoder implements MessageEncoder<ConnectMessage> { public void encode(IoSession session, ConnectMessage message, ProtocolEncoderOutput out) throws Exception { IoBuffer staticHeaderBuff = IoBuffer.allocate(12); staticHeaderBuff.put(Utils.encodeString("MQIsdp")); staticHeaderBuff.put((byte)0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.put(connectionFlags); Utils.writeWord(staticHeaderBuff, message.getKeepAlive()); staticHeaderBuff.flip(); IoBuffer variableHeaderBuff = IoBuffer.allocate(12).setAutoExpand(true); if (message.getClientID() != null) { variableHeaderBuff.put(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.put(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.put(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.put(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.put(Utils.encodeString(message.getPassword())); } } } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); IoBuffer buff = IoBuffer.allocate(14 + variableHeaderSize); buff.put((byte) (AbstractMessage.CONNECT << 4)); buff.put(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.put(staticHeaderBuff).put(variableHeaderBuff).flip(); out.write(buff); }  void encode(IoSession session, ConnectMessage message, ProtocolEncoderOutput out); }
ConnectEncoder implements MessageEncoder<ConnectMessage> { public void encode(IoSession session, ConnectMessage message, ProtocolEncoderOutput out) throws Exception { IoBuffer staticHeaderBuff = IoBuffer.allocate(12); staticHeaderBuff.put(Utils.encodeString("MQIsdp")); staticHeaderBuff.put((byte)0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.put(connectionFlags); Utils.writeWord(staticHeaderBuff, message.getKeepAlive()); staticHeaderBuff.flip(); IoBuffer variableHeaderBuff = IoBuffer.allocate(12).setAutoExpand(true); if (message.getClientID() != null) { variableHeaderBuff.put(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.put(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.put(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.put(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.put(Utils.encodeString(message.getPassword())); } } } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); IoBuffer buff = IoBuffer.allocate(14 + variableHeaderSize); buff.put((byte) (AbstractMessage.CONNECT << 4)); buff.put(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.put(staticHeaderBuff).put(variableHeaderBuff).flip(); out.write(buff); }  void encode(IoSession session, ConnectMessage message, ProtocolEncoderOutput out);  }