use of io.netty.handler.codec.http.HttpResponse in project camel by apache.
the class NettyHttpProducerSimpleTest method testHttpSimpleExchange.
@Test
public void testHttpSimpleExchange() throws Exception {
getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
Exchange out = template.request("netty4-http:http://localhost:{{port}}/foo", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
}
});
assertNotNull(out);
assertTrue(out.hasOut());
NettyHttpMessage response = out.getOut(NettyHttpMessage.class);
assertNotNull(response);
assertEquals(200, response.getHttpResponse().status().code());
// we can also get the response as body
HttpResponse body = out.getOut().getBody(HttpResponse.class);
assertNotNull(body);
assertEquals(200, body.status().code());
assertMockEndpointsSatisfied();
}
use of io.netty.handler.codec.http.HttpResponse in project camel by apache.
the class NettyHttpAccessHttpRequestAndResponseBeanTest method myTransformer.
/**
* We can use both a netty http request and response type for transformation
*/
public static HttpResponse myTransformer(FullHttpRequest request) {
String in = request.content().toString(Charset.forName("UTF-8"));
String reply = "Bye " + in;
request.content().release();
HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, NettyConverter.toByteBuffer(reply.getBytes()));
response.headers().set(HttpHeaderNames.CONTENT_LENGTH.toString(), reply.length());
return response;
}
use of io.netty.handler.codec.http.HttpResponse in project apn-proxy by apn-proxy.
the class TestHttpClientHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
// }
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;
TestResultHolder.httpStatusCode(response.getStatus().code());
}
if (msg instanceof LastHttpContent) {
ctx.close();
}
}
use of io.netty.handler.codec.http.HttpResponse in project elasticsearch by elastic.
the class Netty4HttpChannelTests method testThatStringLiteralWorksOnMatch.
public void testThatStringLiteralWorksOnMatch() {
final String originValue = "remote-host";
Settings settings = Settings.builder().put(SETTING_CORS_ENABLED.getKey(), true).put(SETTING_CORS_ALLOW_ORIGIN.getKey(), originValue).put(SETTING_CORS_ALLOW_METHODS.getKey(), "get, options, post").put(SETTING_CORS_ALLOW_CREDENTIALS.getKey(), true).build();
HttpResponse response = executeRequest(settings, originValue, "request-host");
// inspect response and validate
assertThat(response.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN), notNullValue());
String allowedOrigins = response.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN);
assertThat(allowedOrigins, is(originValue));
assertThat(response.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS), equalTo("true"));
}
use of io.netty.handler.codec.http.HttpResponse in project elasticsearch by elastic.
the class Netty4HttpChannelTests method testThatAnyOriginWorks.
public void testThatAnyOriginWorks() {
final String originValue = Netty4CorsHandler.ANY_ORIGIN;
Settings settings = Settings.builder().put(SETTING_CORS_ENABLED.getKey(), true).put(SETTING_CORS_ALLOW_ORIGIN.getKey(), originValue).build();
HttpResponse response = executeRequest(settings, originValue, "request-host");
// inspect response and validate
assertThat(response.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN), notNullValue());
String allowedOrigins = response.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN);
assertThat(allowedOrigins, is(originValue));
assertThat(response.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS), nullValue());
}
Aggregations