use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project async-http-client by AsyncHttpClient.
the class NettyWebSocket method sendMessage.
@Override
public WebSocket sendMessage(String message, WebSocketWriteCompleteListener listener) {
final ChannelPromise channelPromise = channel.newPromise();
channelPromise.addListener(listener);
channel.writeAndFlush(new TextWebSocketFrame(message), channelPromise);
return this;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project async-http-client by AsyncHttpClient.
the class NettyWebSocket method sendMessage.
@Override
public WebSocket sendMessage(byte[] message, WebSocketWriteCompleteListener listener) {
final ChannelPromise channelPromise = channel.newPromise();
channelPromise.addListener(listener);
channel.writeAndFlush(new BinaryWebSocketFrame(wrappedBuffer(message)), channelPromise);
return this;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project async-http-client by AsyncHttpClient.
the class NettyWebSocket method stream.
@Override
public WebSocket stream(final byte[] fragment, final int offset, final int len, final boolean last, final WebSocketWriteCompleteListener listener) {
final ChannelPromise channelPromise = channel.newPromise();
channelPromise.addListener(listener);
channel.writeAndFlush(new BinaryWebSocketFrame(last, 0, wrappedBuffer(fragment, offset, len)), channelPromise);
return this;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project netty by netty.
the class IdleStateHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
// Allow writing with void promise if handler is only configured for read timeout events.
if (writerIdleTimeNanos > 0 || allIdleTimeNanos > 0) {
ChannelPromise unvoid = promise.unvoid();
unvoid.addListener(writeListener);
ctx.write(msg, unvoid);
} else {
ctx.write(msg, promise);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project riposte by Nike-Inc.
the class VerifyCornerCasesComponentTest method invalid_http_call_should_result_in_expected_400_error.
@Test
public void invalid_http_call_should_result_in_expected_400_error() throws Exception {
// given
// Normal request, but fiddle with the first chunk as it's going out to remove the HTTP version and make it an
// invalid HTTP call.
NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.GET).withUri(BasicEndpoint.MATCHING_PATH).withPipelineAdjuster(p -> p.addFirst(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
String msgAsString = ((ByteBuf) msg).toString(CharsetUtil.UTF_8);
if (msgAsString.contains("HTTP/1.1")) {
msg = Unpooled.copiedBuffer(msgAsString.replace("HTTP/1.1", ""), CharsetUtil.UTF_8);
}
super.write(ctx, msg, promise);
}
}));
// when
NettyHttpClientResponse response = request.execute(downstreamServerConfig.endpointsPort(), 3000);
// then
verifyErrorReceived(response.payload, response.statusCode, new ApiErrorWithMetadata(SampleCoreApiError.MALFORMED_REQUEST, Pair.of("cause", "Invalid HTTP request")));
}
Aggregations