本文整理汇总了Java中io.vertx.core.http.HttpServerResponse.ended方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.ended方法的具体用法?Java HttpServerResponse.ended怎么用?Java HttpServerResponse.ended使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.ended方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addResponseHeaders
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
default void addResponseHeaders(RouteDefinition definition, HttpServerResponse response) {
if (!response.ended() &&
!response.headers().contains(HttpHeaders.CONTENT_TYPE)) {
if (definition != null &&
definition.getProduces() != null) {
for (MediaType produces : definition.getProduces()) {
response.putHeader(HttpHeaders.CONTENT_TYPE, MediaTypeHelper.toString(produces));
}
}
else {
response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD);
}
}
}
示例2: produceResponse
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static void produceResponse(Object result, RoutingContext context, RouteDefinition definition, HttpResponseWriter writer) {
HttpServerResponse response = context.response();
HttpServerRequest request = context.request();
// add default response headers per definition
writer.addResponseHeaders(definition, response);
// write response and override headers if necessary
writer.write(result, request, response);
// finish if not finished by writer
if (!response.ended()) {
response.end();
}
}
示例3: reply
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public static void reply(
final RoutingContext context,
final Envelop envelop) {
// 1. Get response reference
final HttpServerResponse response
= context.response();
// 2. Set response status
final HttpStatusCode code = envelop.status();
response.setStatusCode(code.code());
response.setStatusMessage(code.message());
response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
// 3. Response process
if (!response.ended()) {
response.end(envelop.response());
}
response.close();
}
示例4: handleException
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static void handleException(Exception e, RoutingContext context, final RouteDefinition definition) {
ExecuteException ex = getExecuteException(e);
// get appropriate exception handler/writer ...
ExceptionHandler handler;
try {
Class<? extends Throwable> clazz;
if (ex.getCause() == null) {
clazz = ex.getClass();
} else {
clazz = ex.getCause().getClass();
}
Class<? extends ExceptionHandler>[] exHandlers = null;
if (definition != null) {
exHandlers = definition.getExceptionHandlers();
}
handler = handlers.getExceptionHandler(injectionProvider, exHandlers, clazz);
ContextProviderFactory.injectContext(handler, definition, context);
}
catch (ClassFactoryException classException) {
// Can't provide exception handler ... rethrow
log.error("Can't provide exception handler!", classException);
// fall back to generic ...
handler = new GenericExceptionHandler();
ex = new ExecuteException(500, classException);
}
catch (ContextException contextException) {
// Can't provide @Context for handler ... rethrow
log.error("Can't provide @Context!", contextException);
// fall back to generic ...
handler = new GenericExceptionHandler();
ex = new ExecuteException(500, contextException);
}
HttpServerResponse response = context.response();
response.setStatusCode(ex.getStatusCode());
handler.addResponseHeaders(definition, response);
handler.write(ex.getCause(), context.request(), context.response());
// end response ...
if (!response.ended()) {
response.end();
}
}