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


Java HttpRequest.of方法代码示例

本文整理汇总了Java中com.linecorp.armeria.common.HttpRequest.of方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.of方法的具体用法?Java HttpRequest.of怎么用?Java HttpRequest.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.linecorp.armeria.common.HttpRequest的用法示例。


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

示例1: rpc

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
@Test
public void rpc() {
    final MeterRegistry registry = PrometheusMeterRegistries.newRegistry();
    final ClientRequestContext ctx = new DefaultClientRequestContext(
            mock(EventLoop.class), registry, SessionProtocol.H2C,
            Endpoint.of("example.com", 8080), HttpMethod.POST, "/bar", null, null,
            ClientOptions.DEFAULT, HttpRequest.of(HttpMethod.POST, "/bar"));

    final MeterIdPrefixFunction meterIdPrefixFunction = MeterIdPrefixFunction.ofDefault("bar");

    ctx.logBuilder().startRequest(mock(Channel.class), SessionProtocol.H2C, "example.com");
    RequestMetricSupport.setup(ctx, meterIdPrefixFunction);

    ctx.logBuilder().requestHeaders(HttpHeaders.of(HttpMethod.POST, "/bar"));
    ctx.logBuilder().requestContent(new DefaultRpcRequest(Object.class, "baz"), null);

    assertThat(registry.find("bar.activeRequests")
                       .tags("method", "baz")
                       .value(Statistic.Count, 1).meter()).isPresent();
}
 
开发者ID:line,项目名称:armeria,代码行数:21,代码来源:RequestMetricSupportTest.java

示例2: newServiceContext

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static ServiceRequestContext newServiceContext(String path, String query) throws Exception {
    final Channel ch = mock(Channel.class);
    when(ch.remoteAddress()).thenReturn(
            new InetSocketAddress(InetAddress.getByAddress("client.com", new byte[] { 1, 2, 3, 4 }),
                                  5678));
    when(ch.localAddress()).thenReturn(
            new InetSocketAddress(InetAddress.getByAddress("server.com", new byte[] { 5, 6, 7, 8 }),
                                  8080));

    final HttpService service = mock(HttpService.class);
    final Server server = new ServerBuilder().withVirtualHost("some-host.server.com")
                                             .serviceUnder("/", service)
                                             .and().build();
    final VirtualHost virtualHost = server.config().findVirtualHost("some-host.server.com");
    final ServiceConfig serviceConfig = virtualHost.serviceConfigs().get(0);
    final HttpRequest req = HttpRequest.of(HttpHeaders.of(HttpMethod.GET, path + '?' + query)
                                                      .authority("server.com:8080"));
    final PathMappingContext mappingCtx =
            new DummyPathMappingContext(virtualHost, "server.com", path, query, req.headers());

    final ServiceRequestContext ctx = new DefaultServiceRequestContext(
            serviceConfig, ch, NoopMeterRegistry.get(), SessionProtocol.H2, mappingCtx,
            PathMappingResult.of(path, query, ImmutableMap.of()), req, newSslSession());

    ctx.attr(MY_ATTR).set(new CustomValue("some-attr"));
    return ctx;
}
 
开发者ID:line,项目名称:armeria,代码行数:28,代码来源:RequestContextExportingAppenderTest.java

示例3: newClientContext

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static ClientRequestContext newClientContext(String path, String query) throws Exception {
    final Channel ch = mock(Channel.class);
    when(ch.remoteAddress()).thenReturn(
            new InetSocketAddress(InetAddress.getByAddress("server.com", new byte[] { 1, 2, 3, 4 }),
                                  8080));
    when(ch.localAddress()).thenReturn(
            new InetSocketAddress(InetAddress.getByAddress("client.com", new byte[] { 5, 6, 7, 8 }),
                                  5678));

    final HttpRequest req = HttpRequest.of(HttpHeaders.of(HttpMethod.GET, path + '?' + query)
                                                      .authority("server.com:8080"));

    final DefaultClientRequestContext ctx = new DefaultClientRequestContext(
            mock(EventLoop.class), NoopMeterRegistry.get(), SessionProtocol.H2,
            Endpoint.of("server.com", 8080), req.method(), path, query, null,
            ClientOptions.DEFAULT, req) {

        @Nullable
        @Override
        public SSLSession sslSession() {
            return newSslSession();
        }
    };

    ctx.logBuilder().startRequest(ch, ctx.sessionProtocol(), "some-host.server.com");

    ctx.attr(MY_ATTR).set(new CustomValue("some-attr"));
    return ctx;
}
 
