use of io.netty.handler.codec.stomp.StompSubframeAggregator in project alien4cloud by alien4cloud.
the class StompConnection method init.
@SneakyThrows({ InterruptedException.class, URISyntaxException.class })
private void init() {
if (this.stompChannel != null) {
throw new IllegalStateException("The stomp connection has already been started");
}
String wsUrl = "ws://" + host + ":" + port + endPoint + "/websocket";
if (log.isDebugEnabled()) {
log.debug("Web socket url {}", wsUrl);
}
String loginUrl = null;
if (user != null && password != null && loginPath != null) {
loginUrl = "http://" + host + ":" + port + loginPath;
if (log.isDebugEnabled()) {
log.debug("Authentication url {}", loginUrl);
}
}
this.eventLoopGroup = new NioEventLoopGroup();
this.stompClientHandler = new StompClientHandler();
DefaultHttpHeaders handshakeHeaders = new DefaultHttpHeaders();
if (this.headers != null) {
for (Map.Entry<String, String> header : this.headers.entrySet()) {
handshakeHeaders.add(header.getKey(), header.getValue());
}
}
final WebSocketClientHandler webSocketHandler = new WebSocketClientHandler(WebSocketClientHandshakerFactory.newHandshaker(new URI(wsUrl), WebSocketVersion.V13, null, false, handshakeHeaders), host, user, password, loginUrl);
Bootstrap b = new Bootstrap();
b.group(eventLoopGroup).channel(NioSocketChannel.class);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(HttpClientCodec.class.getName(), new HttpClientCodec());
pipeline.addLast(HttpObjectAggregator.class.getName(), new HttpObjectAggregator(8192));
pipeline.addLast(WebSocketClientCompressionHandler.class.getName(), new WebSocketClientCompressionHandler());
pipeline.addLast(WebSocketClientHandler.class.getName(), webSocketHandler);
pipeline.addLast(StompSubframeDecoder.class.getName(), new StompSubframeDecoder());
pipeline.addLast(StompSubframeEncoder.class.getName(), new StompSubframeEncoder());
pipeline.addLast(StompSubframeAggregator.class.getName(), new StompSubframeAggregator(1048576));
pipeline.addLast(StompClientHandler.class.getName(), stompClientHandler);
}
});
this.stompChannel = b.connect(host, port).sync().channel();
this.stompClientHandler.connectFuture(this.stompChannel.newPromise());
webSocketHandler.handshakeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
stompClientHandler.beginStomp(stompChannel);
}
});
}
use of io.netty.handler.codec.stomp.StompSubframeAggregator in project netty by netty.
the class StompWebSocketProtocolCodec method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof WebSocketServerProtocolHandler.HandshakeComplete) {
StompVersion stompVersion = StompVersion.findBySubProtocol(((HandshakeComplete) evt).selectedSubprotocol());
ctx.channel().attr(StompVersion.CHANNEL_ATTRIBUTE_KEY).set(stompVersion);
ctx.pipeline().addLast(new WebSocketFrameAggregator(65536)).addLast(new StompSubframeDecoder()).addLast(new StompSubframeAggregator(65536)).addLast(stompChatHandler).remove(StompWebSocketClientPageHandler.INSTANCE);
} else {
super.userEventTriggered(ctx, evt);
}
}
use of io.netty.handler.codec.stomp.StompSubframeAggregator in project netty by netty.
the class StompClient method main.
public static void main(String[] args) throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("decoder", new StompSubframeDecoder());
pipeline.addLast("encoder", new StompSubframeEncoder());
pipeline.addLast("aggregator", new StompSubframeAggregator(1048576));
pipeline.addLast("handler", new StompClientHandler());
}
});
b.connect(HOST, PORT).sync().channel().closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
Aggregations