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


Java HttpRequest.streaming方法代码示例

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


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

示例1: notSupported

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
@Test
public void notSupported() throws Exception {
    HttpRequestWriter noopRequest = HttpRequest.streaming(HttpMethod.PUT, "/");
    noopRequest.write(() -> HttpData.ofAscii("noop"));
    noopRequest.close();

    AggregatedHttpMessage res = service.serve(context, noopRequest).aggregate().get();

    assertThat(res.status(), is(HttpStatus.BAD_REQUEST));
    assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE)),
               is(MediaType.PLAIN_TEXT_UTF_8.toString()));
    assertThat(res.content().toStringUtf8(), is("Not supported."));

    service.serverHealth.setHealthy(true);

    noopRequest = HttpRequest.streaming(HttpMethod.PUT, "/");
    noopRequest.write(() -> HttpData.ofAscii("noop"));
    noopRequest.close();

    res = service.serve(context, noopRequest).aggregate().get();

    assertThat(res.status(), is(HttpStatus.BAD_REQUEST));
    assertThat(res.headers().get(AsciiString.of(HttpHeaders.CONTENT_TYPE)),
               is(MediaType.PLAIN_TEXT_UTF_8.toString()));
    assertThat(res.content().toStringUtf8(), is("Not supported."));
}
 
开发者ID:line,项目名称:armeria,代码行数:27,代码来源:ManagedHttpHealthCheckServiceTest.java

示例2: testStreamRequestLongerThanTimeout

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
@Test(timeout = 30000)
public void testStreamRequestLongerThanTimeout() throws Exception {
    // Disable timeouts and length limits so that test does not fail due to slow transfer.
    clientWriteTimeoutMillis = 0;
    clientResponseTimeoutMillis = 0;
    clientMaxResponseLength = 0;
    serverRequestTimeoutMillis = 0;

    HttpRequestWriter request = HttpRequest.streaming(HttpMethod.POST, "/echo");
    HttpResponse response = client().execute(request);
    request.write(HttpData.ofUtf8("a"));
    Thread.sleep(2000);
    request.write(HttpData.ofUtf8("b"));
    Thread.sleep(2000);
    request.write(HttpData.ofUtf8("c"));
    Thread.sleep(2000);
    request.write(HttpData.ofUtf8("d"));
    Thread.sleep(2000);
    request.write(HttpData.ofUtf8("e"));
    request.close();
    assertThat(response.aggregate().get().content().toStringUtf8(), is("abcde"));
}
 
开发者ID:line,项目名称:armeria,代码行数:23,代码来源:HttpServerTest.java

示例3: newCall

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
@Override
public <I, O> ClientCall<I, O> newCall(
        MethodDescriptor<I, O> method, CallOptions callOptions) {
    HttpRequestWriter req = HttpRequest.streaming(
            HttpHeaders
                    .of(HttpMethod.POST, uri().getPath() + method.getFullMethodName())
                    .contentType(serializationFormat.mediaType()));
    ClientRequestContext ctx = newContext(HttpMethod.POST, req);
    ctx.logBuilder().serializationFormat(serializationFormat);
    ctx.logBuilder().requestContent(GrpcLogUtil.rpcRequest(method), null);
    ctx.logBuilder().deferResponseContent();
    return new ArmeriaClientCall<>(
            ctx,
            httpClient,
            req,
            method,
            options().getOrElse(GrpcClientOptions.MAX_OUTBOUND_MESSAGE_SIZE_BYTES,
                                ArmeriaMessageFramer.NO_MAX_OUTBOUND_MESSAGE_SIZE),
            options().getOrElse(
                    GrpcClientOptions.MAX_INBOUND_MESSAGE_SIZE_BYTES,
                    options().getOrElse(
                            ClientOption.DEFAULT_MAX_RESPONSE_LENGTH,
                            (long) DEFAULT_MAX_INBOUND_MESSAGE_SIZE).intValue()),
            callOptions,
            CompressorRegistry.getDefaultInstance(),
            DecompressorRegistry.getDefaultInstance(),
            serializationFormat,
            jsonMarshaller);
}
 
