org.glassfish.jersey.process.internal.RequestScoped Java Examples

The following examples show how to use org.glassfish.jersey.process.internal.RequestScoped. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceTalkFeature.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(final FeatureContext context) {
    if (!context.getConfiguration().isRegistered(EndpointEnhancingRequestFilter.class)) {
        context.register(BufferMessageBodyReaderWriter.class);
        context.register(BufferPublisherMessageBodyReaderWriter.class);
        context.register(BufferSingleMessageBodyReaderWriter.class);
        context.register(EndpointEnhancingRequestFilter.class);

        context.register(new AbstractBinder() {
            @Override
            protected void configure() {
                bindFactory(ConnectionContextReferencingFactory.class).to(ConnectionContext.class)
                        .proxy(true).proxyForSameScope(true).in(RequestScoped.class);
                bindFactory(referenceFactory()).to(CONNECTION_CONTEXT_REF_GENERIC_TYPE).in(RequestScoped.class);

                bindFactory(HttpRequestReferencingFactory.class).to(HTTP_REQUEST_GENERIC_TYPE)
                        .proxy(true).proxyForSameScope(false).in(RequestScoped.class);
                bindFactory(referenceFactory()).to(HTTP_REQUEST_REF_GENERIC_TYPE).in(RequestScoped.class);
            }
        });
    }

    return true;
}
 
Example #2
Source File: JooqBinder.java    From droptools with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    // bind default Configuration to DSLContext
    bindFactory(new DSLContextFactory(configurationMap.values().stream().findFirst().orElse(null)))
            .to(DSLContext.class)
            .in(RequestScoped.class);

    // bind multiple instances of Configuration and ConnectionProvider for Named DSLContext(s)
    for (final Configuration configuration : configurationMap.values()) {

        bind(configuration).to(Configuration.class);

        bind(configuration.connectionProvider())
                .to(ConnectionProvider.class);
    }

    // bind a ValueParamProvider for Named DSLContext(s)
    bind(new DSLContextValueParamProvider(configurationMap))
            .to(ValueParamProvider.class);
}
 
Example #3
Source File: JerseyApplication.java    From katharsis-framework with Apache License 2.0 6 votes vote down vote up
public JerseyApplication() {
    property(KatharsisProperties.RESOURCE_SEARCH_PACKAGE, "io.katharsis.example.jersey.domain");
    property(KatharsisProperties.RESOURCE_DEFAULT_DOMAIN, APPLICATION_URL);
    register(KatharsisDynamicFeature.class);
    register(new AbstractBinder() {
        @Override
        public void configure() {
            bindFactory(ObjectMapperFactory.class).to(ObjectMapper.class).in(Singleton.class);
            bindService(TaskRepository.class);
            bindService(ProjectRepository.class);
            bindService(TaskToProjectRepository.class);
        }

        private void bindService(Class<?> serviceType) {
            bind(serviceType).to(serviceType).proxy(true).in(RequestScoped.class);
        }
    });

}
 
Example #4
Source File: AbstractReferencingBinder.java    From jrestless with Apache License 2.0 5 votes vote down vote up
/**
 * Binds the referencingFactory to the referenceType in the request scope
 * and allows proxying the reference type but not for the same scope.
 * <p>
 * It also binds a referencing factory to the referenceTypeLiteral in the
 * requestScope.
 *
 * @param referenceType
 * @param referencingFacatory
 * @param referenceTypeLiteral
 */
public final <T> void bindReferencingFactory(Class<T> referenceType,
		Class<? extends ReferencingFactory<T>> referencingFacatory, GenericType<Ref<T>> referenceTypeLiteral) {
	bindFactory(referencingFacatory)
		.to(referenceType)
		.proxy(true)
		.proxyForSameScope(false)
		.in(RequestScoped.class);
	bindFactory(ReferencingFactory.<T>referenceFactory())
		.to(referenceTypeLiteral)
		.in(RequestScoped.class);
}
 
Example #5
Source File: JedisPoolBinder.java    From droptools with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    // Always return the same pool when/where ever it's asked for
    bind(pool).to(JedisPool.class);

    bindFactory(new JedisFactory(pool))
            .to(Jedis.class)
            .in(RequestScoped.class);
}
 
Example #6
Source File: WebSocketAddon.java    From ameba with MIT License 5 votes vote down vote up
private Class<? extends Annotation> getScope(final Class<?> clazz) {
    Class<? extends Annotation> hk2Scope = RequestScoped.class;
    if (clazz.isAnnotationPresent(Singleton.class)) {
        hk2Scope = Singleton.class;
    } else if (clazz.isAnnotationPresent(PerLookup.class)) {
        hk2Scope = PerLookup.class;
    }
    return hk2Scope;
}
 
