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


Java HttpMethod类代码示例

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


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

示例1: main

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
public static void main(String[] args) {
    int loopTimes = 200;

    class Runner implements Runnable{

        private Logger logger = LoggerFactory.getLogger(Runner.class);

        @Override
        public void run() {
            RouteResult<RenderType> result = RouterContext.getRouteResult(HttpMethod.GET,"/user/info");
            logger.info("routeResult={},currentThread={}",result,Thread.currentThread().getName());
        }
    }

    for(int i=0;i<loopTimes;i++){
        new Thread(new Runner()).start();
    }

}
 
开发者ID:all4you,项目名称:redant,代码行数:20,代码来源:RouterContext.java

示例2: allowedMethods

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
/**
 * Returns allowed methods for a specific URI.
 * <p>
 * For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
 */
public Set<HttpMethod> allowedMethods(String uri) {
    QueryStringDecoder decoder = new QueryStringDecoder(uri);
    String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");

    if (anyMethodRouter.anyMatched(tokens)) {
        return allAllowedMethods();
    }

    Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
    for (Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
        MethodlessRouter<T> router = entry.getValue();
        if (router.anyMatched(tokens)) {
            HttpMethod method = entry.getKey();
            ret.add(method);
        }
    }

    return ret;
}
 
开发者ID:all4you,项目名称:redant,代码行数:25,代码来源:Router.java

示例3: uri

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
/**
 * Given a target and params, this method tries to do the reverse routing
 * and returns the URI.
 *
 * <p>Placeholders in the path pattern will be filled with the params.
 * The params can be a map of {@code placeholder name -> value}
 * or ordered values.
 *
 * <p>If a param doesn't have a corresponding placeholder, it will be put
 * to the query part of the result URI.
 *
 * @return {@code null} if there's no match
 */
public String uri(HttpMethod method, T target, Object... params) {
    MethodlessRouter<T> router = (method == null) ? anyMethodRouter : routers.get(method);

    // Fallback to anyMethodRouter if no router is found for the method
    if (router == null) {
        router = anyMethodRouter;
    }

    String ret = router.uri(target, params);
    if (ret != null) {
        return ret;
    }

    // Fallback to anyMethodRouter if the router was not anyMethodRouter and no path is found
    return (router != anyMethodRouter) ? anyMethodRouter.uri(target, params) : null;
}
 
开发者ID:all4you,项目名称:redant,代码行数:30,代码来源:Router.java

示例4: doQuery

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
public Observable<DocumentServiceResponse> doQuery(RxDocumentServiceRequest request) {
    request.getHeaders().put(HttpConstants.HttpHeaders.IS_QUERY, "true");

    switch (this.queryCompatibilityMode) {
    case SqlQuery:
        request.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE,
                RuntimeConstants.MediaTypes.SQL);
        break;
    case Default:
    case Query:
    default:
        request.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE,
                RuntimeConstants.MediaTypes.QUERY_JSON);
        break;
    }
    return this.performRequest(request, HttpMethod.POST);
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:18,代码来源:RxGatewayStoreModel.java

示例5: makeHandler

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
@Override
public RequestHandler makeHandler(HttpServerRequest<ByteBuf> request) {
    HttpMethod method = request.getHttpMethod();
    TusRequest tusRequest = new RxNettyTusRequestAdapter(request);
    if (method.equals(HttpMethod.OPTIONS)) {
        return new OptionHandler(options, tusRequest);
    }
    if (method.equals(HttpMethod.POST)) {
        return new PostHandler(options, tusRequest, pool);
    }
    if (method.equals(HttpMethod.HEAD)) {
        return new HeadHandler(options, tusRequest, pool);
    }
    if (method.equals(HttpMethod.PATCH)) {
        return new PatchHandler(options, tusRequest, pool);
    }
    return new NotImplementedHandler();
}
 
开发者ID:jerbome,项目名称:tusRx,代码行数:19,代码来源:RxNettyRequestHandlerFactory.java

示例6: shouldHandlerRequestAndResponse

import io.netty.handler.codec.http.HttpMethod; //导入依赖的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();
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:24,代码来源:Http1BackendHandlerTest.java

示例7: shouldPendingRequests

import io.netty.handler.codec.http.HttpMethod; //导入依赖的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());
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:19,代码来源:Http1BackendHandlerTest.java

