public static <T> void initSingletonEJBCDIProvider(AbstractResourceInfo resource, Message message, T resourceObject) {

        /*
         * Only @Provider will use logic here.
         * As EJB can only be default constructor, CDI can be default constructor or 1 param with @Inject constructor
         * And a provider must have 1 public constructor(default constructor or @Context params constructor)
         * then the intersection is only default constructor.
         * so if ConstructorProxies!=null means there are some other invalid constructors to EJB or CDI container
         */
        if ((!(resource instanceof ProviderInfo)) || (resource instanceof ApplicationInfo) || resource.getConstructorProxies() != null) {
            return;
        }

        ProviderInfo<T> pi = (ProviderInfo<T>) resource;

        /**
         * if this provider is inited which means it may be replaced by EJB or CDI bean or it may be invoked with @PostConstrcut
         */
        if (pi.isInit()) {
            return;
        }

        synchronized(pi) {
            if (pi.isInit()) {
                return;
            }
            Class clz = pi.getProvider().getClass();
            Bus bus = resource.getBus();

            if (bus != null) { // if bus is null, then we don't need to do injection on this provider
                List<JaxRsFactoryBeanCustomizer> beanCustomizers = (List<JaxRsFactoryBeanCustomizer>) bus.getProperty(JaxRsConstants.ENDPOINT_LIST_BEANCUSTOMIZER);
                Map<String, Object> beanCustomizerContexts = (Map<String, Object>) bus.getProperty(JaxRsConstants.ENDPOINT_BEANCUSTOMIZER_CONTEXTOBJ);

                if (beanCustomizers != null && !beanCustomizers.isEmpty() && beanCustomizerContexts != null) {

                    Object newProviderInstance = null;
                    for (JaxRsFactoryBeanCustomizer beanCustomizer : beanCustomizers) {
                        if (beanCustomizer.isCustomizableBean(clz, beanCustomizerContexts.get(Integer.toString(beanCustomizer.hashCode())))) {

                            newProviderInstance = beanCustomizer.onSingletonProviderInit(pi.getProvider(), beanCustomizerContexts.get(Integer.toString(beanCustomizer.hashCode())), message);

                            /**
                             * if newProviderInstance!= the original object, which means it is replaced to EJB or CDI, so just return
                             * no need call @PostConstruct
                             */
                            if (newProviderInstance != null) {
                                //call setProvider to set isInit==true
                                pi.setProvider(newProviderInstance);
                                pi.setIsInit(true);
                                return;
                            }
                        }
                    }
                }
                //No replacement happens which means this is a POJO, call @PostConstruct
                pi.setIsInit(true);
                Method postConstructMethod = ResourceUtils.findPostConstructMethod(clz);
                InjectionUtils.invokeLifeCycleMethod(pi.getProvider(), postConstructMethod);
            }
        }
    }
public static < T > void initSingletonEJBCDIProvider ( AbstractResourceInfo resource , Message message , T resourceObject ) { if ( ( ! ( resource instanceof ProviderInfo ) ) || ( resource instanceof ApplicationInfo ) || resource . getConstructorProxies ( ) != null ) { return ; } ProviderInfo < T > pi = ( ProviderInfo < T > ) resource ; if ( pi . isInit ( ) ) { return ; } synchronized ( pi ) { if ( pi . isInit ( ) ) { return ; } Class clz = pi . getProvider ( ) . getClass ( ) ; Bus bus = resource . getBus ( ) ; if ( bus != null ) { List < JaxRsFactoryBeanCustomizer > beanCustomizers = ( List < JaxRsFactoryBeanCustomizer > ) bus . getProperty ( JaxRsConstants . ENDPOINT_LIST_BEANCUSTOMIZER ) ; Map < String , Object > beanCustomizerContexts = ( Map < String , Object > ) bus . getProperty ( JaxRsConstants . ENDPOINT_BEANCUSTOMIZER_CONTEXTOBJ ) ; if ( beanCustomizers != null && ! beanCustomizers . isEmpty ( ) && beanCustomizerContexts != null ) { Object newProviderInstance = null ; for ( JaxRsFactoryBeanCustomizer beanCustomizer : beanCustomizers ) { if ( beanCustomizer . isCustomizableBean ( clz , beanCustomizerContexts . get ( Integer . toString ( beanCustomizer . hashCode ( ) ) ) ) ) { newProviderInstance = beanCustomizer . onSingletonProviderInit ( pi . getProvider ( ) , beanCustomizerContexts . get ( Integer . toString ( beanCustomizer . hashCode ( ) ) ) , message ) ; if ( newProviderInstance != null ) { pi . setProvider ( newProviderInstance ) ; pi . setIsInit ( true ) ; return ; } } } } pi . setIsInit ( true ) ; Method postConstructMethod = ResourceUtils . findPostConstructMethod ( clz ) ; InjectionUtils . invokeLifeCycleMethod ( pi . getProvider ( ) , postConstructMethod ) ; } } }
RuntimeContextTLS can init the EJB or CDI provider

@param <T>

@param <T>

@param resource
@param message