Example usage for io.netty.handler.codec.http HttpMethod GET

List of usage examples for io.netty.handler.codec.http HttpMethod GET

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod GET.

Prototype

HttpMethod GET

To view the source code for io.netty.handler.codec.http HttpMethod GET.

Click Source Link

Document

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

Usage

From source file:com.github.smallcreep.bmp.client.tests.TestProxyBMPClient.java

License:Apache License

@Test
public void testOverridesResponseAsResponseFilterAndType() throws Throwable {
    Headers headersExpected = new Headers();
    List<String> accessControlAllowCredentialsList = new ArrayList<>();
    accessControlAllowCredentialsList.add("test");
    accessControlAllowCredentialsList.add("test2");
    headersExpected.put(ACCESS_CONTROL_ALLOW_CREDENTIALS, accessControlAllowCredentialsList);
    List<String> accessControlMaxAgeList = new ArrayList<>();
    accessControlMaxAgeList.add("test3");
    headersExpected.put(ACCESS_CONTROL_MAX_AGE, accessControlMaxAgeList);
    io.netty.handler.codec.http.HttpResponse responseOverrides = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.FORBIDDEN);
    for (String headers : headersExpected.keySet()) {
        for (String headersValue : headersExpected.get(headers)) {
            responseOverrides.headers().add(headers, headersValue);
        }/*from w ww.j a  v  a 2 s  . co  m*/
    }
    HttpMessageContents contents = new HttpMessageContents(
            new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FORBIDDEN));
    contents.setTextContents("<html><body>Response successfully intercepted</body></html>");
    List<FilterUrls> filterUrls = new ArrayList<>();
    DefaultHttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add(HttpHeaders.Names.CONTENT_TYPE, "text/css");
    filterUrls.add(new FilterUrls("^http:\\/\\/search\\.maven\\.org\\/(.*)$", HttpMethod.GET, httpHeaders));

    BMPResponseFilter bmpResponseFilter = new BMPResponseFilter(responseOverrides, contents, null, filterUrls);
    getBmpLittleProxy().setFilterResponse(bmpResponseFilter);
    Unirest.setProxy(new HttpHost(getBmpLittleProxy().getAddress(), getBmpLittleProxy().getPort()));

    HttpResponse<String> response = Unirest.get("http://search.maven.org/ajaxsolr/css/central.css").asString();
    assertOverrideResponseEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);

    response = Unirest.get("http://search.maven.org/test.html").asString();
    assertOverrideResponseNotEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);

    response = Unirest.get("http://search.maven.org/").asString();
    assertOverrideResponseNotEquals(accessControlAllowCredentialsList, accessControlMaxAgeList, response);
}

From source file:com.github.smallcreep.bmp.client.tests.TestProxyBMPClient.java

License:Apache License

@Test
public void testSetDelaysResponseFilter() throws Throwable {
    HttpMessageContents contents = null;
    io.netty.handler.codec.http.HttpResponse responseOverrides = null;
    List<FilterUrls> filterUrls = new ArrayList<>();
    filterUrls.add(new FilterUrls("^http:\\/\\/search\\.maven\\.org\\/$", HttpMethod.GET));
    BMPResponseFilter bmpResponseFilter = new BMPResponseFilter(responseOverrides, contents, null, filterUrls,
            Long.valueOf(20000));
    getBmpLittleProxy().setFilterResponse(bmpResponseFilter);
    Unirest.setProxy(new HttpHost(getBmpLittleProxy().getAddress(), getBmpLittleProxy().getPort()));

    Date dateStart = new Date();
    Unirest.get(URL_PROTOCOL + URL_FOR_TEST).asString();
    Date dateFinish = new Date();
    assertTrue(dateFinish.getTime() - dateStart.getTime() > 20000);
    dateStart = new Date();
    Unirest.post(URL_PROTOCOL + URL_FOR_TEST).asString();
    dateFinish = new Date();
    assertTrue(dateFinish.getTime() - dateStart.getTime() < 20000);
}

From source file:com.github.thinker0.mesos.MesosHealthCheckerServer.java

License:Apache License

/**
 * Adds a GET route./*from   w  ww. j av  a  2  s.  c  o  m*/
 *
 * @param path    The URL path.
 * @param handler The request handler.
 * @return This WebServer.
 */