开发者ID:line,项目名称:armeria,代码行数:30,代码来源:RequestContextExportingAppenderTest.java

示例4: testRemoteInvocation

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static void testRemoteInvocation(Tracing tracing, String remoteServiceName)
        throws Exception {

    // prepare parameters
    final HttpRequest req = HttpRequest.of(HttpMethod.POST, "/hello/armeria");
    final RpcRequest rpcReq = RpcRequest.of(HelloService.Iface.class, "hello", "Armeria");
    final HttpResponse res = HttpResponse.of(HttpStatus.OK);
    final RpcResponse rpcRes = RpcResponse.of("Hello, Armeria!");
    final ClientRequestContext ctx = new DefaultClientRequestContext(
            new DefaultEventLoop(), NoopMeterRegistry.get(), H2C, Endpoint.of("localhost", 8080),
            HttpMethod.POST, "/hello/armeria", null, null, ClientOptions.DEFAULT, req);

    ctx.logBuilder().startRequest(mock(Channel.class), H2C, "localhost");
    ctx.logBuilder().requestContent(rpcReq, req);
    ctx.logBuilder().endRequest();

    @SuppressWarnings("unchecked")
    Client<HttpRequest, HttpResponse> delegate = mock(Client.class);
    when(delegate.execute(any(), any())).thenReturn(res);

    HttpTracingClient stub = new HttpTracingClient(delegate, tracing, remoteServiceName);

    // do invoke
    HttpResponse actualRes = stub.execute(ctx, req);

    assertThat(actualRes).isEqualTo(res);

    verify(delegate, times(1)).execute(ctx, req);

    ctx.logBuilder().responseHeaders(HttpHeaders.of(HttpStatus.OK));
    ctx.logBuilder().responseContent(rpcRes, res);
    ctx.logBuilder().endResponse();
}
 
开发者ID:line,项目名称:armeria,代码行数:34,代码来源:HttpTracingClientTest.java

示例5: healthy

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
@Test
public void healthy() throws Exception {
    when(health1.isHealthy()).thenReturn(true);
    when(health2.isHealthy()).thenReturn(true);
    when(health3.isHealthy()).thenReturn(true);

    final HttpRequest req = HttpRequest.of(HttpMethod.GET, "/");
    final AggregatedHttpMessage res = service.serve(context, req).aggregate().get();

    assertEquals(HttpStatus.OK, res.status());
    assertEquals("ok", res.content().toStringUtf8());
}
 
开发者ID:line,项目名称:armeria,代码行数:13,代码来源:HttpHealthCheckServiceTest.java

示例6: assertNotOk

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private void assertNotOk() throws Exception {
    final HttpRequest req = HttpRequest.of(HttpMethod.GET, "/");
    final AggregatedHttpMessage res = service.serve(context, req).aggregate().get();

    assertEquals(HttpStatus.SERVICE_UNAVAILABLE, res.status());
    assertEquals("not ok", res.content().toStringUtf8());
}
 
开发者ID:line,项目名称:armeria,代码行数:8,代码来源:HttpHealthCheckServiceTest.java

示例7: newRequestWithToken

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static HttpRequest newRequestWithToken() {
    return HttpRequest.of(HttpHeaders.of(HttpMethod.GET, "/")
                                     .set(HttpHeaderNames.AUTHORIZATION, "bearer anonymous"));
}
 
开发者ID:line,项目名称:centraldogma,代码行数:5,代码来源:TokenlessClientLoggerTest.java