示例8: handle

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
public void handle(ChannelHandlerContext ctx, HttpRequest req)
  throws IOException, URISyntaxException {
  String op = params.op();
  HttpMethod method = req.getMethod();
  if (PutOpParam.Op.CREATE.name().equalsIgnoreCase(op)
    && method == PUT) {
    onCreate(ctx);
  } else if (PostOpParam.Op.APPEND.name().equalsIgnoreCase(op)
    && method == POST) {
    onAppend(ctx);
  } else if (GetOpParam.Op.OPEN.name().equalsIgnoreCase(op)
    && method == GET) {
    onOpen(ctx);
  } else if(GetOpParam.Op.GETFILECHECKSUM.name().equalsIgnoreCase(op)
    && method == GET) {
    onGetFileChecksum(ctx);
  } else {
    throw new IllegalArgumentException("Invalid operation " + op);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:WebHdfsHandler.java

示例9: computeAccessSignature

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
private String computeAccessSignature(String timestamp, HttpMethod method, String urlTxt, ByteBuffer body)
        throws GeneralSecurityException {
    if (conn == null) {
        throw new IllegalStateException("cannot generate exchange request post-disconnect()");
    }

    String prehash = timestamp + method.name() + urlTxt;

    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(signingKey);
    mac.update(prehash.getBytes());
    if (body != null) {
        mac.update(body);
    }
    return new String(Base64.encodeBase64(mac.doFinal()));
}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:17,代码来源:GdaxExchangeSession.java

示例10: testCorsConfig

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
public void testCorsConfig() {
    final Set<String> methods = new HashSet<>(Arrays.asList("get", "options", "post"));
    final Set<String> headers = new HashSet<>(Arrays.asList("Content-Type", "Content-Length"));
    final String prefix = randomBoolean() ? " " : ""; // sometimes have a leading whitespace between comma delimited elements
    final Settings settings = Settings.builder()
                                  .put(SETTING_CORS_ENABLED.getKey(), true)
                                  .put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "*")
                                  .put(SETTING_CORS_ALLOW_METHODS.getKey(), collectionToDelimitedString(methods, ",", prefix, ""))
                                  .put(SETTING_CORS_ALLOW_HEADERS.getKey(), collectionToDelimitedString(headers, ",", prefix, ""))
                                  .put(SETTING_CORS_ALLOW_CREDENTIALS.getKey(), true)
                                  .build();
    final Netty4CorsConfig corsConfig = Netty4HttpServerTransport.buildCorsConfig(settings);
    assertTrue(corsConfig.isAnyOriginSupported());
    assertEquals(headers, corsConfig.allowedRequestHeaders());
    assertEquals(methods, corsConfig.allowedRequestMethods().stream().map(HttpMethod::name).collect(Collectors.toSet()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:Netty4HttpServerTransportTests.java

示例11: testReleaseOnSendToClosedChannel

import io.netty.handler.codec.http.HttpMethod; //导入依赖的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
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:Netty4HttpChannelTests.java

示例12: executeRequest

import io.netty.handler.codec.http.HttpMethod; //导入依赖的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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:Netty4HttpChannelTests.java

示例13: sendRequest

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
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,代码行数:10,代码来源:NettyHttpClient.java

示例14: ifConnectSuccess

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
private boolean ifConnectSuccess(ChannelHandlerContext ctx, FullHttpRequest request) {
    if (!request.decoderResult().isSuccess()) {
        sendError(ctx, HttpResponseStatus.BAD_REQUEST);
        return false;
    }
    if (request.method() != HttpMethod.GET) {
        sendError(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED);
        return false;
    }
    return true;
}
 
开发者ID:noti0na1,项目名称:HFSN,代码行数:12,代码来源:HttpFileServerHandler.java

示例15: getMethodlessRouter

import io.netty.handler.codec.http.HttpMethod; //导入依赖的package包/类
private MethodlessRouter<T> getMethodlessRouter(HttpMethod method) {
    if (method == null) {
        return anyMethodRouter;
    }

    MethodlessRouter<T> r = routers.get(method);
    if (r == null) {
        r = new MethodlessRouter<T>();
        routers.put(method, r);
    }

    return r;
}
 
开发者ID:all4you,项目名称:redant,代码行数:14,代码来源:Router.java


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