public MesosHealthCheckerServer get(final String path, final Handler handler) {
    this.routeTable.addRoute(new Route(HttpMethod.GET, path, handler));
    return this;
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpDownloadHandler.java

License:Open Source License

private HttpRequest buildRequest(DownloadCommand request) {
    HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            constructPath(request.uri(), request.hash(), request.casDownload()));
    httpRequest.headers().set(HttpHeaderNames.HOST, constructHost(request.uri()));
    httpRequest.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    httpRequest.headers().set(HttpHeaderNames.ACCEPT, "*/*");
    return httpRequest;
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpDownloadHandlerTest.java

License:Open Source License

private void downloadShouldWork(boolean casDownload, EmbeddedChannel ch) throws IOException {
    ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream());
    DownloadCommand cmd = new DownloadCommand(CACHE_URI, casDownload, "abcdef", out);
    ChannelPromise writePromise = ch.newPromise();
    ch.writeOneOutbound(cmd, writePromise);

    HttpRequest request = ch.readOutbound();
    assertThat(request.method()).isEqualTo(HttpMethod.GET);
    assertThat(request.headers().get(HttpHeaderNames.HOST))
            .isEqualTo(CACHE_URI.getHost() + ":" + CACHE_URI.getPort());
    if (casDownload) {
        assertThat(request.uri()).isEqualTo("/cache-bucket/cas/abcdef");
    } else {/*  w  ww.  j  ava2  s .c o  m*/
        assertThat(request.uri()).isEqualTo("/cache-bucket/ac/abcdef");
    }

    assertThat(writePromise.isDone()).isFalse();

    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.headers().set(HttpHeaders.CONTENT_LENGTH, 5);
    response.headers().set(HttpHeaders.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    ch.writeInbound(response);
    ByteBuf content = Unpooled.buffer();
    content.writeBytes(new byte[] { 1, 2, 3, 4, 5 });
    ch.writeInbound(new DefaultLastHttpContent(content));

    assertThat(writePromise.isDone()).isTrue();
    assertThat(out.toByteArray()).isEqualTo(new byte[] { 1, 2, 3, 4, 5 });
    verify(out, never()).close();
    assertThat(ch.isActive()).isTrue();
}

From source file:com.google.devtools.build.remote.worker.HttpCacheServerHandler.java

License:Open Source License

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) {
    if (!request.decoderResult().isSuccess()) {
        sendError(ctx, request, HttpResponseStatus.BAD_REQUEST);
        return;//from   w  w w. j  av a  2s  .c o m
    }

    if (request.method() == HttpMethod.GET) {
        handleGet(ctx, request);
    } else if (request.method() == HttpMethod.PUT) {
        handlePut(ctx, request);
    } else {
        sendError(ctx, request, HttpResponseStatus.METHOD_NOT_ALLOWED);
    }
}

From source file:com.jetbrains.edu.learning.stepik.builtInServer.StepikRestService.java

License:Apache License

@Override
protected boolean isMethodSupported(@NotNull HttpMethod method) {
    return method == HttpMethod.GET;
}

From source file:com.jetbrains.edu.learning.stepik.builtInServer.StepikRestService.java

License:Apache License

@Override
protected boolean isHostTrusted(@NotNull FullHttpRequest request)
        throws InterruptedException, InvocationTargetException {
    String uri = request.uri();//from  ww w .j a v  a  2 s. c  o  m
    Matcher codeMatcher = OAUTH_CODE_PATTERN.matcher(uri);
    if (request.method() == HttpMethod.GET && codeMatcher.matches()) {
        return true;
    }
    return super.isHostTrusted(request);
}

From source file:com.king.platform.net.http.netty.NettyHttpClient.java

License:Apache License

@Override
public HttpClientRequest createGet(String uri) {
    if (!started.get()) {
        throw new IllegalStateException("Http client is not started!");
    }/*from   www. ja  v a2s.c  om*/

    return new HttpClientRequestBuilder(this, HttpVersion.HTTP_1_1, HttpMethod.GET, uri, confMap);
}

From source file:com.king.platform.net.http.netty.requestbuilder.HttpClientSseRequestBuilderImpl.java

License:Apache License

public HttpClientSseRequestBuilderImpl(HttpClientCaller httpClientCaller, String uri, ConfMap confMap,
        Executor callbackExecutor) {
    super(HttpClientSseRequestBuilder.class, httpClientCaller, HttpVersion.HTTP_1_1, HttpMethod.GET, uri,
            confMap, callbackExecutor);//from   w  w w  . j a  v  a 2 s . c  o m
}