本文整理汇总了Java中io.netty.handler.codec.http.DefaultFullHttpRequest类的典型用法代码示例。如果您正苦于以下问题:Java DefaultFullHttpRequest类的具体用法?Java DefaultFullHttpRequest怎么用?Java DefaultFullHttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultFullHttpRequest类属于io.netty.handler.codec.http包,在下文中一共展示了DefaultFullHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldHandlerRequestAndResponse
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void shouldHandlerRequestAndResponse() {
inboundChannel.pipeline().addLast(handler);
DefaultFullHttpRequest req = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
inboundChannel.write(req);
assertEquals(1, inboundChannel.outboundMessages().size());
Object outboundReq = inboundChannel.outboundMessages().poll();
assertTrue(outboundReq instanceof ByteBuf);
assertEquals("GET / HTTP/1.1\r\n\r\n", new String(readBytes((ByteBuf) outboundReq)));
DefaultFullHttpResponse resp = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
assertFalse(inboundChannel.writeInbound(resp));
assertEquals(1, outboundChannel.outboundMessages().size());
assertEquals(resp, outboundChannel.outboundMessages().poll());
resp.release();
}
示例2: shouldPendingRequests
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void shouldPendingRequests() {
inboundChannel.pipeline().addLast(handler);
DefaultFullHttpRequest req = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
// First request
inboundChannel.write(req.retain());
assertEquals(1, inboundChannel.outboundMessages().size());
assertTrue(inboundChannel.outboundMessages().poll() instanceof ByteBuf);
// Second request
inboundChannel.write(req);
// Should pending second request
assertTrue(inboundChannel.outboundMessages().isEmpty());
}
示例3: shouldClearPendingRequests
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void shouldClearPendingRequests() {
inboundChannel.pipeline().addLast(handler);
DefaultFullHttpRequest req = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
// First request
inboundChannel.write(req.retain());
assertEquals(1, req.refCnt());
assertEquals(1, inboundChannel.outboundMessages().size());
assertTrue(inboundChannel.outboundMessages().poll() instanceof ByteBuf);
// Second request
inboundChannel.write(req);
assertEquals(1, req.refCnt());
assertTrue(inboundChannel.outboundMessages().isEmpty());
inboundChannel.close();
assertEquals(0, req.refCnt());
}
示例4: testReleaseOnSendToClosedChannel
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
public void testReleaseOnSendToClosedChannel() {
final Settings settings = Settings.builder().build();
final NamedXContentRegistry registry = xContentRegistry();
try (Netty4HttpServerTransport httpServerTransport =
new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, registry, new NullDispatcher())) {
final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
final Netty4HttpRequest request = new Netty4HttpRequest(registry, httpRequest, embeddedChannel);
final HttpPipelinedRequest pipelinedRequest = randomBoolean() ? new HttpPipelinedRequest(request.request(), 1) : null;
final Netty4HttpChannel channel =
new Netty4HttpChannel(httpServerTransport, request, pipelinedRequest, randomBoolean(), threadPool.getThreadContext());
final TestResponse response = new TestResponse(bigArrays);
assertThat(response.content(), instanceOf(Releasable.class));
embeddedChannel.close();
channel.sendResponse(response);
// ESTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
}
}
示例5: executeRequest
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
private FullHttpResponse executeRequest(final Settings settings, final String originValue, final String host) {
// construct request and send it over the transport layer
try (Netty4HttpServerTransport httpServerTransport =
new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(),
new NullDispatcher())) {
httpServerTransport.start();
final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
if (originValue != null) {
httpRequest.headers().add(HttpHeaderNames.ORIGIN, originValue);
}
httpRequest.headers().add(HttpHeaderNames.HOST, host);
final WriteCapturingChannel writeCapturingChannel = new WriteCapturingChannel();
final Netty4HttpRequest request = new Netty4HttpRequest(xContentRegistry(), httpRequest, writeCapturingChannel);
Netty4HttpChannel channel =
new Netty4HttpChannel(httpServerTransport, request, null, randomBoolean(), threadPool.getThreadContext());
channel.sendResponse(new TestResponse());
// get the response
List<Object> writtenObjects = writeCapturingChannel.getWrittenObjects();
assertThat(writtenObjects.size(), is(1));
return (FullHttpResponse) writtenObjects.get(0);
}
}
示例6: testBasicAuthenticationFailure
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testBasicAuthenticationFailure() throws Exception {
Configuration config = TestConfiguration.createMinimalConfigurationForTest();
BasicAuthLogin auth = new BasicAuthLogin();
auth.setUsername("test");
auth.setPassword("test2");
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/login");
request.content().writeBytes(JsonSerializer.getObjectMapper().writeValueAsBytes(auth));
TestHttpQueryDecoder decoder = new TestHttpQueryDecoder(config);
decoder.decode(null, request, results);
Assert.assertEquals(1, results.size());
Object result = results.iterator().next();
Assert.assertEquals(BasicAuthLoginRequest.class, result.getClass());
BasicAuthLoginRequestHandler handler = new BasicAuthLoginRequestHandler(config);
CaptureChannelHandlerContext ctx = new CaptureChannelHandlerContext();
handler.channelRead(ctx, result);
Assert.assertNotNull(ctx.msg);
Assert.assertTrue(ctx.msg instanceof DefaultFullHttpResponse);
DefaultFullHttpResponse response = (DefaultFullHttpResponse) ctx.msg;
Assert.assertEquals(HttpResponseStatus.UNAUTHORIZED, response.getStatus());
Assert.assertTrue(response.headers().contains(Names.CONTENT_TYPE));
Assert.assertEquals(Constants.JSON_TYPE, response.headers().get(Names.CONTENT_TYPE));
}
示例7: testIsProxyRequest
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testIsProxyRequest() throws IOException{
AppConfiguration appConfig = new AppConfiguration(new ConfigLoader(),
null);
appConfig.init();
PolicyManager policyManager = mock(PolicyManager.class);
NettyRequestProxyFilter filter = new NettyRequestProxyFilter(
policyManager, appConfig);
DefaultFullHttpRequest req = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "/version");
assertTrue(filter.isProxyRequest(req));
assertRequest(filter, req, false, "localhost:32876");
assertRequest(filter, req, false, "127.0.0.1:32876");
assertRequest(filter, req, true, "localhost:32877");
assertRequest(filter, req, true, "localhost");
assertRequest(filter, req, true, "127.0.0.1");
assertRequest(filter, req, true, "trace.vip.ebay.com");
assertRequest(filter, req, true, "");
}
示例8: test
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void test() throws InterruptedException, ExecutionException {
int streamId = 3;
FullHttpRequest request =
new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
request.headers().add(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(),
streamId);
Promise<FullHttpResponse> promise = CHANNEL.eventLoop().newPromise();
synchronized (RESPONSE_HANDLER) {
CHANNEL.writeAndFlush(request);
RESPONSE_HANDLER.put(streamId, promise);
}
assertEquals(HttpResponseStatus.OK, promise.get().status());
ByteBuf content = promise.get().content();
assertEquals("HTTP/2 DTP", content.toString(StandardCharsets.UTF_8));
}
示例9: createFullHttpRequest
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) {
io.netty.handler.codec.http.HttpMethod nettyMethod =
io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name());
FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
nettyMethod, this.uri.toString(), this.body.buffer());
nettyRequest.headers().set(HttpHeaders.HOST, uri.getHost());
nettyRequest.headers().set(HttpHeaders.CONNECTION, io.netty.handler.codec.http.HttpHeaders.Values.CLOSE);
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
nettyRequest.headers().add(entry.getKey(), entry.getValue());
}
return nettyRequest;
}
示例10: testLookupPostWithNoLimit
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testLookupPostWithNoLimit() throws Exception {
// @formatter:off
String content =
"{\n" +
" \"metric\": \"sys.cpu.user\"\n" +
"}";
// @formatter:on
decoder = new TestHttpQueryDecoder(config);
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
"/api/search/lookup");
request.content().writeBytes(content.getBytes());
addCookie(request);
decoder.decode(null, request, results);
Assert.assertEquals(1, results.size());
Assert.assertEquals(SearchLookupRequest.class, results.iterator().next().getClass());
SearchLookupRequest lookup = (SearchLookupRequest) results.iterator().next();
Assert.assertEquals("sys.cpu.user", lookup.getQuery());
Assert.assertEquals(25, lookup.getLimit());
Assert.assertEquals(0, lookup.getTags().size());
}
示例11: testLookupPostWithLimit
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testLookupPostWithLimit() throws Exception {
// @formatter:off
String content =
"{\n" +
" \"metric\": \"sys.cpu.user\",\n" +
" \"limit\": 3000\n" +
"}";
// @formatter:on
decoder = new TestHttpQueryDecoder(config);
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
"/api/search/lookup");
request.content().writeBytes(content.getBytes());
addCookie(request);
decoder.decode(null, request, results);
Assert.assertEquals(1, results.size());
Assert.assertEquals(SearchLookupRequest.class, results.iterator().next().getClass());
SearchLookupRequest lookup = (SearchLookupRequest) results.iterator().next();
Assert.assertEquals("sys.cpu.user", lookup.getQuery());
Assert.assertEquals(3000, lookup.getLimit());
Assert.assertEquals(0, lookup.getTags().size());
}
示例12: testLookupURIWithLimitAndTags
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testLookupURIWithLimitAndTags() throws Exception {
decoder = new TestHttpQueryDecoder(config);
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
"/api/search/lookup?m=sys.cpu.user{host=*}&limit=3000");
addCookie(request);
decoder.decode(null, request, results);
Assert.assertEquals(1, results.size());
Assert.assertEquals(SearchLookupRequest.class, results.iterator().next().getClass());
SearchLookupRequest lookup = (SearchLookupRequest) results.iterator().next();
Assert.assertEquals("sys.cpu.user", lookup.getQuery());
Assert.assertEquals(3000, lookup.getLimit());
Assert.assertEquals(1, lookup.getTags().size());
Tag tag = lookup.getTags().iterator().next();
Assert.assertEquals("host", tag.getKey());
Assert.assertEquals("*", tag.getValue());
}
示例13: testSuggestPostWithValidType
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testSuggestPostWithValidType() throws Exception {
// @formatter:off
String content =
"{\n" +
" \"type\": \"metrics\"\n" +
"}";
// @formatter:on
decoder = new TestHttpQueryDecoder(config);
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
"/api/suggest");
request.content().writeBytes(content.getBytes());
addCookie(request);
decoder.decode(null, request, results);
Assert.assertEquals(1, results.size());
Assert.assertEquals(SuggestRequest.class, results.iterator().next().getClass());
SuggestRequest suggest = (SuggestRequest) results.iterator().next();
Assert.assertEquals("metrics", suggest.getType());
Assert.assertFalse(suggest.getQuery().isPresent());
Assert.assertEquals(25, suggest.getMax());
suggest.validate();
}
示例14: testSuggestPostWithValidTypeAndQuery
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testSuggestPostWithValidTypeAndQuery() throws Exception {
// @formatter:off
String content =
"{\n" +
" \"type\": \"metrics\",\n" +
" \"q\": \"sys.cpu.user\"\n" +
"}";
// @formatter:on
decoder = new TestHttpQueryDecoder(config);
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
"/api/suggest");
request.content().writeBytes(content.getBytes());
addCookie(request);
decoder.decode(null, request, results);
Assert.assertEquals(1, results.size());
Assert.assertEquals(SuggestRequest.class, results.iterator().next().getClass());
SuggestRequest suggest = (SuggestRequest) results.iterator().next();
Assert.assertEquals("metrics", suggest.getType());
Assert.assertEquals("sys.cpu.user", suggest.getQuery().get());
Assert.assertEquals(25, suggest.getMax());
suggest.validate();
}
示例15: testSuggestPostWithValidTypeAndQueryAndMax
import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入依赖的package包/类
@Test
public void testSuggestPostWithValidTypeAndQueryAndMax() throws Exception {
// @formatter:off
String content =
"{\n" +
" \"type\": \"metrics\",\n" +
" \"q\": \"sys.cpu.user\",\n" +
" \"max\": 30\n" +
"}";
// @formatter:on
decoder = new TestHttpQueryDecoder(config);
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
"/api/suggest");
request.content().writeBytes(content.getBytes());
addCookie(request);
decoder.decode(null, request, results);
Assert.assertEquals(1, results.size());
Assert.assertEquals(SuggestRequest.class, results.iterator().next().getClass());
SuggestRequest suggest = (SuggestRequest) results.iterator().next();
Assert.assertEquals("metrics", suggest.getType());
Assert.assertEquals("sys.cpu.user", suggest.getQuery().get());
Assert.assertEquals(30, suggest.getMax());
suggest.validate();
}