本文整理汇总了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."));
}
示例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"));
}
示例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);
}
示例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);
}
示例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"));
}
示例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();
}
}