开发者ID:line,项目名称:armeria,代码行数:30,代码来源:ArmeriaChannel.java

示例4: invoke0

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static void invoke0(THttpService service, HttpData content,
                            CompletableFuture<HttpData> promise) throws Exception {

    final ServiceRequestContext ctx = mock(ServiceRequestContext.class);
    when(ctx.alloc()).thenReturn(ByteBufAllocator.DEFAULT);
    final DefaultRequestLog reqLogBuilder = new DefaultRequestLog(ctx);

    when(ctx.blockingTaskExecutor()).thenReturn(ImmediateEventExecutor.INSTANCE);
    when(ctx.log()).thenReturn(reqLogBuilder);
    when(ctx.logBuilder()).thenReturn(reqLogBuilder);
    doNothing().when(ctx).invokeOnEnterCallbacks();
    doNothing().when(ctx).invokeOnExitCallbacks();

    final HttpRequestWriter req = HttpRequest.streaming(HttpHeaders.of(HttpMethod.POST, "/"));

    req.write(content);
    req.close();

    final HttpResponse res = service.serve(ctx, req);
    res.aggregate().handle(voidFunction((aReq, cause) -> {
        if (cause == null) {
            if (aReq.headers().status().code() == 200) {
                promise.complete(aReq.content());
            } else {
                promise.completeExceptionally(new AssertionError(
                        aReq.headers().status() + ", " +
                        aReq.content().toString(StandardCharsets.UTF_8)));
            }
        } else {
            promise.completeExceptionally(cause);
        }
    })).exceptionally(CompletionActions::log);
}
 
开发者ID:line,项目名称:armeria,代码行数:34,代码来源:ThriftServiceTest.java

示例5: testTooLargeContent

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
@Test(timeout = 10000)
public void testTooLargeContent() throws Exception {
    clientWriteTimeoutMillis = 0L;
    final HttpRequestWriter req = HttpRequest.streaming(HttpMethod.POST, "/count");
    final CompletableFuture<AggregatedHttpMessage> f = client().execute(req).aggregate();

    stream(req, MAX_CONTENT_LENGTH + 1, 1024);

    final AggregatedHttpMessage res = f.get();

    assertThat(res.status(), is(HttpStatus.REQUEST_ENTITY_TOO_LARGE));
    assertThat(res.headers().contentType(), is(MediaType.PLAIN_TEXT_UTF_8));
    assertThat(res.content().toStringUtf8(), is("413 Request Entity Too Large"));
}
 
开发者ID:line,项目名称:armeria,代码行数:15,代码来源:HttpServerTest.java

示例6: runStreamingRequestTest

import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private void runStreamingRequestTest(String path) throws InterruptedException, ExecutionException {
    // Disable timeouts and length limits so that test does not fail due to slow transfer.
    clientWriteTimeoutMillis = 0;
    clientResponseTimeoutMillis = 0;
    serverRequestTimeoutMillis = 0;
    serverMaxRequestLength = 0;

    final HttpRequestWriter req = HttpRequest.streaming(HttpMethod.POST, path);
    final CompletableFuture<AggregatedHttpMessage> f = client().execute(req).aggregate();

    // Stream a large of the max memory.
    // This test will fail if the implementation keep the whole content in memory.
    final long expectedContentLength = STREAMING_CONTENT_LENGTH;

    try {
        stream(req, expectedContentLength, STREAMING_CONTENT_CHUNK_LENGTH);

        final AggregatedHttpMessage res = f.get();

        assertThat(res.status(), is(HttpStatus.OK));
        assertThat(res.headers().contentType(), is(MediaType.PLAIN_TEXT_UTF_8));
        assertThat(res.content().toStringUtf8(), is(String.valueOf(expectedContentLength)));
    } finally {
        // Make sure the stream is closed even when this test fails due to timeout.
        req.close();
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:28,代码来源:HttpServerTest.java


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