/** * Returns whether the verbose exception mode is enabled. When enabled, the exceptions frequently thrown by * Armeria will have full stack trace. When disabled, such exceptions will have empty stack trace to * eliminate the cost of capturing the stack trace. * * @deprecated Use {@link Flags#verboseExceptions()} instead. */ @Deprecated public static boolean isVerbose() { return Flags.verboseExceptions(); }
/** * Returns a {@link Router} which is wrapped with a {@link Cache} layer in order to improve the * performance of the {@link CompositeServiceEntry} search. */ static <I extends Request, O extends Response> Router<CompositeServiceEntry<I, O>> wrapCompositeServiceRouter( Router<CompositeServiceEntry<I, O>> delegate) { final Cache<PathMappingContext, CompositeServiceEntry<I, O>> cache = Flags.compositeServiceCacheSpec().map(RouteCache::<CompositeServiceEntry<I, O>>buildCache) .orElse(null); if (cache == null) { return delegate; } return new CachingRouter<>(delegate, cache, CompositeServiceEntry::pathMapping); }
/** * Creates a new instance wrapping a {@link HttpRequest} and publishing to multiple subscribers. * The length of request is limited by default with the server-side parameter which is * {@link Flags#DEFAULT_MAX_REQUEST_LENGTH}. If you are at client-side, you need to use * {@link #HttpRequestDuplicator(HttpRequest, long)} and the {@code long} value should be greater than * the length of request or {@code 0} which disables the limit. * @param req the request that will publish data to subscribers */ public HttpRequestDuplicator(HttpRequest req) { this(req, Flags.defaultMaxRequestLength()); }
/** * Creates a new instance wrapping a {@link HttpResponse} and publishing to multiple subscribers. * The length of response is limited by default with the client-side parameter which is * {@link Flags#DEFAULT_MAX_RESPONSE_LENGTH}. If you are at server-side, you need to use * {@link #HttpResponseDuplicator(HttpResponse, long)} and the {@code long} value should be greater than * the length of response or {@code 0} which disables the limit. * @param res the response that will publish data to subscribers */ public HttpResponseDuplicator(HttpResponse res) { this(res, Flags.defaultMaxResponseLength()); }
@Override public HttpResponse handleException(RequestContext ctx, HttpRequest req, Throwable cause) { final Throwable peeledCause = Exceptions.peel(cause); if (Flags.annotatedServiceExceptionVerbosity() == ExceptionVerbosity.ALL && logger.isWarnEnabled()) { logger.warn("{} Exception raised by method '{}' in '{}':", ctx, methodName, className, peeledCause); } for (final ExceptionHandlerFunction func : functions) { try { final HttpResponse response = func.handleException(ctx, req, peeledCause); // Check the return value just in case, then pass this exception to the default handler // if it is null. if (response == null) { break; } return response; } catch (FallthroughException ignore) { // Do nothing. } catch (Exception e) { logger.warn("{} Unexpected exception from an exception handler {}:", ctx, func.getClass().getName(), e); } } return HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR); } }
/** * Returns the default timeout of a server reply to a client call. */ public long defaultResponseTimeoutMillis() { return getOrElse(DEFAULT_RESPONSE_TIMEOUT_MILLIS, Flags.defaultResponseTimeoutMillis()); }
/** * Creates a new instance. */ public ClientFactoryBuilder() { connectTimeoutMillis(Flags.defaultConnectTimeoutMillis()); channelOption(ChannelOption.SO_KEEPALIVE, true); }
/** * Returns the maximum allowed length of a server response. */ public long defaultMaxResponseLength() { return getOrElse(DEFAULT_MAX_RESPONSE_LENGTH, Flags.defaultMaxResponseLength()); }
@Override public HttpResponse handleException(RequestContext ctx, HttpRequest req, Throwable cause) { if (cause instanceof IllegalArgumentException) { return HttpResponse.of(HttpStatus.BAD_REQUEST); } if (cause instanceof HttpStatusException) { return HttpResponse.of(((HttpStatusException) cause).httpStatus()); } if (cause instanceof HttpResponseException) { return ((HttpResponseException) cause).httpResponse(); } if (Flags.annotatedServiceExceptionVerbosity() == ExceptionVerbosity.UNHANDLED && logger.isWarnEnabled()) { logger.warn("{} Unhandled exception from an annotated service:", ctx, cause); } return HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR); } }
/** * Returns a {@link ClosedSessionException} which may be a singleton or a new instance, depending on * whether {@linkplain Flags#verboseExceptions() the verbose exception mode} is enabled. */ public static ClosedSessionException get() { return Flags.verboseExceptions() ? new ClosedSessionException() : INSTANCE; }
/** * Returns a {@link ContentTooLargeException} which may be a singleton or a new instance, depending on * whether {@linkplain Flags#verboseExceptions() the verbose exception mode} is enabled. */ public static ContentTooLargeException get() { return Flags.verboseExceptions() ? new ContentTooLargeException() : INSTANCE; }
@Override public Throwable fillInStackTrace() { if (Flags.verboseExceptions()) { return super.fillInStackTrace(); } return this; } }
/** * Returns a {@link AbortedStreamException} which may be a singleton or a new instance, depending on * whether {@linkplain Flags#verboseExceptions() the verbose exception mode} is enabled. */ public static AbortedStreamException get() { return Flags.verboseExceptions() ? new AbortedStreamException() : INSTANCE; }
@Override public Throwable fillInStackTrace() { if (Flags.verboseExceptions()) { return super.fillInStackTrace(); } return this; } }
/** * Returns a {@link ClosedPublisherException} which may be a singleton or a new instance, depending on * whether {@linkplain Flags#verboseExceptions() the verbose exception mode} is enabled. */ public static ClosedPublisherException get() { return Flags.verboseExceptions() ? new ClosedPublisherException() : INSTANCE; }
@Override public Throwable fillInStackTrace() { if (Flags.verboseExceptions()) { super.fillInStackTrace(); } return this; } }
/** * Returns an {@link UnprocessedRequestException} which may be a singleton or a new instance, depending on * whether {@linkplain Flags#verboseExceptions() the verbose exception mode} is enabled. */ public static UnprocessedRequestException get() { return Flags.verboseExceptions() ? new UnprocessedRequestException() : INSTANCE; }
/** * Returns a {@link CancelledSubscriptionException} which may be a singleton or a new instance, depending * on whether {@linkplain Flags#verboseExceptions() the verbose exception mode} is enabled. */ public static CancelledSubscriptionException get() { return Flags.verboseExceptions() ? new CancelledSubscriptionException() : INSTANCE; }
if (Flags.verboseExceptions()) { return false;
/** * Returns a new {@link HttpStatusException} instance with the specified HTTP status code. */ public static HttpStatusException of(int statusCode) { if (statusCode < 0 || statusCode >= 1000) { final HttpStatus status = HttpStatus.valueOf(statusCode); if (Flags.verboseExceptions()) { return new HttpStatusException(status); } else { return new HttpStatusException(status, false); } } else { return EXCEPTIONS[statusCode]; } }