@Provides
 ServerSentEventStreamClient sseClient(ByteBufAllocator byteBufAllocator) {
   return ServerSentEventStreamClient.sseStreamClient(byteBufAllocator);
 }
Exemplo n.º 2
0
  public static Registry buildBaseRegistry(
      RatpackServer ratpackServer, ExecController execController, ServerConfig serverConfig) {
    ErrorHandler errorHandler =
        serverConfig.isDevelopment()
            ? new DefaultDevelopmentErrorHandler()
            : new DefaultProductionErrorHandler();

    RegistryBuilder baseRegistryBuilder;
    try {
      baseRegistryBuilder =
          Registry.builder()
              .add(ServerConfig.class, serverConfig)
              .add(ByteBufAllocator.class, PooledByteBufAllocator.DEFAULT)
              .add(ExecController.class, execController)
              .add(MimeTypes.class, new ActivationBackedMimeTypes())
              .add(
                  PublicAddress.class,
                  new DefaultPublicAddress(
                      serverConfig.getPublicAddress(),
                      serverConfig.getSSLContext() == null ? HTTP_SCHEME : HTTPS_SCHEME))
              .add(Redirector.class, new DefaultRedirector())
              .add(ClientErrorHandler.class, errorHandler)
              .add(ServerErrorHandler.class, errorHandler)
              .with(new DefaultFileRenderer().register())
              .with(new PromiseRenderer().register())
              .with(new PublisherRenderer().register())
              .with(new RenderableRenderer().register())
              .with(new CharSequenceRenderer().register())
              .add(FormParser.class, FormParser.multiPart())
              .add(FormParser.class, FormParser.urlEncoded())
              .add(FormNoOptParser.class, FormNoOptParser.multiPart())
              .add(FormNoOptParser.class, FormNoOptParser.urlEncoded())
              .add(RatpackServer.class, ratpackServer)
              // TODO remove Stopper, and just use RatpackServer instead (will need to update perf
              // and gradle tests)
              .add(
                  Stopper.class,
                  () ->
                      uncheck(
                          () -> {
                            ratpackServer.stop();
                            return null;
                          }))
              .add(
                  HttpClient.class,
                  HttpClient.httpClient(
                      PooledByteBufAllocator.DEFAULT, serverConfig.getMaxContentLength()))
              .add(
                  ServerSentEventStreamClient.class,
                  ServerSentEventStreamClient.sseStreamClient(PooledByteBufAllocator.DEFAULT))
              .add(HealthCheckResultsRenderer.class, new HealthCheckResultsRenderer())
              .add(RequestId.Generator.class, new UuidBasedRequestIdGenerator());

      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();
  }