当前位置: 首页>>代码示例>>Java>>正文


Java HttpMethod.GET属性代码示例

本文整理汇总了Java中io.netty.handler.codec.http.HttpMethod.GET属性的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.GET属性的具体用法?Java HttpMethod.GET怎么用?Java HttpMethod.GET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在io.netty.handler.codec.http.HttpMethod的用法示例。


在下文中一共展示了HttpMethod.GET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldHandlerRequestAndResponse

@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();
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:23,代码来源:Http1BackendHandlerTest.java

示例2: shouldPendingRequests

@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());
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:18,代码来源:Http1BackendHandlerTest.java

示例3: shouldClearPendingRequests

@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());
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:23,代码来源:Http1BackendHandlerTest.java

示例4: method

@Override
public Method method() {
    HttpMethod httpMethod = request.method();
    if (httpMethod == HttpMethod.GET)
        return Method.GET;

    if (httpMethod == HttpMethod.POST)
        return Method.POST;

    if (httpMethod == HttpMethod.PUT)
        return Method.PUT;

    if (httpMethod == HttpMethod.DELETE)
        return Method.DELETE;

    if (httpMethod == HttpMethod.HEAD) {
        return Method.HEAD;
    }

    if (httpMethod == HttpMethod.OPTIONS) {
        return Method.OPTIONS;
    }

    return Method.GET;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:Netty4HttpRequest.java

示例5: testReleaseOnSendToClosedChannel

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
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:Netty4HttpChannelTests.java

示例6: executeRequest

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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:Netty4HttpChannelTests.java

示例7: sendRequest

private void sendRequest(HttpUrl url) {
  start = System.nanoTime();
  total = 0;
  HttpRequest request = new DefaultFullHttpRequest(
      HttpVersion.HTTP_1_1, HttpMethod.GET, url.encodedPath());
  request.headers().set(HttpHeaders.Names.HOST, url.host());
  request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
  channel.writeAndFlush(request);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:NettyHttpClient.java

示例8: shouldHandleRequestsAndResponses

@Test
public void shouldHandleRequestsAndResponses() {
    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);

    // First response
    DefaultFullHttpResponse resp = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    assertFalse(inboundChannel.writeInbound(resp));

    assertEquals(1, outboundChannel.outboundMessages().size());
    assertEquals(resp, outboundChannel.outboundMessages().poll());

    // Second request
    inboundChannel.write(req);

    assertEquals(1, inboundChannel.outboundMessages().size());
    assertTrue(inboundChannel.outboundMessages().poll() instanceof ByteBuf);

    // Second response
    assertFalse(inboundChannel.writeInbound(resp));

    assertEquals(1, outboundChannel.outboundMessages().size());
    assertEquals(resp, outboundChannel.outboundMessages().poll());

    resp.release();
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:35,代码来源:Http1BackendHandlerTest.java

示例9: testThatPipeliningWorksWithChunkedRequests

public void testThatPipeliningWorksWithChunkedRequests() throws InterruptedException {
    final int numberOfRequests = randomIntBetween(2, 128);
    final EmbeddedChannel embeddedChannel =
        new EmbeddedChannel(
            new AggregateUrisAndHeadersHandler(),
            new HttpPipeliningHandler(numberOfRequests),
            new WorkEmulatorHandler());

    for (int i = 0; i < numberOfRequests; i++) {
        final DefaultHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/" + i);
        embeddedChannel.writeInbound(request);
        embeddedChannel.writeInbound(LastHttpContent.EMPTY_LAST_CONTENT);
    }

    final List<CountDownLatch> latches = new ArrayList<>();
    for (int i = numberOfRequests - 1; i >= 0; i--) {
        latches.add(finishRequest(Integer.toString(i)));
    }

    for (final CountDownLatch latch : latches) {
        latch.await();
    }

    embeddedChannel.flush();

    for (int i = 0; i < numberOfRequests; i++) {
        assertReadHttpMessageHasContent(embeddedChannel, Integer.toString(i));
    }

    assertTrue(embeddedChannel.isOpen());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:Netty4HttpPipeliningHandlerTests.java

示例10: testHeadersSet

public void testHeadersSet() {
    Settings settings = Settings.builder().build();
    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, "/");
        httpRequest.headers().add(HttpHeaderNames.ORIGIN, "remote");
        final WriteCapturingChannel writeCapturingChannel = new WriteCapturingChannel();
        Netty4HttpRequest request = new Netty4HttpRequest(xContentRegistry(), httpRequest, writeCapturingChannel);

        // send a response
        Netty4HttpChannel channel =
                new Netty4HttpChannel(httpServerTransport, request, null, randomBoolean(), threadPool.getThreadContext());
        TestResponse resp = new TestResponse();
        final String customHeader = "custom-header";
        final String customHeaderValue = "xyz";
        resp.addHeader(customHeader, customHeaderValue);
        channel.sendResponse(resp);

        // inspect what was written
        List<Object> writtenObjects = writeCapturingChannel.getWrittenObjects();
        assertThat(writtenObjects.size(), is(1));
        HttpResponse response = (HttpResponse) writtenObjects.get(0);
        assertThat(response.headers().get("non-existent-header"), nullValue());
        assertThat(response.headers().get(customHeader), equalTo(customHeaderValue));
        assertThat(response.headers().get(HttpHeaderNames.CONTENT_LENGTH), equalTo(Integer.toString(resp.content().length())));
        assertThat(response.headers().get(HttpHeaderNames.CONTENT_TYPE), equalTo(resp.contentType()));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:Netty4HttpChannelTests.java

示例11: get

public Collection<FullHttpResponse> get(SocketAddress remoteAddress, String... uris) throws InterruptedException {
    Collection<HttpRequest> requests = new ArrayList<>(uris.length);
    for (int i = 0; i < uris.length; i++) {
        final HttpRequest httpRequest = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, uris[i]);
        httpRequest.headers().add(HOST, "localhost");
        httpRequest.headers().add("X-Opaque-ID", String.valueOf(i));
        requests.add(httpRequest);
    }
    return sendRequests(remoteAddress, requests);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:Netty4HttpClient.java

示例12: main

public static void main(String[] args) {
		NettyHttpClient client=new NettyHttpClient();
		long time=System.currentTimeMillis();
		HttpRequest request=new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/baidu?tn=monline_6_dg&ie=utf-8&wd=netty+http客户端");
		HttpResponse response=client.syncRequest("www.baidu.com", 80, request);
		System.out.println(System.currentTimeMillis()-time);
		System.out.println(response);
		FullHttpResponse rsp=(FullHttpResponse) response;
		System.out.println("content:"+rsp.content().toString(CharsetUtil.UTF_8));
//		new Scanner(System.in).nextLine();
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:11,代码来源:NettyHttpClient.java

示例13: createHttpCarbonMessage

public HTTPCarbonMessage createHttpCarbonMessage(String method) {
    HTTPCarbonMessage httpCarbonMessage = null;
    switch (method) {
        case "GET": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""));
            break;
        }
        case "PUT": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, ""));
            break;
        }
        case "PATCH": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, ""));
            break;
        }
        case "DELETE": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, ""));
            break;
        }
        case "POST": {
            httpCarbonMessage = new HTTPCarbonMessage(
                    new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, ""));
            break;
        }
        default: {
            log.error("Invalid request type.");

            break;
        }
    }
    return httpCarbonMessage;
}
 