Example #7
Source File: LinkFactoryResourceConfig.java    From rest-schemagen with Apache License 2.0 5 votes vote down vote up
private static void bindDefaultPlugins(ResourceConfig config) {
    config.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(MethodCheckerForLinkFactory.class)
                    .to(MethodCheckerForLink.class)
                    .in(RequestScoped.class)
                    .proxy(true);
            bindFactory(FieldCheckerForSchemaFactory.class, Singleton.class).to(FieldCheckerForSchema.class).in(
                    Singleton.class);
        }
    });
}
 
Example #8
Source File: LinkFactoryResourceConfig.java    From rest-schemagen with Apache License 2.0 5 votes vote down vote up
public static void configureWithoutPlugins(ResourceConfig config) {
    config.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(RestJsonSchemaGeneratorFactory.class, Singleton.class).to(JsonSchemaGenerator.class).in(
                    Singleton.class);
            bind(BaseUriCreatorDefault.class).to(BaseUriCreator.class).in(Singleton.class);
            bindFactory(LinkFactoryContextFactory.class).to(LinkFactoryContext.class).in(RequestScoped.class).proxy(
                    true);
            bindFactory(LinkMetaFactoryFactory.class).to(LinkMetaFactory.class);
        }
    });

}
 
Example #9
Source File: InstanceFactoryDefinitionTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@Test
public void testPreconditions() throws NoSuchMethodException, SecurityException {
	new ConstructorPreconditionsTester(
			InstanceFactoryDefinition.class.getDeclaredConstructor(Object.class, Class.class, Class.class))
		.addValidArgs(0, "String")
		.addInvalidNpeArg(0)
		.addValidArgs(1, String.class)
		.addInvalidNpeArg(1)
		.addValidArgs(2, RequestScoped.class)
		.addInvalidNpeArg(2)
		.testPreconditionsAndValidCombinations();
}
 
Example #10
Source File: InstanceFactoryDefinitionTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetters() {
	SomeObject instance = mock(SomeObject.class);
	InstanceFactoryDefinition<SomeObject> instanceFactory = new InstanceFactoryDefinition<>(instance,
			SomeObject.class, RequestScoped.class);
	assertSame(instance, instanceFactory.getInstanceFactory().get());
	assertEquals(SomeObject.class, instanceFactory.getType());
	assertEquals(RequestScoped.class, instanceFactory.getScope());
}
 
Example #11
Source File: JerseyLambdaContainerHandler.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
/**
 * Private constructor for a LambdaContainer. Sets the application object, sets the ApplicationHandler,
 * and initializes the application using the <code>onStartup</code> method.
 * @param requestTypeClass The class for the expected event type
 * @param responseTypeClass The class for the output type
 * @param requestReader A request reader instance
 * @param responseWriter A response writer instance
 * @param securityContextWriter A security context writer object
 * @param exceptionHandler An exception handler
 * @param jaxRsApplication The JaxRs application
 */
public JerseyLambdaContainerHandler(Class<RequestType> requestTypeClass,
                                    Class<ResponseType> responseTypeClass,
                                    RequestReader<RequestType, HttpServletRequest> requestReader,
                                    ResponseWriter<AwsHttpServletResponse, ResponseType> responseWriter,
                                    SecurityContextWriter<RequestType> securityContextWriter,
                                    ExceptionHandler<ResponseType> exceptionHandler,
                                    Application jaxRsApplication) {

    super(requestTypeClass, responseTypeClass, requestReader, responseWriter, securityContextWriter, exceptionHandler);
    Timer.start("JERSEY_CONTAINER_CONSTRUCTOR");
    initialized = false;
    if (jaxRsApplication instanceof ResourceConfig) {
        ((ResourceConfig)jaxRsApplication).register(new AbstractBinder() {
            @Override
            protected void configure() {
                bindFactory(AwsProxyServletContextSupplier.class)
                        .proxy(true)
                        .proxyForSameScope(true)
                        .to(ServletContext.class)
                        .in(RequestScoped.class);
                bindFactory(AwsProxyServletRequestSupplier.class)
                        .proxy(true)
                        .proxyForSameScope(true)
                        .to(HttpServletRequest.class)
                        .in(RequestScoped.class);
                bindFactory(AwsProxyServletResponseSupplier.class)
                        .proxy(true)
                        .proxyForSameScope(true)
                        .to(HttpServletResponse.class)
                        .in(RequestScoped.class);
            }
        });
    }

    this.jerseyFilter = new JerseyHandlerFilter(jaxRsApplication);
    Timer.stop("JERSEY_CONTAINER_CONSTRUCTOR");
}
 