示例8: newRequestWithoutToken

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static HttpRequest newRequestWithoutToken() {
    return HttpRequest.of(HttpMethod.GET, "/");
}
 
开发者ID:line,项目名称:centraldogma,代码行数:4,代码来源:TokenlessClientLoggerTest.java

示例9: frameAndServe

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private void frameAndServe(
        ServiceRequestContext ctx,
        HttpHeaders grpcHeaders,
        AggregatedHttpMessage clientRequest,
        CompletableFuture<HttpResponse> res) {
    final HttpRequest grpcRequest;
    try (ArmeriaMessageFramer framer = new ArmeriaMessageFramer(
            ctx.alloc(), ArmeriaMessageFramer.NO_MAX_OUTBOUND_MESSAGE_SIZE)) {
        HttpData content = clientRequest.content();
        ByteBuf message = ctx.alloc().buffer(content.length());
        final HttpData frame;
        boolean success = false;
        try {
            message.writeBytes(content.array(), content.offset(), content.length());
            frame = framer.writePayload(message);
            success = true;
        } finally {
            if (!success) {
                message.release();
            }
        }
        grpcRequest = HttpRequest.of(grpcHeaders, frame);
    }

    final HttpResponse grpcResponse;
    try {
        grpcResponse = delegate().serve(ctx, grpcRequest);
    } catch (Exception e) {
        res.completeExceptionally(e);
        return;
    }

    grpcResponse.aggregate().whenCompleteAsync(
            (framedResponse, t) -> {
                if (t != null) {
                    res.completeExceptionally(t);
                } else {
                    deframeAndRespond(ctx, framedResponse, res);
                }
            },
            ctx.eventLoop());
}
 
开发者ID:line,项目名称:armeria,代码行数:43,代码来源:UnframedGrpcService.java

示例10: testServiceInvocation

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static SpanCollectingReporter testServiceInvocation(float samplingRate) throws Exception {
    SpanCollectingReporter reporter = new SpanCollectingReporter();

    Tracing tracing = Tracing.newBuilder()
                             .localServiceName(TEST_SERVICE)
                             .spanReporter(reporter)
                             .sampler(Sampler.create(samplingRate))
                             .build();

    @SuppressWarnings("unchecked")
    Service<HttpRequest, HttpResponse> delegate = mock(Service.class);

    final HttpTracingService stub = new HttpTracingService(delegate, tracing);

    final ServiceRequestContext ctx = mock(ServiceRequestContext.class);
    final HttpRequest req = HttpRequest.of(HttpMethod.POST, "/hello/trustin");
    final RpcRequest rpcReq = RpcRequest.of(HelloService.Iface.class, "hello", "trustin");
    final HttpResponse res = HttpResponse.of(HttpStatus.OK);
    final RpcResponse rpcRes = RpcResponse.of("Hello, trustin!");
    final DefaultRequestLog log = new DefaultRequestLog(ctx);
    log.startRequest(mock(Channel.class), H2C, "localhost");
    log.requestContent(rpcReq, req);
    log.endRequest();

    // HttpTracingService prefers RpcRequest.method() to ctx.method(), so "POST" should be ignored.
    when(ctx.method()).thenReturn(HttpMethod.POST);
    when(ctx.log()).thenReturn(log);
    when(ctx.logBuilder()).thenReturn(log);
    when(ctx.path()).thenReturn("/hello/trustin");
    ctx.onEnter(isA(Consumer.class));
    ctx.onExit(isA(Consumer.class));
    when(delegate.serve(ctx, req)).thenReturn(res);

    // do invoke
    stub.serve(ctx, req);

    verify(delegate, times(1)).serve(eq(ctx), eq(req));
    log.responseHeaders(HttpHeaders.of(HttpStatus.OK));
    log.responseContent(rpcRes, res);
    log.endResponse();

    return reporter;
}
 
开发者ID:line,项目名称:armeria,代码行数:44,代码来源:HttpTracingServiceTest.java

