本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
示例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());
}
示例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"));
}
示例8: newRequestWithoutToken
import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
private static HttpRequest newRequestWithoutToken() {
return HttpRequest.of(HttpMethod.GET, "/");
}
示例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());
}
示例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;
}
示例11: DummyRequestContext
import com.linecorp.armeria.common.HttpRequest; //导入方法依赖的package包/类
DummyRequestContext() {
super(NoopMeterRegistry.get(), SessionProtocol.HTTP,
HttpMethod.GET, "/", null, HttpRequest.of(HttpMethod.GET, "/"));
}
示例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();
}