Example #12
Source File: ApplicationConfig.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    bindFactory(this).to(HugeConfig.class).in(RequestScoped.class);
}
 
Example #13
Source File: ApplicationConfig.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    bindFactory(this).to(GraphManager.class).in(RequestScoped.class);
}
 
Example #14
Source File: DremioBinder.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
protected void bindReflectionFactory() {
  bindFactory(ReflectionAdministrationServiceFactory.class).proxy(true).in(RequestScoped.class).to(ReflectionAdministrationService.class);
}
 
Example #15
Source File: DremioBinder.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {
  for(Binding b : bindings){
    switch(b.getType()){
    case INSTANCE:
      InstanceBinding ib = (InstanceBinding) b;
      if(ib.getInstance().getAnnotation(RequestScoped.class) != null){
        bind(ib.getInstance()).in(RequestScoped.class).to(b.getIface());
      }else{
        bind(ib.getInstance()).to(b.getIface());
      }
      break;
    case SINGLETON:
      SingletonBinding sb = (SingletonBinding) b;
      bind(sb.getSingleton()).to(b.getIface());
      break;
    case PROVIDER:
      BinderImpl.ProviderBinding pb = (BinderImpl.ProviderBinding) b;
      bindFactory(() -> pb.getProvider().get()).to(b.getIface());
      break;
    default:
      throw new IllegalStateException();
    }
  }

  bindToSelf(QueryExecutor.class);
  bindToSelf(SampleDataPopulator.class);
  bindToSelf(DatasetVersionMutator.class);
  bindToSelf(SourceService.class);
  bindToSelf(ReflectionServiceHelper.class);
  bindToSelf(CatalogServiceHelper.class);
  bindToSelf(CollaborationHelper.class);
  bindToSelf(FormatTools.class);
  bindFactory(OptionManagerFactory.class).to(OptionManager.class);
  bind(JobsBasedRecommender.class).to(JoinRecommender.class);
  bind(DACSecurityContext.class).in(RequestScoped.class).to(SecurityContext.class);
  bindFactory(CatalogFactory.class).proxy(true).in(RequestScoped.class).to(Catalog.class);
  bindFactory(CatalogFactory.class).proxy(true).in(RequestScoped.class).to(EntityExplorer.class);
  bindFactory(CatalogFactory.class).proxy(true).in(RequestScoped.class).to(DatasetCatalog.class);
  bindFactory(CatalogFactory.class).proxy(true).in(RequestScoped.class).to(SourceCatalog.class);
  bindReflectionFactory();
}
 
Example #16
Source File: WebConfigImpl.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public <T> WebConfig bind(Class<T> contextClass, Provider<T> provider) {
    binder.bind(contextClass).toProvider(provider).in(RequestScoped.class);
    return this;
}
 
Example #17
Source File: WebConfigImpl.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public <T> WebConfig bind(Class<T> contextClass, Class<? extends Provider<T>> providerClass) {
    binder.bind(contextClass).toProvider(providerClass).in(RequestScoped.class);
    return this;
}
 
Example #18
Source File: PaginationInfoInjectorBinder.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  bindFactory(PaginationInfoInjector.class).to(PaginationInfo.class).in(RequestScoped.class);
}
 
Example #19
Source File: WebConfigImpl.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public <T> WebConfig controller(Class<T> controllerClass) {
    binder.bind(controllerClass).in(RequestScoped.class);
    app.register(controllerClass);
    return this;
}
 
Example #20
Source File: DrillRestServer.java    From Bats with Apache License 2.0 4 votes vote down vote up
@RequestScoped
@Override
public DrillUserPrincipal provide() {
  return new AnonDrillUserPrincipal();
}
 
Example #21
Source File: ApplicationConfig.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    bindFactory(this).to(WorkLoad.class).in(RequestScoped.class);
}
 
Example #22
Source File: InstanceBinder.java    From jrestless with Apache License 2.0 2 votes vote down vote up
/**
 * Add a request-scoped instance for the given type.
 *
 * @param instance
 * @param type
 * @return
 */
public <T> Builder addInstance(T instance, Class<T> type) {
	return addInstance(instance, type, RequestScoped.class);
}