コード例 #1
0
  @Before
  public void setupApplication() {
    Services services = HK2.get().create(null, new ServerModule());

    final Ref<ServiceProviders> providers =
        services.forContract(new TypeLiteral<Ref<ServiceProviders>>() {}).get();
    providers.set(services.forContract(ServiceProviders.Builder.class).get().build());
    final Ref<MessageBodyWorkers> workers =
        services.forContract(new TypeLiteral<Ref<MessageBodyWorkers>>() {}).get();
    workers.set(new MessageBodyFactory(providers.get()));
    final Ref<ExceptionMappers> mappers =
        services.forContract(new TypeLiteral<Ref<ExceptionMappers>>() {}).get();
    mappers.set(new ExceptionMapperFactory(providers.get()));

    Injector injector = services.forContract(Injector.class).get();
    injector.inject(this);

    final InvokerBuilder invokerBuilder = injector.inject(InvokerBuilder.class);
    this.invoker =
        invokerBuilder.build(
            routeBuilder.root(
                routeBuilder
                    .route("a(/.*)?")
                    .to(LastPathSegmentTracingFilter.class)
                    .to(
                        routeBuilder
                            .route("b(/.*)?")
                            .to(LastPathSegmentTracingFilter.class)
                            .to(
                                routeBuilder
                                    .route("c(/)?")
                                    .to(LastPathSegmentTracingFilter.class)
                                    .to(Routers.asTreeAcceptor(new AsyncInflector(injector))))
                            .to(
                                routeBuilder
                                    .route("d(/)?")
                                    .to(LastPathSegmentTracingFilter.class)
                                    .to(Routers.asTreeAcceptor(new AsyncInflector(injector)))))
                    .build()));
    this.requestScope = injector.inject(RequestScope.class);
  }
コード例 #2
0
  private Router createSingleMethodAcceptor(
      final ResourceMethod resourceMethod, final boolean subResourceMode) {
    Router methodAcceptor = null;
    switch (resourceMethod.getType()) {
      case RESOURCE_METHOD:
      case SUB_RESOURCE_METHOD:
        methodAcceptor = Routers.asTreeAcceptor(createInflector(resourceMethod));
        break;
      case SUB_RESOURCE_LOCATOR:
        methodAcceptor = new SubResourceLocatorRouter(locator, this, resourceMethod);
        break;
    }

    // TODO: solve this via instance-based method handler model?
    if (subResourceMode) {
      return methodAcceptor;
    } else {
      return pushHandlerAcceptorBuilder.build(
          resourceMethod.getInvocable().getHandler(), methodAcceptor);
    }
  }