コード例 #1
0
  @Override
  public Continuation apply(final ContainerRequest request) {
    final RoutingContext routingCtx = injector.inject(RoutingContext.class);

    Object subResource = getResource(routingCtx);
    if (subResource == null) {
      throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    if (subResource.getClass().isAssignableFrom(Class.class)) {
      final Class<?> clazz = (Class<?>) subResource;
      SingletonResourceBinder singletonResourceFactory =
          injector.inject(SingletonResourceBinder.class);
      singletonResourceFactory.bindResourceClassAsSingleton(clazz);
      subResource = injector.inject(clazz);
    }

    // TODO: what to do with the issues?
    final Resource subResourceModel =
        Resource.builder(subResource, new LinkedList<ResourceModelIssue>()).build();
    runtimeModelBuilder.process(subResourceModel, true);

    // TODO: implement generated sub-resource methodAcceptorPair caching
    routingCtx.pushMatchedResource(subResource);
    Router subResourceAcceptor = runtimeModelBuilder.buildModel(true);
    return Continuation.of(request, subResourceAcceptor);
  }
コード例 #2
0
    @Override
    public Response apply(final Request req) {
      i.inject(this);
      // Suspend current request
      invocationContext.suspend();

      Executors.newSingleThreadExecutor()
          .submit(
              new Runnable() {

                @Override
                public void run() {
                  try {
                    Thread.sleep(500);
                  } catch (InterruptedException ex) {
                    ex.printStackTrace(System.err);
                  }

                  // Returning will enter the suspended request
                  invocationContext.resume(Responses.from(200, req).entity("B").build());
                }
              });

      return null;
    }
コード例 #3
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);
  }