use of io.netty.handler.codec.stomp.DefaultStompFrame in project alien4cloud by alien4cloud.
the class StompClientHandler method beginStomp.
public void beginStomp(Channel channel) throws Exception {
StompFrame connFrame = new DefaultStompFrame(StompCommand.CONNECT);
connFrame.headers().set(StompHeaders.ACCEPT_VERSION, "1.2");
channel.writeAndFlush(connFrame);
if (log.isDebugEnabled()) {
log.debug("Begin web socket connection");
}
}
use of io.netty.handler.codec.stomp.DefaultStompFrame in project netty by netty.
the class StompClientHandler method channelActive.
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
state = ClientState.AUTHENTICATING;
StompFrame connFrame = new DefaultStompFrame(StompCommand.CONNECT);
connFrame.headers().set(StompHeaders.ACCEPT_VERSION, "1.2");
connFrame.headers().set(StompHeaders.HOST, StompClient.HOST);
connFrame.headers().set(StompHeaders.LOGIN, StompClient.LOGIN);
connFrame.headers().set(StompHeaders.PASSCODE, StompClient.PASSCODE);
ctx.writeAndFlush(connFrame);
}
use of io.netty.handler.codec.stomp.DefaultStompFrame in project netty by netty.
the class StompChatHandler method onSubscribe.
private void onSubscribe(ChannelHandlerContext ctx, StompFrame inboundFrame) {
String destination = inboundFrame.headers().getAsString(DESTINATION);
String subscriptionId = inboundFrame.headers().getAsString(ID);
if (destination == null || subscriptionId == null) {
sendErrorFrame("missed header", "Required 'destination' or 'id' header missed", ctx);
return;
}
Set<StompSubscription> subscriptions = chatDestinations.get(destination);
if (subscriptions == null) {
subscriptions = new HashSet<StompSubscription>();
Set<StompSubscription> previousSubscriptions = chatDestinations.putIfAbsent(destination, subscriptions);
if (previousSubscriptions != null) {
subscriptions = previousSubscriptions;
}
}
final StompSubscription subscription = new StompSubscription(subscriptionId, destination, ctx.channel());
if (subscriptions.contains(subscription)) {
sendErrorFrame("duplicate subscription", "Received duplicate subscription id=" + subscriptionId, ctx);
return;
}
subscriptions.add(subscription);
ctx.channel().closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
chatDestinations.get(subscription.destination()).remove(subscription);
}
});
String receiptId = inboundFrame.headers().getAsString(RECEIPT);
if (receiptId != null) {
StompFrame receiptFrame = new DefaultStompFrame(StompCommand.RECEIPT);
receiptFrame.headers().set(RECEIPT_ID, receiptId);
ctx.writeAndFlush(receiptFrame);
}
}
use of io.netty.handler.codec.stomp.DefaultStompFrame in project netty by netty.
the class StompChatHandler method onConnect.
private static void onConnect(ChannelHandlerContext ctx, StompFrame inboundFrame) {
String acceptVersions = inboundFrame.headers().getAsString(ACCEPT_VERSION);
StompVersion handshakeAcceptVersion = ctx.channel().attr(StompVersion.CHANNEL_ATTRIBUTE_KEY).get();
if (acceptVersions == null || !acceptVersions.contains(handshakeAcceptVersion.version())) {
sendErrorFrame("invalid version", "Received invalid version, expected " + handshakeAcceptVersion.version(), ctx);
return;
}
StompFrame connectedFrame = new DefaultStompFrame(StompCommand.CONNECTED);
connectedFrame.headers().set(VERSION, handshakeAcceptVersion.version()).set(SERVER, "Netty-Server").set(HEART_BEAT, "0,0");
ctx.writeAndFlush(connectedFrame);
}
use of io.netty.handler.codec.stomp.DefaultStompFrame in project netty by netty.
the class StompChatHandler method onDisconnect.
private static void onDisconnect(ChannelHandlerContext ctx, StompFrame inboundFrame) {
String receiptId = inboundFrame.headers().getAsString(RECEIPT);
if (receiptId == null) {
ctx.close();
return;
}
StompFrame receiptFrame = new DefaultStompFrame(StompCommand.RECEIPT);
receiptFrame.headers().set(RECEIPT_ID, receiptId);
ctx.writeAndFlush(receiptFrame).addListener(ChannelFutureListener.CLOSE);
}
Aggregations