@Provides public Application createJaxRsApplication(@JaxrsResource Set<Object> jaxRsSingletons, @JaxrsResource Set<JaxrsBinding> jaxrsBinding, Injector injector) { // detect jax-rs services that are bound into Guice, but not explicitly exported Set<Key<?>> missingBindings = new HashSet<>(); ImmutableSet.Builder<Object> singletons = ImmutableSet.builder(); singletons.addAll(jaxRsSingletons); while (injector != null) { for (Entry<Key<?>, Binding<?>> entry : injector.getBindings().entrySet()) { Key<?> key = entry.getKey(); if (isJaxRsBinding(key) && !jaxrsBinding.contains(new JaxrsBinding(key))) { if (requireExplicitBindings) { missingBindings.add(key); } else { log.warn("Jax-rs service %s is not explicitly bound using the JaxrsBinder", key); Object jaxRsSingleton = entry.getValue().getProvider().get(); singletons.add(jaxRsSingleton); } } } injector = injector.getParent(); } checkState(!requireExplicitBindings || missingBindings.isEmpty(), "Jax-rs services must be explicitly bound using the JaxRsBinder: ", missingBindings); return new JaxRsApplication(singletons.build()); }
@Provides public Application createJaxRsApplication(@JaxrsResource Set<Object> jaxRsSingletons, @JaxrsResource Set<JaxrsBinding> jaxrsBinding, Injector injector) { // detect jax-rs services that are bound into Guice, but not explicitly exported Set<Key<?>> missingBindings = new HashSet<>(); ImmutableSet.Builder<Object> singletons = ImmutableSet.builder(); singletons.addAll(jaxRsSingletons); while (injector != null) { for (Entry<Key<?>, Binding<?>> entry : injector.getBindings().entrySet()) { Key<?> key = entry.getKey(); if (isJaxRsBinding(key) && !jaxrsBinding.contains(new JaxrsBinding(key))) { if (requireExplicitBindings) { missingBindings.add(key); } else { log.warn("Jax-rs service %s is not explicitly bound using the JaxrsBinder", key); Object jaxRsSingleton = entry.getValue().getProvider().get(); singletons.add(jaxRsSingleton); } } } injector = injector.getParent(); } checkState(!requireExplicitBindings || missingBindings.isEmpty(), "Jax-rs services must be explicitly bound using the JaxRsBinder: ", missingBindings); return new JaxRsApplication(singletons.build()); }