示例11: DummyRequestContext

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
DummyRequestContext() {
    super(NoopMeterRegistry.get(), SessionProtocol.HTTP,
          HttpMethod.GET, "/", null, HttpRequest.of(HttpMethod.GET, "/"));
}
 
开发者ID:line,项目名称:armeria,代码行数:5,代码来源:AccessLogFormatsTest.java

示例12: http

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
@Test
public void http() {
    final MeterRegistry registry = PrometheusMeterRegistries.newRegistry();
    final ClientRequestContext ctx = new DefaultClientRequestContext(
            mock(EventLoop.class), registry, SessionProtocol.H2C,
            Endpoint.of("example.com", 8080), HttpMethod.POST, "/foo", null, null,
            ClientOptions.DEFAULT, HttpRequest.of(HttpMethod.POST, "/foo"));

    final MeterIdPrefixFunction meterIdPrefixFunction = MeterIdPrefixFunction.ofDefault("foo");

    ctx.logBuilder().startRequest(mock(Channel.class), SessionProtocol.H2C, "example.com");
    RequestMetricSupport.setup(ctx, meterIdPrefixFunction);

    ctx.logBuilder().requestHeaders(HttpHeaders.of(HttpMethod.POST, "/foo"));
    ctx.logBuilder().requestContent(null, null);
    ctx.logBuilder().requestLength(123);

    assertThat(registry.find("foo.activeRequests")
                       .tags("method", "POST")
                       .value(Statistic.Count, 1).meter()).isPresent();
    assertThat(registry.find("foo.requestDuration")
                       .tags("method", "POST")
                       .value(Statistic.Count, 0).meter()).isPresent();
    assertThat(registry.find("foo.requestDuration")
                       .tags("method", "POST")
                       .value(Statistic.Total, 0).meter()).isPresent();
    assertThat(registry.find("foo.requestLength")
                       .tags("method", "POST")
                       .value(Statistic.Count, 0).meter()).isPresent();
    assertThat(registry.find("foo.requestLength")
                       .tags("method", "POST")
                       .value(Statistic.Total, 0).meter()).isPresent();

    ctx.logBuilder().endRequest();
    assertThat(registry.find("foo.requestDuration")
                       .tags("method", "POST")
                       .value(Statistic.Count, 1).meter()).isPresent();
    assertThat(registry.find("foo.requestLength")
                       .tags("method", "POST")
                       .value(Statistic.Count, 1).meter()).isPresent();
    assertThat(registry.find("foo.requestLength")
                       .tags("method", "POST")
                       .value(Statistic.Total, 123).meter()).isPresent();

    ctx.logBuilder().responseHeaders(HttpHeaders.of(200));
    ctx.logBuilder().responseLength(456);
    ctx.logBuilder().endResponse();

    assertThat(registry.find("foo.activeRequests")
                       .tags("method", "POST")
                       .value(Statistic.Count, 0).meter()).isPresent();
    assertThat(registry.find("foo.requests")
                       .tags("method", "POST", "result", "success")
                       .value(Statistic.Count, 1).meter()).isPresent();
    assertThat(registry.find("foo.requests")
                       .tags("method", "POST", "result", "failure")
                       .value(Statistic.Count, 0).meter()).isPresent();
    assertThat(registry.find("foo.responseDuration")
                       .tags("method", "POST")
                       .value(Statistic.Count, 1).meter()).isPresent();
    assertThat(registry.find("foo.responseLength")
                       .tags("method", "POST")
                       .value(Statistic.Count, 1).meter()).isPresent();
    assertThat(registry.find("foo.responseLength")
                       .tags("method", "POST")
                       .value(Statistic.Total, 456).meter()).isPresent();
    assertThat(registry.find("foo.totalDuration")
                       .tags("method", "POST")
                       .value(Statistic.Count, 1).meter()).isPresent();
}
 
开发者ID:line,项目名称:armeria,代码行数:71,代码来源:RequestMetricSupportTest.java


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