當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。