diff --git a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/hibernate/DestructibleBeanInstance.java b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/hibernate/DestructibleBeanInstance.java index d0492e9f12..dbaa9b31aa 100644 --- a/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/hibernate/DestructibleBeanInstance.java +++ b/ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/hibernate/DestructibleBeanInstance.java @@ -12,6 +12,7 @@ import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; /** * @author Hardy Ferentschik @@ -43,7 +44,9 @@ public void destroy() { private InjectionTarget createInjectionTarget(BeanManager beanManager, Class type) { AnnotatedType annotatedType = beanManager.createAnnotatedType(type); - return beanManager.createInjectionTarget(annotatedType); + InjectionTargetFactory injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType); + + return injectionTargetFactory.createInjectionTarget(null); } private static T createAndInjectBeans(BeanManager beanManager, InjectionTarget injectionTarget) { diff --git a/ext/cdi/jersey-cdi1x-servlet/src/main/java/org/glassfish/jersey/ext/cdi1x/servlet/internal/CdiExternalRequestScopeExtension.java b/ext/cdi/jersey-cdi1x-servlet/src/main/java/org/glassfish/jersey/ext/cdi1x/servlet/internal/CdiExternalRequestScopeExtension.java index 54b51e7186..50c05a30a1 100644 --- a/ext/cdi/jersey-cdi1x-servlet/src/main/java/org/glassfish/jersey/ext/cdi1x/servlet/internal/CdiExternalRequestScopeExtension.java +++ b/ext/cdi/jersey-cdi1x-servlet/src/main/java/org/glassfish/jersey/ext/cdi1x/servlet/internal/CdiExternalRequestScopeExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018 Payara Foundation and/or its affiliates. * * This program and the accompanying materials are made available under the @@ -35,6 +35,7 @@ import javax.enterprise.inject.spi.Extension; import javax.enterprise.inject.spi.InjectionPoint; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import javax.enterprise.util.AnnotationLiteral; /** @@ -69,7 +70,10 @@ private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscove private void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager) { // we need the injection target so that CDI could instantiate the original interceptor for us - final InjectionTarget interceptorTarget = beanManager.createInjectionTarget(requestScopeType); + final InjectionTargetFactory injectionTargetFactory = + beanManager.getInjectionTargetFactory(requestScopeType); + final InjectionTarget interceptorTarget = + injectionTargetFactory.createInjectionTarget(null); afterBeanDiscovery.addBean(new Bean() { diff --git a/ext/cdi/jersey-cdi1x-validation/src/main/java/org/glassfish/jersey/ext/cdi1x/validation/internal/CdiInterceptorWrapperExtension.java b/ext/cdi/jersey-cdi1x-validation/src/main/java/org/glassfish/jersey/ext/cdi1x/validation/internal/CdiInterceptorWrapperExtension.java index 0a31b53cf0..463f0edc1e 100644 --- a/ext/cdi/jersey-cdi1x-validation/src/main/java/org/glassfish/jersey/ext/cdi1x/validation/internal/CdiInterceptorWrapperExtension.java +++ b/ext/cdi/jersey-cdi1x-validation/src/main/java/org/glassfish/jersey/ext/cdi1x/validation/internal/CdiInterceptorWrapperExtension.java @@ -37,6 +37,7 @@ import javax.enterprise.inject.spi.Extension; import javax.enterprise.inject.spi.InjectionPoint; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import javax.enterprise.util.AnnotationLiteral; import javax.interceptor.Interceptor; @@ -100,7 +101,10 @@ private void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, // we need the injection target so that CDI could instantiate the original interceptor for us final AnnotatedType interceptorType = interceptorAnnotatedType; - final InjectionTarget interceptorTarget = beanManager.createInjectionTarget(interceptorType); + final InjectionTargetFactory injectionTargetFactory = + beanManager.getInjectionTargetFactory(interceptorType); + final InjectionTarget interceptorTarget = + injectionTargetFactory.createInjectionTarget(null); afterBeanDiscovery.addBean(new Bean() { diff --git a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/BeanHelper.java b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/BeanHelper.java index d1fbafae5d..81dc831889 100644 --- a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/BeanHelper.java +++ b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/bean/BeanHelper.java @@ -28,6 +28,7 @@ import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import javax.ws.rs.HttpMethod; import javax.ws.rs.Path; import javax.ws.rs.RuntimeType; @@ -105,7 +106,8 @@ public static void registerBean(RuntimeType runtimeType, InitializableInstan public static BindingBeanPair registerBean(RuntimeType runtimeType, ClassBinding binding, AfterBeanDiscovery abd, Collection resolvers, BeanManager beanManager) { AnnotatedType annotatedType = beanManager.createAnnotatedType(binding.getService()); - InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType); + InjectionTargetFactory injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType); + InjectionTarget injectionTarget = injectionTargetFactory.createInjectionTarget(null); ClassBean bean = new ClassBean<>(runtimeType, binding); bean.setInjectionTarget(getJerseyInjectionTarget(binding.getService(), injectionTarget, bean, resolvers)); diff --git a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java index a99f2f05a1..e3746abec0 100644 --- a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java +++ b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/managed/CdiInjectionManager.java @@ -29,6 +29,7 @@ import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import javax.enterprise.inject.spi.Unmanaged; import javax.inject.Singleton; import javax.ws.rs.RuntimeType; @@ -295,10 +296,12 @@ public List getAllInstances(Type contractOrImpl) { @Override @SuppressWarnings("unchecked") public void inject(Object instance) { + CreationalContext creationalContext = createCreationalContext(null); AnnotatedType annotatedType = beanManager.createAnnotatedType((Class) instance.getClass()); - InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType); - CreationalContext context = createCreationalContext(null); - injectionTarget.inject(instance, context); + InjectionTargetFactory injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType); + InjectionTarget injectionTarget = injectionTargetFactory.createInjectionTarget(null); + + injectionTarget.inject(instance, creationalContext); } @Override diff --git a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/scope/RequestScopeBean.java b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/scope/RequestScopeBean.java index 6770060bfa..62d7e1bec5 100644 --- a/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/scope/RequestScopeBean.java +++ b/incubator/cdi-inject-weld/src/main/java/org/glassfish/jersey/inject/weld/internal/scope/RequestScopeBean.java @@ -30,6 +30,7 @@ import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionPoint; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import javax.enterprise.util.AnnotationLiteral; import javax.inject.Singleton; @@ -49,7 +50,8 @@ public class RequestScopeBean implements Bean { */ public RequestScopeBean(BeanManager beanManager) { AnnotatedType annotatedType = beanManager.createAnnotatedType(CdiRequestScope.class); - this.injectionTarget = beanManager.createInjectionTarget(annotatedType); + InjectionTargetFactory injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType); + this.injectionTarget = injectionTargetFactory.createInjectionTarget(null); } @Override diff --git a/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/CdiSeInjectionManager.java b/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/CdiSeInjectionManager.java index 309649077e..3a8d44d40f 100644 --- a/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/CdiSeInjectionManager.java +++ b/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/CdiSeInjectionManager.java @@ -32,6 +32,7 @@ import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import javax.enterprise.inject.spi.Unmanaged; import org.glassfish.jersey.inject.cdi.se.bean.JerseyBean; @@ -236,9 +237,11 @@ public List getAllInstances(Type contractOrImpl) { @SuppressWarnings("unchecked") public void inject(Object instance) { if (isInitialized()) { - AnnotatedType annotatedType = beanManager.createAnnotatedType((Class) instance.getClass()); - InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType); CreationalContext context = beanManager.createCreationalContext(null); + AnnotatedType annotatedType = beanManager.createAnnotatedType((Class) instance.getClass()); + InjectionTargetFactory injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType); + InjectionTarget injectionTarget = injectionTargetFactory.createInjectionTarget(null); + injectionTarget.inject(instance, context); } } diff --git a/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/RequestScopeBean.java b/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/RequestScopeBean.java index 7b2541bd5f..c605b5003f 100644 --- a/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/RequestScopeBean.java +++ b/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/RequestScopeBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -30,6 +30,7 @@ import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionPoint; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import javax.enterprise.util.AnnotationLiteral; import javax.inject.Singleton; @@ -49,7 +50,8 @@ public class RequestScopeBean implements Bean { */ public RequestScopeBean(BeanManager beanManager) { AnnotatedType annotatedType = beanManager.createAnnotatedType(CdiRequestScope.class); - this.injectionTarget = beanManager.createInjectionTarget(annotatedType); + InjectionTargetFactory injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType); + this.injectionTarget = injectionTargetFactory.createInjectionTarget(null); } @Override diff --git a/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/bean/BeanHelper.java b/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/bean/BeanHelper.java index 97d472c6e6..1a408366a9 100644 --- a/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/bean/BeanHelper.java +++ b/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/bean/BeanHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -26,6 +26,7 @@ import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionTarget; +import javax.enterprise.inject.spi.InjectionTargetFactory; import org.glassfish.jersey.inject.cdi.se.injector.CachedConstructorAnalyzer; import org.glassfish.jersey.inject.cdi.se.injector.InjectionUtils; @@ -99,7 +100,8 @@ public static void registerBean(InstanceBinding binding, AfterBeanDiscove public static void registerBean(ClassBinding binding, AfterBeanDiscovery abd, Collection resolvers, BeanManager beanManager) { AnnotatedType annotatedType = beanManager.createAnnotatedType(binding.getService()); - InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType); + InjectionTargetFactory injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType); + InjectionTarget injectionTarget = injectionTargetFactory.createInjectionTarget(null); ClassBean bean = new ClassBean<>(binding); bean.setInjectionTarget(getJerseyInjectionTarget(binding.getService(), injectionTarget, bean, resolvers));