本文整理了Java中com.linecorp.armeria.common.HttpResponse.of()
方法的一些代码示例,展示了HttpResponse.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.of()
方法的具体详情如下:
包路径:com.linecorp.armeria.common.HttpResponse
类名称:HttpResponse
方法名:of
[英]Creates a new HTTP response of the specified statusCode and closes the stream if the HttpStatusClass is not HttpStatusClass#INFORMATIONAL (1xx).
[中]创建指定状态代码的新HTTP响应,如果HttpStatusClass不是HttpStatusClass#information(1xx),则关闭流。
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response of OK status with the content as UTF_8 and closes the stream.
*
* @param content the content of the response
*/
static HttpResponse of(String content) {
return of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content);
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response of OK status with the content as UTF_8 and closes the stream.
* The content of the response is formatted by {@link String#format(Locale, String, Object...)} with
* {@linkplain Locale#ENGLISH English locale}.
*
* @param format {@linkplain Formatter the format string} of the response content
* @param args the arguments referenced by the format specifiers in the format string
*/
static HttpResponse of(String format, Object... args) {
return of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, format, args);
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response of the specified headers.
*/
static HttpResponse of(HttpHeaders headers) {
return of(headers, HttpData.EMPTY_DATA);
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response of OK status with the content and closes the stream.
*
* @param mediaType the {@link MediaType} of the response content
* @param content the content of the response
*/
static HttpResponse of(MediaType mediaType, String content) {
return of(HttpStatus.OK, mediaType, content);
}
代码示例来源:origin: line/armeria
@Override
protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req)
throws Exception {
return HttpResponse.of(HttpStatus.OK, MediaType.JSON_UTF_8,
objectMapper.writeValueAsBytes(dropwizardRegistry));
}
});
代码示例来源:origin: line/armeria
/**
* Invoked when {@code req} is throttled. By default, this method responds with the
* {@link HttpStatus#SERVICE_UNAVAILABLE} status.
*/
@Override
protected HttpResponse onFailure(ServiceRequestContext ctx, HttpRequest req, @Nullable Throwable cause)
throws Exception {
return HttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE);
}
}
代码示例来源:origin: line/armeria
@Override
protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req)
throws Exception {
return HttpResponse.of(HttpStatus.OK, MediaType.JSON_UTF_8,
objectMapper.writeValueAsBytes(dropwizardRegistry));
}
});
代码示例来源:origin: line/armeria
/**
* Converts this message into a new complete {@link HttpResponse}.
*
* @deprecated Use {@link HttpResponse#of(AggregatedHttpMessage)}.
*/
@Deprecated
default HttpResponse toHttpResponse() {
return HttpResponse.of(this);
}
}
代码示例来源:origin: line/armeria
@Override
protected HttpResponse doRead(HttpHeaders headers, long length,
Executor fileReadExecutor, ByteBufAllocator alloc) {
if (content instanceof ByteBufHolder) {
final ByteBufHolder holder = (ByteBufHolder) content;
return HttpResponse.of(headers, (HttpData) holder.retainedDuplicate());
} else {
return HttpResponse.of(headers, content);
}
}
代码示例来源:origin: line/armeria
@Override
public HttpResponse convertResponse(ServiceRequestContext ctx,
HttpHeaders headers,
@Nullable Object result,
HttpHeaders trailingHeaders) throws Exception {
if (result == null) {
// Ignore the specified headers and return '204 No Content'.
return HttpResponse.of(HttpStatus.NO_CONTENT);
}
return ResponseConverterFunction.fallthrough();
}
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response of the specified {@link HttpStatus} and closes the stream.
*
* @param mediaType the {@link MediaType} of the response content
* @param content the content of the response
* @param offset the start offset of {@code content}
* @param length the length of {@code content}
*/
static HttpResponse of(HttpStatus status, MediaType mediaType, byte[] content, int offset, int length) {
return of(status, mediaType, HttpData.of(content, offset, length));
}
代码示例来源:origin: line/armeria
/**
* Returns a new {@link HttpResponseException} instance with the specified {@link AggregatedHttpMessage}.
*/
public static HttpResponseException of(AggregatedHttpMessage httpMessage) {
return of(HttpResponse.of(requireNonNull(httpMessage, "httpMessage")));
}
代码示例来源:origin: line/armeria
@Override
protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req) {
return HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "ok");
}
})
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response of the specified {@code statusCode} and closes the stream if the
* {@link HttpStatusClass} is not {@linkplain HttpStatusClass#INFORMATIONAL informational} (1xx).
*/
static HttpResponse of(int statusCode) {
return of(HttpStatus.valueOf(statusCode));
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP response of the specified {@link HttpStatus} and closes the stream.
*
* @param mediaType the {@link MediaType} of the response content
* @param content the content of the response
*/
static HttpResponse of(HttpStatus status, MediaType mediaType, String content) {
return of(status, mediaType, content.getBytes(mediaType.charset().orElse(StandardCharsets.UTF_8)));
}
代码示例来源:origin: line/armeria
@Override
public HttpResponse convertResponse(ServiceRequestContext ctx,
HttpHeaders headers,
@Nullable Object result,
HttpHeaders trailingHeaders) throws Exception {
return HttpResponse.of(HttpStatus.OK);
}
}
代码示例来源:origin: line/armeria
/**
* NB: For now we redirect all methods.
*/
@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req)
throws Exception {
return HttpResponse.of(HttpHeaders.of(httpStatus)
.set(HttpHeaderNames.LOCATION, locationFunction.apply(ctx)));
}
代码示例来源:origin: line/armeria
@Override
public HttpResponse handleException(RequestContext ctx, HttpRequest req, Throwable cause) {
if (cause instanceof IllegalArgumentException) {
return HttpResponse.of("exception");
}
return ExceptionHandlerFunction.fallthrough();
}
}
代码示例来源:origin: line/armeria
@Override
public void messageRead(ByteBufOrStream message) {
// We know there is only one message in total, so don't bother with checking endOfStream
// We also know that we don't support compression, so this is always a ByteBuffer.
final HttpData unframedContent = new ByteBufHttpData(message.buf(), true);
unframedHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, unframedContent.length());
res.complete(HttpResponse.of(unframedHeaders, unframedContent));
}
代码示例来源:origin: line/armeria
@Override
public HttpResponse loginSucceeded(ServiceRequestContext ctx, AggregatedHttpMessage req,
MessageContext<Response> message, @Nullable String sessionIndex,
@Nullable String relayState) {
return HttpResponse.of(headersWithLocation(firstNonNull(relayState, "/"))
.add(HttpHeaderNames.SET_COOKIE, setCookie));
}
内容来源于网络,如有侵权,请联系作者删除!