javax.enterprise.inject.Instance Java Examples
The following examples show how to use
javax.enterprise.inject.Instance.
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: CacheGrant.java From oxAuth with MIT License | 6 votes |
public AuthorizationCodeGrant asCodeGrant(Instance<AbstractAuthorizationGrant> grantInstance) { AuthorizationCodeGrant grant = grantInstance.select(AuthorizationCodeGrant.class).get(); grant.init(user, client, authenticationTime); grant.setAuthorizationCode(new AuthorizationCode(authorizationCodeString, authorizationCodeCreationDate, authorizationCodeExpirationDate)); grant.setScopes(scopes); grant.setGrantId(grantId); grant.setSessionDn(sessionDn); grant.setCodeChallenge(codeChallenge); grant.setCodeChallengeMethod(codeChallengeMethod); grant.setAcrValues(acrValues); grant.setNonce(nonce); grant.setClaims(claims); return grant; }
Example #2
Source File: VertxRequestHandler.java From quarkus with Apache License 2.0 | 6 votes |
public VertxRequestHandler(Vertx vertx, BeanContainer beanContainer, String rootPath, Executor executor) { this.vertx = vertx; this.beanContainer = beanContainer; // make sure rootPath ends with "/" for easy parsing if (rootPath == null) { this.rootPath = "/"; } else if (!rootPath.endsWith("/")) { this.rootPath = rootPath + "/"; } else { this.rootPath = rootPath; } this.executor = executor; Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class); this.association = association.isResolvable() ? association.get() : null; currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get(); }
Example #3
Source File: KafkaStreamsTopologyManager.java From quarkus with Apache License 2.0 | 6 votes |
@Inject public KafkaStreamsTopologyManager(Instance<Topology> topology, Instance<KafkaClientSupplier> kafkaClientSupplier, Instance<StateListener> stateListener, Instance<StateRestoreListener> globalStateRestoreListener) { // No producer for Topology -> nothing to do if (topology.isUnsatisfied()) { LOGGER.debug("No Topology producer; Kafka Streams will not be started"); this.executor = null; return; } this.executor = Executors.newSingleThreadExecutor(); this.topology = topology; this.kafkaClientSupplier = kafkaClientSupplier; this.stateListener = stateListener; this.globalStateRestoreListener = globalStateRestoreListener; }
Example #4
Source File: CacheGrant.java From oxAuth with MIT License | 6 votes |
public CIBAGrant asCibaGrant(Instance<AbstractAuthorizationGrant> grantInstance) { CIBAGrant grant = grantInstance.select(CIBAGrant.class).get(); grant.init(user, AuthorizationGrantType.CIBA, client, authenticationTime); grant.setScopes(scopes); grant.setGrantId(grantId); grant.setSessionDn(sessionDn); grant.setCodeChallenge(codeChallenge); grant.setCodeChallengeMethod(codeChallengeMethod); grant.setAcrValues(acrValues); grant.setNonce(nonce); grant.setClaims(claims); grant.setAuthReqId(authReqId); grant.setTokensDelivered(tokensDelivered); return grant; }
Example #5
Source File: SmallRyeJWTAuthCDIExtension.java From smallrye-jwt with Apache License 2.0 | 6 votes |
public static boolean isHttpAuthMechanismEnabled() { boolean enabled = false; if (isEESecurityAvailable()) { Instance<JWTHttpAuthenticationMechanism> instance; try { instance = CDI.current().select(JWTHttpAuthenticationMechanism.class); enabled = instance.isResolvable(); } catch (@SuppressWarnings("unused") Exception e) { //Ignore exceptions, consider HTTP authentication mechanism to be disabled } } return enabled; }
Example #6
Source File: VertxRequestHandler.java From quarkus with Apache License 2.0 | 6 votes |
public VertxRequestHandler(Vertx vertx, BeanContainer beanContainer, ObjectMapper mapper, FunqyKnativeEventsConfig config, FunctionInvoker defaultInvoker, Map<String, FunctionInvoker> typeTriggers, Executor executor) { this.defaultInvoker = defaultInvoker; this.vertx = vertx; this.beanContainer = beanContainer; this.executor = executor; this.mapper = mapper; this.typeTriggers = typeTriggers; Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class); this.association = association.isResolvable() ? association.get() : null; Instance<IdentityProviderManager> identityProviderManager = CDI.current().select(IdentityProviderManager.class); this.currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get(); }
Example #7
Source File: AuthenticationProviderFactory.java From pnc with Apache License 2.0 | 6 votes |
@Inject public AuthenticationProviderFactory( @AuthProvider Instance<AuthenticationProvider> providers, Configuration configuration) throws CoreException { AtomicReference<String> providerId = new AtomicReference<>(null); try { providerId.set( configuration.getModuleConfig(new PncConfigProvider<>(SystemConfig.class)) .getAuthenticationProviderId()); } catch (ConfigurationParseException e) { logger.warn("Unable parse config. Using default scheduler"); providerId.set(DEFAULT_AUTHENTICATION_PROVIDER_ID); } providers.forEach(provider -> setMatchingProvider(provider, providerId.get())); if (authenticationProvider == null) { throw new CoreException( "Cannot get AuthenticationProvider, check configurations and make sure a provider with configured id is available for injection. configured id: " + providerId); } }
Example #8
Source File: DataSources.java From quarkus with Apache License 2.0 | 6 votes |
public DataSources(DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, DataSourcesRuntimeConfig dataSourcesRuntimeConfig, DataSourcesJdbcBuildTimeConfig dataSourcesJdbcBuildTimeConfig, DataSourcesJdbcRuntimeConfig dataSourcesJdbcRuntimeConfig, LegacyDataSourcesJdbcBuildTimeConfig legacyDataSourcesJdbcBuildTimeConfig, LegacyDataSourcesRuntimeConfig legacyDataSourcesRuntimeConfig, LegacyDataSourcesJdbcRuntimeConfig legacyDataSourcesJdbcRuntimeConfig, TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry, DataSourceSupport dataSourceSupport, @Any Instance<AgroalPoolInterceptor> agroalPoolInterceptors) { this.dataSourcesBuildTimeConfig = dataSourcesBuildTimeConfig; this.dataSourcesRuntimeConfig = dataSourcesRuntimeConfig; this.dataSourcesJdbcBuildTimeConfig = dataSourcesJdbcBuildTimeConfig; this.dataSourcesJdbcRuntimeConfig = dataSourcesJdbcRuntimeConfig; this.legacyDataSourcesJdbcBuildTimeConfig = legacyDataSourcesJdbcBuildTimeConfig; this.legacyDataSourcesRuntimeConfig = legacyDataSourcesRuntimeConfig; this.legacyDataSourcesJdbcRuntimeConfig = legacyDataSourcesJdbcRuntimeConfig; this.transactionManager = transactionManager; this.transactionSynchronizationRegistry = transactionSynchronizationRegistry; this.dataSourceSupport = dataSourceSupport; this.agroalPoolInterceptors = agroalPoolInterceptors; }
Example #9
Source File: BuildSchedulerFactory.java From pnc with Apache License 2.0 | 6 votes |
@Inject public BuildSchedulerFactory(Instance<BuildScheduler> availableSchedulers, Configuration configuration) throws CoreException { AtomicReference<String> schedulerId = new AtomicReference<>(null); try { schedulerId.set( configuration.getModuleConfig(new PncConfigProvider<>(SystemConfig.class)).getBuildSchedulerId()); } catch (ConfigurationParseException e) { logger.warn("Unable parse config. Using default scheduler"); schedulerId.set(DEFAULT_SCHEDULER_ID); } availableSchedulers.forEach(scheduler -> setMatchingScheduler(scheduler, schedulerId.get())); if (configuredBuildScheduler == null) { throw new CoreException( "Cannot get BuildScheduler, check configurations and make sure a scheduler with configured id is available for injection. configured id: " + schedulerId); } }
Example #10
Source File: JsfRequestLifecycleBroadcaster.java From deltaspike with Apache License 2.0 | 6 votes |
@Inject protected JsfRequestLifecycleBroadcaster(Instance<PhaseListener> phaseListenerInstance) { Class phaseListenerClass; for (PhaseListener currentPhaseListener : phaseListenerInstance) { phaseListenerClass = ProxyUtils.getUnproxiedClass(currentPhaseListener.getClass()); if (phaseListenerClass.isAnnotationPresent(JsfPhaseListener.class)) { if (Deactivatable.class.isAssignableFrom(phaseListenerClass) && !ClassDeactivationUtils.isActivated(phaseListenerClass)) { continue; } this.phaseListeners.add(currentPhaseListener); } } //higher ordinals first sortDescending(this.phaseListeners); }
Example #11
Source File: CDIContextTest.java From microprofile-context-propagation with Apache License 2.0 | 6 votes |
/** * Set some state on a request scoped bean, then verify a contextualized callable * has the state cleared from it when ran on the same thread. * * @throws Exception indicates test failure */ @Test public void testCDITCCtxClear() throws Exception { ThreadContext clearAllCtx = ThreadContext.builder() .propagated() // propagate nothing .cleared(ThreadContext.ALL_REMAINING) .unchanged() .build(); Instance<RequestScopedBean> selectedInstance = instance.select(RequestScopedBean.class); assertTrue(selectedInstance.isResolvable()); RequestScopedBean requestBean = selectedInstance.get(); requestBean.setState("testCDIThreadCtxClear-STATE1"); Callable<String> getState = clearAllCtx.contextualCallable(() -> { String state = requestBean.getState(); return state; }); assertEquals(getState.call(), "UNINITIALIZED"); }
Example #12
Source File: CDIContextTest.java From microprofile-context-propagation with Apache License 2.0 | 6 votes |
/** * Set some state on Conversation scoped bean and verify * the state is cleared on the thread where the other task runs. * * If the CDI context in question is not active, the test is deemed successful as there is no propagation to be done. * * @throws Exception indicates test failure */ @Test public void testCDIMECtxClearsConversationScopedBeans() throws Exception { // check if given context is active, if it isn't test ends successfully try { bm.getContext(ConversationScoped.class); } catch (ContextNotActiveException e) { return; } ManagedExecutor propagatedNone = ManagedExecutor.builder() .propagated() // none .cleared(ThreadContext.ALL_REMAINING) .build(); Instance<ConversationScopedBean> selectedInstance = instance.select(ConversationScopedBean.class); assertTrue(selectedInstance.isResolvable()); try { checkCDIPropagation(false, "testCDI_ME_Ctx_Clear-CONVERSATION", propagatedNone, selectedInstance.get()); } finally { propagatedNone.shutdown(); } }
Example #13
Source File: CDIContextTest.java From microprofile-context-propagation with Apache License 2.0 | 6 votes |
/** * Set some state on Session scoped bean and verify * the state is cleared on the thread where the other task runs. * * If the CDI context in question is not active, the test is deemed successful as there is no propagation to be done. * * @throws Exception indicates test failure */ @Test public void testCDIMECtxClearsSessionScopedBeans() throws Exception { // check if given context is active, if it isn't test ends successfully try { bm.getContext(SessionScoped.class); } catch (ContextNotActiveException e) { return; } ManagedExecutor propagatedNone = ManagedExecutor.builder() .propagated() // none .cleared(ThreadContext.ALL_REMAINING) .build(); Instance<SessionScopedBean> selectedInstance = instance.select(SessionScopedBean.class); assertTrue(selectedInstance.isResolvable()); try { checkCDIPropagation(false, "testCDI_ME_Ctx_Clear-SESSION", propagatedNone, selectedInstance.get()); } finally { propagatedNone.shutdown(); } }
Example #14
Source File: CDIContextTest.java From microprofile-context-propagation with Apache License 2.0 | 6 votes |
/** * Set some state on Session scoped bean and verify * the state is propagated to the thread where the other task runs. * * If the CDI context in question is not active, the test is deemed successful as there is no propagation to be done. * * @throws Exception indicates test failure */ @Test public void testCDIMECtxPropagatesSessionScopedBean() throws Exception { // check if given context is active, if it isn't test ends successfully try { bm.getContext(SessionScoped.class); } catch (ContextNotActiveException e) { return; } ManagedExecutor propagateCDI = ManagedExecutor.builder().propagated(ThreadContext.CDI) .cleared(ThreadContext.ALL_REMAINING) .build(); Instance<SessionScopedBean> selectedInstance = instance.select(SessionScopedBean.class); assertTrue(selectedInstance.isResolvable()); try { checkCDIPropagation(true, "testCDI_ME_Ctx_Propagate-SESSION", propagateCDI, selectedInstance.get()); } finally { propagateCDI.shutdown(); } }
Example #15
Source File: CDIContextTest.java From microprofile-context-propagation with Apache License 2.0 | 6 votes |
/** * Set some state on Request scoped bean and verify * the state is propagated to the thread where the other task runs. * * If the CDI context in question is not active, the test is deemed successful as there is no propagation to be done. * * @throws Exception indicates test failure */ @Test public void testCDIMECtxPropagatesRequestScopedBean() throws Exception { // check if given context is active, if it isn't test ends successfully try { bm.getContext(RequestScoped.class); } catch (ContextNotActiveException e) { return; } ManagedExecutor propagateCDI = ManagedExecutor.builder().propagated(ThreadContext.CDI) .cleared(ThreadContext.ALL_REMAINING) .build(); Instance<RequestScopedBean> selectedInstance = instance.select(RequestScopedBean.class); assertTrue(selectedInstance.isResolvable()); try { checkCDIPropagation(true, "testCDI_ME_Ctx_Propagate-REQUEST", propagateCDI, selectedInstance.get()); } finally { propagateCDI.shutdown(); } }
Example #16
Source File: DisposerTest.java From quarkus with Apache License 2.0 | 5 votes |
void dipose(@Disposes Long value, @MyQualifier String injectedString, Instance<Pong> pongs) { assertNotNull(injectedString); DISPOSED.set(value); pongs.forEach(p -> { assertEquals("OK", p.id); }); }
Example #17
Source File: VertxClientCertificateLookup.java From keycloak with Apache License 2.0 | 5 votes |
@Override public X509Certificate[] getCertificateChain(HttpRequest httpRequest) { Instance<RoutingContext> instances = CDI.current().select(RoutingContext.class); if (instances.isResolvable()) { RoutingContext context = instances.get(); try { SSLSession sslSession = context.request().sslSession(); if (sslSession == null) { return null; } X509Certificate[] certificates = (X509Certificate[]) sslSession.getPeerCertificates(); if (logger.isTraceEnabled() && certificates != null) { for (X509Certificate cert : certificates) { logger.tracef("Certificate's SubjectDN => \"%s\"", cert.getSubjectDN().getName()); } } return certificates; } catch (SSLPeerUnverifiedException ignore) { // client not authenticated } } return null; }
Example #18
Source File: InterceptorExecutor.java From vraptor4 with Apache License 2.0 | 5 votes |
@Inject public InterceptorExecutor(StepInvoker stepInvoker, InterceptorMethodParametersResolver parametersResolver, Instance<SimpleInterceptorStack> simpleInterceptorStack) { this.stepInvoker = stepInvoker; this.parametersResolver = parametersResolver; this.simpleInterceptorStack = simpleInterceptorStack; }
Example #19
Source File: QuarkusJpaConnectionProviderFactory.java From keycloak with Apache License 2.0 | 5 votes |
private void lazyInit() { Instance<EntityManagerFactory> instance = CDI.current().select(EntityManagerFactory.class); if (!instance.isResolvable()) { throw new RuntimeException("Failed to resolve " + EntityManagerFactory.class + " from Quarkus runtime"); } emf = instance.get(); try (Connection connection = getConnection()) { if (jtaEnabled) { KeycloakModelUtils.suspendJtaTransaction(factory, () -> { KeycloakSession session = factory.create(); try { migration(getSchema(), connection, session); } finally { session.close(); } }); } else { KeycloakModelUtils.runJobInTransaction(factory, session -> { migration(getSchema(), connection, session); }); } prepareOperationalInfo(connection); } catch (SQLException cause) { throw new RuntimeException("Failed to migrate model", cause); } }
Example #20
Source File: HttpAuthorizer.java From quarkus with Apache License 2.0 | 5 votes |
@Inject HttpAuthorizer(Instance<HttpSecurityPolicy> installedPolicies) { policies = new ArrayList<>(); for (HttpSecurityPolicy i : installedPolicies) { policies.add(i); } }
Example #21
Source File: SmallRyeGraphQLRecorder.java From quarkus with Apache License 2.0 | 5 votes |
public Handler<RoutingContext> executionHandler(boolean allowGet) { Instance<CurrentIdentityAssociation> identityAssociations = CDI.current() .select(CurrentIdentityAssociation.class); CurrentIdentityAssociation association; if (identityAssociations.isResolvable()) { association = identityAssociations.get(); } else { association = null; } return new SmallRyeGraphQLExecutionHandler(allowGet, association); }
Example #22
Source File: BeanManagerInstanceTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void testGetEvent() { BeanManager beanManager = Arc.container() .beanManager(); Instance<FuuService> instance = beanManager.createInstance() .select(FuuService.class); assertTrue(instance.isResolvable()); assertEquals(10, instance.get().age); }
Example #23
Source File: DefaultPicocliCommandLineFactory.java From quarkus with Apache License 2.0 | 5 votes |
public DefaultPicocliCommandLineFactory(@TopCommand Instance<Object> topCommand, PicocliConfiguration picocliConfiguration, CommandLine.IFactory picocliFactory) { this.topCommand = topCommand; this.picocliConfiguration = picocliConfiguration; this.picocliFactory = picocliFactory; }
Example #24
Source File: InstanceBean.java From quarkus with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public Instance<?> get(CreationalContext<Instance<?>> creationalContext) { // Obtain current IP to get the required type and qualifiers InjectionPoint ip = InjectionPointProvider.get(); InstanceImpl<Instance<?>> instance = new InstanceImpl<Instance<?>>((InjectableBean<?>) ip.getBean(), ip.getType(), ip.getQualifiers(), (CreationalContextImpl<?>) creationalContext, Collections.EMPTY_SET, ip.getMember(), 0); CreationalContextImpl.addDependencyToParent((InjectableBean<Instance<?>>) ip.getBean(), instance, creationalContext); return instance; }
Example #25
Source File: CDIAccessor.java From javamoney-lib with Apache License 2.0 | 5 votes |
public static <T> Instance<T> getInstances(Class<T> instanceType, Annotation... qualifiers) { try { //noinspection ConstantConditions return getInstance(Instance.class).get().select(instanceType, qualifiers); } catch (Exception e) { LOG.info("Failed to load instances from CDI.", e); return emptyInstance(); } }
Example #26
Source File: MessageSenderProvider.java From pnc with Apache License 2.0 | 5 votes |
@Inject public MessageSenderProvider(Instance<MessageSender> messageSenders, SystemConfig config) throws MessagingConfigurationException { this.messageSenders = messageSenders; this.config = config; this.messageSender = selectMessageSender(); }
Example #27
Source File: DefaultJoynrRuntimeFactoryTest.java From joynr with Apache License 2.0 | 5 votes |
@Test public void testJoynrPropertiesAmbiguousThrows() throws Exception { Instance<Properties> joynrProperties = createPropertiesMock(null); when(joynrProperties.isAmbiguous()).thenReturn(true); expectedException.expect(JoynrIllegalStateException.class); expectedException.expectMessage("Multiple joynrProperties specified. Please provide only one configuration EJB containing a value for the joynrProperties via @JoynrProperties."); createFixture(joynrProperties, createLocalDomainMock()); }
Example #28
Source File: QuestionIndexProviderTest.java From mamute with Apache License 2.0 | 5 votes |
@Test public void should_build_null_question_index() throws Exception { Environment env = mock(Environment.class); when(env.get(eq("feature.solr"), anyString())).thenReturn("false"); Instance<SolrServer> instance = mock(Instance.class); QuestionIndexProvider provider = new QuestionIndexProvider(env, instance); QuestionIndex build = provider.build(); assertTrue(NullQuestionIndex.class.isInstance(build)); }
Example #29
Source File: VertxJobsService.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Inject public VertxJobsService(@ConfigProperty(name = "kogito.jobs-service.url") String jobServiceUrl, @ConfigProperty(name = "kogito.service.url") String callbackEndpoint, Vertx vertx, Instance<WebClient> providedWebClient) { super(jobServiceUrl, callbackEndpoint); this.vertx = vertx; this.providedWebClient = providedWebClient; }
Example #30
Source File: GrpcServerRecorder.java From quarkus with Apache License 2.0 | 5 votes |
private static List<ServerServiceDefinition> gatherServices(Instance<BindableService> services) { List<ServerServiceDefinition> definitions = new ArrayList<>(); services.forEach(new Consumer<BindableService>() { // NOSONAR @Override public void accept(BindableService bindable) { ServerServiceDefinition definition = bindable.bindService(); LOGGER.debugf("Registered gRPC service '%s'", definition.getServiceDescriptor().getName()); definitions.add(definition); } }); return definitions; }