本文整理了Java中com.hotels.styx.api.HttpResponse.stream()
方法的一些代码示例,展示了HttpResponse.stream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.stream()
方法的具体详情如下:
包路径:com.hotels.styx.api.HttpResponse
类名称:HttpResponse
方法名:stream
[英]Converts this response to a streaming form (LiveHttpResponse).
Converts this response to an LiveHttpResponse object which represents the HTTP response as a stream of bytes.
[中]将此响应转换为流形式(LiveHttpResponse)。
将此响应转换为LiveHttpResponse对象,该对象将HTTP响应表示为字节流。
代码示例来源:origin: HotelsDotCom/styx
@Override
public Map<String, HttpHandler> adminInterfaceHandlers() {
return ImmutableMap.of("status", (request, context) -> Eventual.of(
response(OK)
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.body(format("{ name: \"%s\" status: \"%s\" }", name, status), UTF_8)
.build()
.stream()));
}
代码示例来源:origin: HotelsDotCom/styx
@Override
public LiveHttpResponse doHandle(LiveHttpRequest request) {
return HttpResponse.response(NOT_FOUND)
.body(NOT_FOUND_MESSAGE, UTF_8)
.build()
.stream();
}
}
代码示例来源:origin: HotelsDotCom/styx
static ImmutableMap<String, HttpHandler> adminHandlers(String endpoint, String responseContent) {
return ImmutableMap.of(endpoint, (request, context) -> Eventual.of(response(OK)
.body(responseContent, UTF_8)
.build().stream()));
}
}
代码示例来源:origin: HotelsDotCom/styx
static ImmutableMap<String, HttpHandler> adminHandlers(String endpoint, String responseContent) {
return ImmutableMap.of(endpoint, (request, context) -> Eventual.of(response(OK)
.body(responseContent, UTF_8)
.build()
.stream()
));
}
}
代码示例来源:origin: HotelsDotCom/styx
@Override
public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
Stream<NamedPlugin> enabled = plugins.stream().filter(NamedPlugin::enabled);
Stream<NamedPlugin> disabled = plugins.stream().filter(plugin -> !plugin.enabled());
String output = section("Enabled", enabled)
+ section("Disabled", disabled);
return Eventual.of(response(OK)
.body(output, UTF_8)
.addHeader(CONTENT_TYPE, HTML_UTF_8.toString())
.build()
.stream());
}
代码示例来源:origin: HotelsDotCom/styx
private LiveHttpResponse generateResponse() {
Content content = contentSupplier.get();
return response(OK)
.header(CONTENT_TYPE, content.type)
.header(CONTENT_LENGTH, content.length)
.body(content.content, UTF_8)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
private LiveHttpResponse okResponse(String content) {
return HttpResponse.response(OK)
.header(CONTENT_TYPE, PLAIN_TEXT_UTF_8)
.body(content, UTF_8)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
private LiveHttpResponse errorResponse(HttpResponseStatus code, String content) {
return HttpResponse.response(code)
.header(CONTENT_TYPE, PLAIN_TEXT_UTF_8)
.body(content, UTF_8)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
@Override
public LiveHttpResponse doHandle(LiveHttpRequest request) {
boolean withStackTrace = request.queryParam("withStackTrace")
.map("true"::equals)
.orElse(false);
return HttpResponse
.response(OK)
.disableCaching()
.header(CONTENT_TYPE, PLAIN_TEXT_UTF_8)
.body(getCurrentRequestContent(withStackTrace), UTF_8, true)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
public static HttpHandler returnsResponse(String response) {
return returnsResponse(() -> response().body(response, UTF_8).build().stream());
}
代码示例来源:origin: HotelsDotCom/styx
@Test(dataProvider = "emptyBodyResponses")
public void convertsToStreamingHttpResponseWithEmptyBody(HttpResponse response) throws ExecutionException, InterruptedException {
LiveHttpResponse streaming = response.stream();
byte[] result = streaming.body().aggregate(1000)
.get()
.content();
assertThat(result.length, is(0));
}
代码示例来源:origin: HotelsDotCom/styx
LiveHttpResponse toResponse() {
return HttpResponse.response(OK)
.header(CONTENT_TYPE, contentType)
.header(CONTENT_LENGTH, contentLength)
.body(content, UTF_8)
.build()
.stream();
}
}
代码示例来源:origin: HotelsDotCom/styx
@Override
public LiveHttpResponse doHandle(LiveHttpRequest request) {
return HttpResponse.response(OK)
.disableCaching()
.header(CONTENT_TYPE, PLAIN_TEXT_UTF_8)
.body(threadDumpContent(), true)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
@Override
protected LiveHttpResponse doHandle(LiveHttpRequest request) {
return response(OK)
.disableCaching()
.addHeader(CONTENT_TYPE, PLAIN_TEXT_UTF_8.toString())
.body("pong", UTF_8)
.build()
.stream();
}
}
代码示例来源:origin: HotelsDotCom/styx
@Override
protected LiveHttpResponse doHandle(LiveHttpRequest request) {
return response(OK)
.addHeader(CONTENT_TYPE, HTML_UTF_8.toString())
.header(CONTENT_LANGUAGE, "en")
.body(html, UTF_8)
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
private static LiveHttpResponse responseWith(HttpResponseStatus status, String message) {
return HttpResponse.response(status)
.body(message + "\n", UTF_8)
.addHeader(CONTENT_TYPE, PLAIN_TEXT_UTF_8.toString())
.disableCaching()
.build()
.stream();
}
代码示例来源:origin: HotelsDotCom/styx
@Override
public LiveHttpResponse doHandle(LiveHttpRequest request) {
return HttpResponse.response(OK)
.header(CONTENT_TYPE, this.contentType.toString())
.header(CONTENT_LENGTH, this.contentLength)
.body(this.body, StandardCharsets.UTF_8)
.build()
.stream();
}
}
代码示例来源:origin: HotelsDotCom/styx
@Override
public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
MetricRequest metricRequest = new MetricRequest(request);
return metricRequest.fullMetrics()
? super.handle(request, context)
: Eventual.of(restrictedMetricsResponse(metricRequest).build().stream());
}
代码示例来源:origin: HotelsDotCom/styx
private static HttpHandler newHandler(String originId, RequestHandler wireMockHandler) {
return (httpRequest, ctx) ->
httpRequest.aggregate(MAX_CONTENT_LENGTH)
.map(fullRequest -> {
LOGGER.info("{} received: {}\n{}", new Object[]{originId, fullRequest.url(), fullRequest.body()});
return fullRequest;
})
.flatMap(fullRequest -> {
Request wmRequest = new WiremockStyxRequestAdapter(fullRequest);
com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest);
return Eventual.of(toStyxResponse(wmResponse).stream());
});
}
代码示例来源:origin: HotelsDotCom/styx
@Override
protected LiveHttpResponse doHandle(LiveHttpRequest request) {
return response(OK)
.addHeader(CONTENT_TYPE, JSON_UTF_8.toString())
.disableCaching()
.body(content(isPrettyPrint(request)), UTF_8)
.build()
.stream();
}
内容来源于网络,如有侵权,请联系作者删除!