开发者ID:wso2-extensions,项目名称:siddhi-io-http,代码行数:36,代码来源:HttpSink.java

示例14: createHttpCarbonMessage

/**
 * Create new HTTP carbon messge.
 *
 * @param isRequest
 * @return
 */
private static HTTPCarbonMessage createHttpCarbonMessage(boolean isRequest) {
    HTTPCarbonMessage httpCarbonMessage;
    if (isRequest) {
        httpCarbonMessage = new HTTPCarbonMessage(
                new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""));
        httpCarbonMessage.setEndOfMsgAdded(true);
    } else {
        httpCarbonMessage = new HTTPCarbonMessage(
                new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
        httpCarbonMessage.setEndOfMsgAdded(true);
    }
    return httpCarbonMessage;
}
 
开发者ID:wso2-extensions,项目名称:siddhi-io-http,代码行数:19,代码来源:HttpIoUtil.java

示例15: testVersionGet

/**
 * Only /login requests are handled
 */
@Test(expected = QonduitException.class)
public void testVersionGet() throws Exception {
    decoder = new TestHttpQueryDecoder(config);
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/version");
    addCookie(request);
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals("VersionRequest", results.iterator().next().getClass().getSimpleName());
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:12,代码来源:HttpRequestDecoderTest.java


注:本文中的io.netty.handler.codec.http.HttpMethod.GET属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。