use of ratpack.error.internal.DefaultDevelopmentErrorHandler in project ratpack by ratpack.
the class ServerRegistry method buildBaseRegistry.
public static Registry buildBaseRegistry(RatpackServer ratpackServer, Impositions impositions, ExecController execController, ServerConfig serverConfig) {
ErrorHandler errorHandler = serverConfig.isDevelopment() ? new DefaultDevelopmentErrorHandler() : new DefaultProductionErrorHandler();
RegistryBuilder baseRegistryBuilder;
try {
HttpClient httpClient = HttpClient.of(s -> s.poolSize(0).byteBufAllocator(PooledByteBufAllocator.DEFAULT).maxContentLength(serverConfig.getMaxContentLength()));
baseRegistryBuilder = Registry.builder().add(ServerConfig.class, serverConfig).add(Impositions.class, impositions).add(ByteBufAllocator.class, PooledByteBufAllocator.DEFAULT).add(ExecController.class, execController).add(MimeTypes.class, ActivationBackedMimeTypes.INSTANCE).add(PublicAddress.class, Optional.ofNullable(serverConfig.getPublicAddress()).map(PublicAddress::of).orElseGet(() -> PublicAddress.inferred(serverConfig.getSslContext() == null ? HTTP_SCHEME : HTTPS_SCHEME))).add(Redirector.TYPE, Redirector.standard()).add(ClientErrorHandler.class, errorHandler).add(ServerErrorHandler.class, errorHandler).add(FileRenderer.TYPE, serverConfig.isDevelopment() ? FileRenderer.NON_CACHING : FileRenderer.CACHING).add(PromiseRenderer.TYPE, PromiseRenderer.INSTANCE).add(PublisherRenderer.TYPE, PublisherRenderer.INSTANCE).add(OptionalRenderer.TYPE, OptionalRenderer.INSTANCE).add(RenderableRenderer.TYPE, RenderableRenderer.INSTANCE).add(CharSequenceRenderer.TYPE, CharSequenceRenderer.INSTANCE).add(JsonRenderer.TYPE, JsonRenderer.INSTANCE).add(FormParser.TYPE, FormParser.INSTANCE).add(JsonParser.TYPE, JsonParser.INSTANCE).add(Clock.class, Clock.systemDefaultZone()).add(RatpackServer.class, ratpackServer).add(ObjectMapper.class, new ObjectMapper()).add(Stopper.class, () -> uncheck(() -> {
ratpackServer.stop();
return null;
})).add(HttpClient.class, httpClient).add(ServerSentEventStreamClient.class, ServerSentEventStreamClient.of(httpClient)).add(HealthCheckResultsRenderer.TYPE, new HealthCheckResultsRenderer(PooledByteBufAllocator.DEFAULT)).add(RequestId.Generator.class, UuidBasedRequestIdGenerator.INSTANCE);
addConfigObjects(serverConfig, baseRegistryBuilder);
} catch (Exception e) {
// Uncheck because it really shouldn't happen
throw uncheck(e);
}
if (serverConfig.isHasBaseDir()) {
baseRegistryBuilder.add(FileSystemBinding.class, serverConfig.getBaseDir());
}
return baseRegistryBuilder.build();
}
Aggregations