Package ratpack.registry

Examples of ratpack.registry.Registry


    ServerErrorHandler serverErrorHandler = (context, throwable1) -> {
      DefaultHandlingResult.this.throwable = throwable1;
      latch.countDown();
    };

    final Registry userRegistry = Registries.registry().
      add(ClientErrorHandler.class, clientErrorHandler).
      add(ServerErrorHandler.class, serverErrorHandler).
      build()
      .join(registry);

    final RenderController renderController = (object, context) -> {
      rendered = object;
      latch.countDown();
    };

    Stopper stopper = () -> {
      throw new UnsupportedOperationException("stopping not supported while unit testing");
    };

    ResponseTransmitter responseTransmitter = new ResponseTransmitter() {
      @Override
      public void transmit(HttpResponseStatus status, ByteBuf byteBuf) {
        sentResponse = true;
        body = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(body);
        byteBuf.release();
        eventController.fire(new DefaultRequestOutcome(request, new DefaultSentResponse(headers, new DefaultStatus(status)), System.currentTimeMillis()));
        latch.countDown();
      }

      @Override
      public void transmit(HttpResponseStatus responseStatus, BasicFileAttributes basicFileAttributes, Path file) {
        sentFile = file;
        eventController.fire(new DefaultRequestOutcome(request, new DefaultSentResponse(headers, status), System.currentTimeMillis()));
        latch.countDown();
      }

      @Override
      public Subscriber<ByteBuf> transmitter(HttpResponseStatus status) {
        throw new UnsupportedOperationException("streaming not supported while unit testing");
      }
    };

    ExecControl execControl = launchConfig.getExecController().getControl();
    Registry baseRegistry = NettyHandlerAdapter.buildBaseRegistry(stopper, launchConfig);
    Registry effectiveRegistry = baseRegistry.join(userRegistry);
    Response response = new DefaultResponse(execControl, responseHeaders, launchConfig.getBufferAllocator(), responseTransmitter);
    DefaultContext.ApplicationConstants applicationConstants = new DefaultContext.ApplicationConstants(launchConfig, renderController, next);
    requestConstants = new DefaultContext.RequestConstants(
      applicationConstants, bindAddress, request, response, null, eventController.getRegistry()
    );
View Full Code Here


  }

  @Override
  public HandlingResult handleChain(Action<? super Chain> chainAction) throws Exception {
    LaunchConfig launchConfig = launchConfigBuilder.build();
    Registry registry = registryBuilder.build();
    Handler handler = Handlers.chain(launchConfig, registry, chainAction);
    return invoke(handler, launchConfig, registry);
  }
View Full Code Here

      if (module instanceof HandlerDecoratingModule) {
        handler = ((HandlerDecoratingModule) module).decorate(injector, handler);
      }
    }

    Registry registry = Guice.registry(injector);
    return Handlers.chain(Handlers.register(registry), handler);
  }
View Full Code Here

  }

  private class InsertHandler implements Handler {
    @Override
    public void handle(Context context) throws Exception {
      Registry registryInjection = registryReference.get();
      if (registryInjection == null) {
        rest.handle(context);
      } else {
        context.insert(registryInjection, rest);
      }
View Full Code Here

  }

  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

    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

    this.launchConfig = launchConfig;
    this.closure = closure;
  }

  public Handler apply(Injector injector) throws Exception {
    final Registry registry = Guice.justInTimeRegistry(injector);
    return Groovy.chain(launchConfig, registry, closure);
  }
View Full Code Here

    return LaunchConfigsInternal.determineBaseDir(configPath);
  }

  @Override
  public LaunchConfig build(ConfigurationSource configurationSource, Configuration configuration) {
    Registry defaultRegistry = Registries.registry().add(Configuration.class, configuration).add(configuration).build();
    HandlerFactory handlerFactory;
    Verify.verifyNotNull(handlerFactoryClass);
    try {
      handlerFactory = handlerFactoryClass.newInstance();
    } catch (Exception e) {
View Full Code Here

    return this;
  }

  private <T, N> void doInit(final Closure<T> closure, final Class<N> clazz, final int resolveStrategy) {
    init(injector -> {
      Registry injectorBackedRegistry = Guice.registry(injector);
      N delegate = clazz.equals(Void.class) ? null : injector.getInstance(clazz);
      new ClosureInvoker<T, N>(closure).invoke(injectorBackedRegistry, delegate, resolveStrategy);
    });
  }
View Full Code Here

TOP

Related Classes of ratpack.registry.Registry

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.