use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project camel by apache.
the class NettyHttpConverter method convertToHttpRequest.
/**
* A fallback converter that allows us to easily call Java beans and use the raw Netty {@link HttpRequest} as parameter types.
*/
@FallbackConverter
public static Object convertToHttpRequest(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
// if we want to covert to HttpRequest
if (value != null && HttpRequest.class.isAssignableFrom(type)) {
// okay we may need to cheat a bit when we want to grab the HttpRequest as its stored on the NettyHttpMessage
// so if the message instance is a NettyHttpMessage and its body is the value, then we can grab the
// HttpRequest from the NettyHttpMessage
NettyHttpMessage msg;
if (exchange.hasOut()) {
msg = exchange.getOut(NettyHttpMessage.class);
} else {
msg = exchange.getIn(NettyHttpMessage.class);
}
if (msg != null && msg.getBody() == value) {
// ensure the http request content is reset so we can read all the content out-of-the-box
FullHttpRequest request = msg.getHttpRequest();
request.content().resetReaderIndex();
return request;
}
}
return null;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project camel by apache.
the class NettyHttpEndpoint method createExchange.
@Override
public Exchange createExchange(ChannelHandlerContext ctx, Object message) throws Exception {
Exchange exchange = createExchange();
FullHttpRequest request = (FullHttpRequest) message;
Message in = getNettyHttpBinding().toCamelMessage(request, exchange, getConfiguration());
exchange.setIn(in);
// setup the common message headers
updateMessageHeader(in, ctx);
// honor the character encoding
String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class);
String charset = NettyHttpHelper.getCharsetFromContentType(contentType);
if (charset != null) {
exchange.setProperty(Exchange.CHARSET_NAME, charset);
in.setHeader(Exchange.HTTP_CHARACTER_ENCODING, charset);
}
return exchange;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project rest.li by linkedin.
the class TestRAPClientCodec method testRequestEncoder.
@Test(dataProvider = "restRequest")
public void testRequestEncoder(String uri, RestRequest request) {
final EmbeddedChannel ch = new EmbeddedChannel(new RAPClientCodec());
ch.writeOutbound(request);
FullHttpRequest nettyRequest = (FullHttpRequest) ch.readOutbound();
Assert.assertEquals(nettyRequest.uri(), uri);
Assert.assertEquals(nettyRequest.method(), HttpMethod.valueOf(request.getMethod()));
Assert.assertEquals(nettyRequest.content().toString(CHARSET), request.getEntity().asString(CHARSET));
Assert.assertEquals(nettyRequest.headers().get(HttpHeaderNames.HOST), HOST);
assertList(nettyRequest.headers().getAll(HttpConstants.REQUEST_COOKIE_HEADER_NAME), request.getCookies());
for (String name : request.getHeaders().keySet()) {
Assert.assertEquals(nettyRequest.headers().get(name), request.getHeader(name));
}
ch.finish();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project ratpack by ratpack.
the class WebSocketEngine method connect.
@SuppressWarnings("deprecation")
public static <T> void connect(final Context context, String path, int maxLength, final WebSocketHandler<T> handler) {
PublicAddress publicAddress = context.get(PublicAddress.class);
URI address = publicAddress.get(context);
URI httpPath = address.resolve(path);
URI wsPath;
try {
wsPath = new URI("ws", httpPath.getUserInfo(), httpPath.getHost(), httpPath.getPort(), httpPath.getPath(), httpPath.getQuery(), httpPath.getFragment());
} catch (URISyntaxException e) {
throw uncheck(e);
}
WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(wsPath.toString(), null, false, maxLength);
Request request = context.getRequest();
HttpMethod method = valueOf(request.getMethod().getName());
FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, request.getUri());
nettyRequest.headers().add(SEC_WEBSOCKET_VERSION, request.getHeaders().get(SEC_WEBSOCKET_VERSION));
nettyRequest.headers().add(SEC_WEBSOCKET_KEY, request.getHeaders().get(SEC_WEBSOCKET_KEY));
final WebSocketServerHandshaker handshaker = factory.newHandshaker(nettyRequest);
final DirectChannelAccess directChannelAccess = context.getDirectChannelAccess();
final Channel channel = directChannelAccess.getChannel();
if (!channel.config().isAutoRead()) {
channel.config().setAutoRead(true);
}
handshaker.handshake(channel, nettyRequest).addListener(new HandshakeFutureListener<>(context, handshaker, handler));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project ambry by linkedin.
the class FrontendIntegrationTest method postBlobAndVerify.
/**
* Posts a blob with the given {@code headers} and {@code content}.
* @param headers the headers required.
* @param content the content of the blob.
* @return the blob ID of the blob.
* @throws ExecutionException
* @throws InterruptedException
*/
private String postBlobAndVerify(HttpHeaders headers, ByteBuffer content) throws ExecutionException, InterruptedException {
FullHttpRequest httpRequest = buildRequest(HttpMethod.POST, "/", headers, content);
ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
return verifyPostAndReturnBlobId(responseParts);
}
Aggregations