Package ratpack.registry

Examples of ratpack.registry.RegistryBuilder


  private class CommandHandler implements Handler {
    @Override
    public void handle(Context context) throws Exception {
      final Registry commandRegistry = context.join(registry);
      final RegistryBuilder registryBuilder = Registries.registry();

      Receiver receiver = new RatpackReceiver(chain -> new DelegatingCommandDelegate(registryBuilder, commandRegistry) {
        @Override
        public void clearRegistry() {
          registryReference.set(null);
        }
      });

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      receiver.execute(context.getRequest().getBody().getInputStream(), outputStream);

      if (registryBuilder.size() > 0) {
        Registry newRegistry = registryBuilder.build();
        registryReference.set(newRegistry);
      }

      context.getResponse().send(ContentType.RESULT.getValue(), outputStream.toByteArray());
    }
View Full Code Here


  }

  public static Registry buildBaseRegistry(Stopper stopper, LaunchConfig launchConfig) {
    ErrorHandler errorHandler = launchConfig.isDevelopment() ? new DefaultDevelopmentErrorHandler() : new DefaultProductionErrorHandler();

    RegistryBuilder registryBuilder = Registries.registry()
      .add(Stopper.class, stopper)
      .add(MimeTypes.class, new ActivationBackedMimeTypes())
      .add(PublicAddress.class, new DefaultPublicAddress(launchConfig.getPublicAddress(), launchConfig.getSSLContext() == null ? HTTP_SCHEME : HTTPS_SCHEME))
      .add(Redirector.class, new DefaultRedirector())
      .add(ClientErrorHandler.class, errorHandler)
      .add(ServerErrorHandler.class, errorHandler)
      .add(LaunchConfig.class, launchConfig)
      .add(FileRenderer.class, new DefaultFileRenderer())
      .add(ServerSentEventsRenderer.TYPE, new ServerSentEventsRenderer(launchConfig.getBufferAllocator()))
      .add(HttpResponseChunksRenderer.TYPE, new HttpResponseChunksRenderer())
      .add(CharSequenceRenderer.class, new DefaultCharSequenceRenderer())
      .add(FormParser.class, FormParser.multiPart())
      .add(FormParser.class, FormParser.urlEncoded())
      .add(HttpClient.class, HttpClients.httpClient(launchConfig));

    if (launchConfig.isHasBaseDir()) {
      registryBuilder.add(FileSystemBinding.class, launchConfig.getBaseDir());
    }

    Registry foundationRegistry = registryBuilder.build();
    Registry defaultRegistry = launchConfig.getDefaultRegistry();
    return defaultRegistry != null ? foundationRegistry.join(defaultRegistry) : foundationRegistry;
  }
View Full Code Here

TOP

Related Classes of ratpack.registry.RegistryBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.