本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttConnAckMessage类的典型用法代码示例。如果您正苦于以下问题:Java MqttConnAckMessage类的具体用法?Java MqttConnAckMessage怎么用?Java MqttConnAckMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MqttConnAckMessage类属于io.netty.handler.codec.mqtt包,在下文中一共展示了MqttConnAckMessage类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCONNECTION_REFUSED_SERVER_UNAVAILABLE
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
@Test
public void testCONNECTION_REFUSED_SERVER_UNAVAILABLE() throws Exception {
ServiceChecker prev = Plugins.INSTANCE.put(ServiceChecker.class, new ServiceChecker() {
@Override
public Plugin clone() {
return this;
}
@Override
public boolean isServiceAvailable() {
return false;
}
});
MqttConnAckMessage ret = executeNormalChannelRead0(TestUtil.newClientId(), true, null);
Assert.assertEquals(ret.variableHeader().connectReturnCode(),
MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE);
Plugins.INSTANCE.put(ServiceChecker.class, prev);
}
示例2: testCONNECTION_REFUSED_NOT_AUTHORIZED
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
@Test
public void testCONNECTION_REFUSED_NOT_AUTHORIZED() throws Exception {
Authorizer prev = Plugins.INSTANCE.put(Authorizer.class, new Authorizer() {
@Override
public Plugin clone() {
return this;
}
@Override
public boolean isAuthorized(String clientId, String username) {
return false;
}
});
MqttConnAckMessage ret = executeNormalChannelRead0(TestUtil.newClientId(), true, null);
Assert.assertEquals(ret.variableHeader().connectReturnCode(),
MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED);
Plugins.INSTANCE.put(Authorizer.class, prev);
}
示例3: executeNormalChannelRead0
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
private MqttConnAckMessage executeNormalChannelRead0(String clientId, boolean cleanSession, ChannelId channelId)
throws Exception {
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
10);
MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader("MQTT", 4, true, true, true, 0, true,
cleanSession, 60);
MqttConnectPayload payload = new MqttConnectPayload(clientId, "willtopic", "willmessage", "username",
"password");
MqttConnectMessage msg = new MqttConnectMessage(fixedHeader, variableHeader, payload);
ChannelId cid = channelId == null ? TestUtil.newChannelId(clientId, false) : channelId;
EmbeddedChannel channel = new EmbeddedChannel(cid, new ConnectReceiver());
channel.writeInbound(msg);
return channel.readOutbound();
}
示例4: connack
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
public static MqttConnAckMessage connack(MqttConnectReturnCode returnCode, boolean sessionPresent) {
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false,
2);
MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
return new MqttConnAckMessage(fixedHeader, variableHeader);
}
示例5: testCleanSessionWithoutClientIdReturnFalse
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
@Test
public void testCleanSessionWithoutClientIdReturnFalse() throws Exception {
Settings.INSTANCE.setProperty("mqttserver.acceptEmptyClientId", "false");
MqttConnAckMessage ret = executeNormalChannelRead0("", true, null);
Assert.assertEquals(MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED,
ret.variableHeader().connectReturnCode());
Settings.INSTANCE.setProperty("mqttserver.acceptEmptyClientId", "true");
}
示例6: nonCleanSession
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
@Test
public void nonCleanSession() throws Exception {
String clientId = TestUtil.newClientId();
MqttConnAckMessage ret = executeNormalChannelRead0(clientId, false, null);
Assert.assertEquals(ret.variableHeader().connectReturnCode(), MqttConnectReturnCode.CONNECTION_ACCEPTED);
}
示例7: assertEqualsConnAck
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
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());
}
示例8: createMqttConnAckMsg
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
private MqttConnAckMessage createMqttConnAckMsg(MqttConnectReturnCode returnCode) {
MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(CONNACK, false, AT_MOST_ONCE, false, 0);
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, true);
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader);
}
示例9: connect
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
public MqttConnectReturnCode connect() throws InterruptedException {
Class<? extends SocketChannel> socketChannelClass;
if (Literals.NETTY_EPOLL.equals(Settings.INSTANCE.nettyTransportMode())) {
group = new EpollEventLoopGroup(1, new DefaultThreadFactory("client"));
socketChannelClass = EpollSocketChannel.class;
}
else {
group = new NioEventLoopGroup(1, new DefaultThreadFactory("client"));
socketChannelClass = NioSocketChannel.class;
}
bootstrap.group(group).channel(socketChannelClass).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
if ("mqtts".equalsIgnoreCase(uri.getScheme())) {
SslContext sslCtx = SslContextBuilder.forClient().trustManager(trustManagerFactory).build();
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc(), uri.getHost(), uri.getPort()));
}
ch.pipeline().addLast(MqttDecoder.class.getName(), new MqttDecoder());
ch.pipeline().addLast(MqttEncoder.class.getName(), MqttEncoder.INSTANCE);
ch.pipeline().addLast(MqttPacketReceiver.class.getName(),
new MqttPacketReceiver(MqttClient.this, receiver, sharedObject));
}
});
channel = bootstrap.connect(uri.getHost(), uri.getPort()).sync().channel();
normalizeMessage(options.will());
send(MqttMessageFactory.connect(options));
synchronized (sharedObject.locker()) {
int timeout = Settings.INSTANCE.getInt("mqttclient.responseTimeoutSeconds", 15);
sharedObject.locker().wait(timeout * 1000);
}
if (sharedObject.receivedMessage() == null) { return null; }
return ((MqttConnAckMessage) sharedObject.receivedMessage()).variableHeader().connectReturnCode();
}
示例10: testDefaultChannelRead0
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
@Test
public void testDefaultChannelRead0() throws Exception {
MqttConnAckMessage ret = executeNormalChannelRead0(TestUtil.newClientId(), true, null);
Assert.assertEquals(ret.variableHeader().connectReturnCode(), MqttConnectReturnCode.CONNECTION_ACCEPTED);
}
示例11: testCleanSessionWithoutClientIdReturnTrue
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
@Test
public void testCleanSessionWithoutClientIdReturnTrue() throws Exception {
MqttConnAckMessage ret = executeNormalChannelRead0("", true, null);
Assert.assertEquals(MqttConnectReturnCode.CONNECTION_ACCEPTED, ret.variableHeader().connectReturnCode());
}
示例12: createConnAckMessage
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
private static MqttConnAckMessage createConnAckMessage(MqttConnectReturnCode code) {
MqttFixedHeader mqttFixedHeader =
new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 2);
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(code, true);
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader);
}
示例13: sendConnack
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
void sendConnack(MqttConnectReturnCode returnCode) {
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttConnAckVariableHeader varHeader = new MqttConnAckVariableHeader(returnCode, true);
MqttConnAckMessage message = new MqttConnAckMessage(fixedHeader, varHeader);
sendToClient(message);
}
示例14: cleanSessionOnSameClientIdSession
import io.netty.handler.codec.mqtt.MqttConnAckMessage; //导入依赖的package包/类
@Test
public void cleanSessionOnSameClientIdSession() throws Exception {
String clientId = TestUtil.newClientId();
executeNormalChannelRead0(clientId, true, null);
MqttConnAckMessage ret = executeNormalChannelRead0(clientId, true, null);
Assert.assertEquals(ret.variableHeader().connectReturnCode(), MqttConnectReturnCode.CONNECTION_ACCEPTED);
}