use of io.netty.handler.codec.string.StringEncoder in project camel by apache.
the class NettySingleCodecTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
StringEncoder stringEncoder = new StringEncoder();
StringDecoder stringDecoder = new StringDecoder();
registry.bind("encoder", stringEncoder);
registry.bind("decoder", stringDecoder);
return registry;
}
use of io.netty.handler.codec.string.StringEncoder in project flink by apache.
the class NettyClientServerSslTest method testValidSslConnection.
/**
* Verify valid ssl configuration and connection
*
*/
@Test
public void testValidSslConnection() throws Exception {
NettyProtocol protocol = new NettyProtocol() {
@Override
public ChannelHandler[] getServerChannelHandlers() {
return new ChannelHandler[0];
}
@Override
public ChannelHandler[] getClientChannelHandlers() {
return new ChannelHandler[0];
}
};
NettyConfig nettyConfig = new NettyConfig(InetAddress.getLoopbackAddress(), NetUtils.getAvailablePort(), NettyTestUtil.DEFAULT_SEGMENT_SIZE, 1, createSslConfig());
NettyTestUtil.NettyServerAndClient serverAndClient = NettyTestUtil.initServerAndClient(protocol, nettyConfig);
Channel ch = NettyTestUtil.connect(serverAndClient);
// should be able to send text data
ch.pipeline().addLast(new StringDecoder()).addLast(new StringEncoder());
assertTrue(ch.writeAndFlush("test").await().isSuccess());
NettyTestUtil.shutdown(serverAndClient);
}
use of io.netty.handler.codec.string.StringEncoder in project flink by apache.
the class NettyClientServerSslTest method testSslHandshakeError.
/**
* Verify SSL handshake error when untrusted server certificate is used
*
*/
@Test
public void testSslHandshakeError() throws Exception {
NettyProtocol protocol = new NettyProtocol() {
@Override
public ChannelHandler[] getServerChannelHandlers() {
return new ChannelHandler[0];
}
@Override
public ChannelHandler[] getClientChannelHandlers() {
return new ChannelHandler[0];
}
};
Configuration config = createSslConfig();
// Use a server certificate which is not present in the truststore
config.setString(ConfigConstants.SECURITY_SSL_KEYSTORE, "src/test/resources/untrusted.keystore");
NettyConfig nettyConfig = new NettyConfig(InetAddress.getLoopbackAddress(), NetUtils.getAvailablePort(), NettyTestUtil.DEFAULT_SEGMENT_SIZE, 1, config);
NettyTestUtil.NettyServerAndClient serverAndClient = NettyTestUtil.initServerAndClient(protocol, nettyConfig);
Channel ch = NettyTestUtil.connect(serverAndClient);
ch.pipeline().addLast(new StringDecoder()).addLast(new StringEncoder());
// Attempting to write data over ssl should fail
assertFalse(ch.writeAndFlush("test").await().isSuccess());
NettyTestUtil.shutdown(serverAndClient);
}
use of io.netty.handler.codec.string.StringEncoder in project jackrabbit-oak by apache.
the class StandbyClient method connect.
void connect(String host, int port) throws Exception {
final SslContext sslContext;
if (secure) {
sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
} else {
sslContext = null;
}
Bootstrap b = new Bootstrap().group(group).channel(NioSocketChannel.class).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, readTimeoutMs).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_KEEPALIVE, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslContext != null) {
p.addLast(sslContext.newHandler(ch.alloc()));
}
p.addLast(new ReadTimeoutHandler(readTimeoutMs, TimeUnit.MILLISECONDS));
// Decoders
p.addLast(new SnappyFramedDecoder(true));
// Such a big max frame length is needed because blob
// values are sent in one big message. In future
// versions of the protocol, sending binaries in chunks
// should be considered instead.
p.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
p.addLast(new ResponseDecoder());
// Encoders
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
p.addLast(new GetHeadRequestEncoder());
p.addLast(new GetSegmentRequestEncoder());
p.addLast(new GetBlobRequestEncoder());
p.addLast(new GetReferencesRequestEncoder());
// Handlers
p.addLast(new GetHeadResponseHandler(headQueue));
p.addLast(new GetSegmentResponseHandler(segmentQueue));
p.addLast(new GetBlobResponseHandler(blobQueue));
p.addLast(new GetReferencesResponseHandler(referencesQueue));
// Exception handler
p.addLast(new ExceptionHandler(clientId));
}
});
channel = b.connect(host, port).sync().channel();
}
Aggregations