diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/codegen/AsmSerializableBeanGenerator.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/codegen/AsmSerializableBeanGenerator.java index eeecc7507d5..d363ac43e50 100644 --- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/codegen/AsmSerializableBeanGenerator.java +++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/codegen/AsmSerializableBeanGenerator.java @@ -37,12 +37,13 @@ * only if the new code is made subject to such option by the copyright * holder. */ -//Portions Copyright [2016] [Payara Foundation] +//Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates] package com.sun.ejb.codegen; import org.glassfish.hk2.external.org.objectweb.asm.*; import java.io.Serializable; +import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.lang.reflect.ReflectPermission; import java.security.AccessController; @@ -97,7 +98,7 @@ public Class generateSerializableSubclass() Type.getType(Serializable.class).getInternalName() }; - tv.visit(V1_1, ACC_PUBLIC, + tv.visit(V1_8, ACC_PUBLIC, subclassInternalName, null, Type.getType(baseClass).getInternalName(), interfaces); @@ -109,12 +110,12 @@ public Class generateSerializableSubclass() Constructor[] ctors = baseClass.getConstructors(); Constructor ctorWithParams = null; for(Constructor ctor : ctors) { - if(ctor.getParameterTypes().length == 0) { + if (ctor.getParameterTypes().length == 0) { ctorWithParams = null; //exists the no-arg ctor, use it break; } else if(ctorWithParams == null) { - ctorWithParams = ctor; - } + ctorWithParams = ctor; + } } int numArgsToPass = 1; // default is 1 to just handle 'this' @@ -137,6 +138,18 @@ public Class generateSerializableSubclass() ctorv.visitInsn(RETURN); ctorv.visitMaxs(numArgsToPass, numArgsToPass); + if (ctorWithParams != null) { + for (Annotation annotation : ctorWithParams.getAnnotations()) { + ctorv.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true); + } + + for (int i = 0; i < ctorWithParams.getParameterTypes().length; i++) { + for (Annotation parameterAnnotation : ctorWithParams.getParameterAnnotations()[i]) { + ctorv.visitParameterAnnotation(i, Type.getDescriptor(parameterAnnotation.annotationType()), true); + } + } + } + MethodVisitor cv = cw.visitMethod(ACC_PRIVATE, "writeObject", "(Ljava/io/ObjectOutputStream;)V", null, new String[] { "java/io/IOException" }); cv.visitVarInsn(ALOAD, 0); cv.visitVarInsn(ALOAD, 1); diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/MetricsInterceptor.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/MetricsInterceptor.java index afdc697f7e5..47c87aea56d 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/MetricsInterceptor.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/MetricsInterceptor.java @@ -87,9 +87,9 @@ public class MetricsInterceptor { private MetricsResolver resolver; private Bean bean; - + @Inject - private MetricsInterceptor(MetricRegistry registry, MetricsResolver resolver, @Intercepted Bean bean) { + public MetricsInterceptor(MetricRegistry registry, MetricsResolver resolver, @Intercepted Bean bean) { this.registry = registry; this.resolver = resolver; this.bean = bean; diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java index 91a86f56ffd..6dd0cb565da 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java @@ -84,6 +84,8 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; +import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType; +import org.jboss.weld.manager.BeanManagerImpl; @Service @Rank(10) @@ -392,7 +394,7 @@ public T createInterceptorInstance(Class interceptorClass, BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName()); WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication()); - WeldManager beanManager = bootstrap.getManager(bda); + BeanManagerImpl beanManager = bootstrap.getManager(bda); org.jboss.weld.ejb.spi.EjbDescriptor ejbDesc = beanManager.getEjbDescriptor( ejb.getName()); @@ -420,30 +422,20 @@ public T createInterceptorInstance(Class interceptorClass, // Check to see if the interceptor was defined as a Bean. // This can happen when using @Interceptors to define the interceptors. - Set> availableBeans = beanManager.getBeans( interceptorClass); - if ( availableBeans != null && !availableBeans.isEmpty()) { + Set> availableBeans = beanManager.getBeans(interceptorClass); + Bean interceptorBean; + if (availableBeans != null && !availableBeans.isEmpty()) { // using the ejb's creationalContext so we don't have to do any cleanup. // the cleanup will be handled by weld when it clean's up the ejb. - Bean interceptorBean = beanManager.resolve( availableBeans ); - Object instance = beanManager.getReference(interceptorBean, interceptorClass, creationalContext ); - return ( T ) instance; - } - - // There are other interceptors like SessionBeanInterceptor that are - // defined via code and they are not beans. - // Cannot use the ejb's creationalContext. - creationalContext = beanManager.createCreationalContext(null); - - AnnotatedType annotatedType = beanManager.createAnnotatedType(interceptorClass); - InjectionTarget it = - beanManager.getInjectionTargetFactory(annotatedType).createInterceptorInjectionTarget(); - T interceptorInstance = it.produce(creationalContext); - it.inject(interceptorInstance, creationalContext); - - // make sure the interceptor's cdi objects get cleaned up when the ejb is cleaned up. - ejbContext.addDependentContext( new JCDIInjectionContextImpl<>( it, creationalContext, interceptorInstance ) ); - - return interceptorInstance; + interceptorBean = beanManager.resolve(availableBeans); + } else { + AnnotatedType annotatedType = beanManager.createAnnotatedType(interceptorClass); + BeanAttributes attributes = beanManager.createBeanAttributes(annotatedType); + EnhancedAnnotatedType enhancedAnnotatedType = beanManager.createEnhancedAnnotatedType(interceptorClass); + interceptorBean = InterceptorImpl.of(attributes, enhancedAnnotatedType, beanManager); + } + Object instance = beanManager.getReference(interceptorBean, interceptorClass, creationalContext); + return (T) instance; } @Override