@Override
    public void onPrepareProviderResource(BeanCustomizerContext context) {

        EndpointInfo endpointInfo = context.getEndpointInfo();
        Set<ProviderResourceInfo> perRequestProviderAndPathInfos = endpointInfo.getPerRequestProviderAndPathInfos();
        Set<ProviderResourceInfo> singletonProviderAndPathInfos = endpointInfo.getSingletonProviderAndPathInfos();

        //The resources map may already exist on the context.  If it does we will want to add to it.
        Map<Class<?>, ManagedObject<?>> resourcesManagedbyCDI = (Map<Class<?>, ManagedObject<?>>)context.getContextObject();
        if (resourcesManagedbyCDI == null || !(resourcesManagedbyCDI instanceof ThreadBasedHashMap)) {
            resourcesManagedbyCDI = new ThreadBasedHashMap();//HashMap<Class<?>, ManagedObject<?>>();
        }

        CXFJaxRsProviderResourceHolder cxfPRHolder = context.getCxfRPHolder();
        for (ProviderResourceInfo p : perRequestProviderAndPathInfos) {
            /**
             * CDI customizer only check if the POJO type bean is CDI bean
             * because when EJB priority is higher than CDI, engine will take the bean as EJB but not CDI,
             * that means EJB already processes it, CDI should not process it again,
             * then CDI should not cache the bean's info in resourcesManagedbyCDI
             */
            if (p.getRuntimeType() != RuntimeType.POJO)
                continue;

            Class<?> clazz = p.getProviderResourceClass();
            if (!hasValidConstructor(clazz, false)) {
                continue;
            }

            Bean<?> bean = null;
            try {
                bean = getBeanFromCDI(clazz);
            } catch (Exception e1) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "ManagedObjectFactory failed to create bean", e1);
                }
            }

            if (bean != null) {

                String scopeName = bean.getScope().getName();
                p.setRuntimeType(RuntimeType.CDI);
                resourcesManagedbyCDI.put(p.getProviderResourceClass(), null);

                if (p.isJaxRsProvider()) {
                    //if CDI Scope is APPLICATION_SCOPE or DEPENDENT_SCOPE, report warning and no action: get provider from CDI
                    if (validSingletonScopeList.contains(scopeName)) {
                        logProviderMismatch(clazz, scopeName, "CDI");
                    }
                    //else report warning, keep using provider from rs: change to use RuntimeType.POJO
                    else {
                        p.setRuntimeType(RuntimeType.POJO);
                        resourcesManagedbyCDI.remove(p.getProviderResourceClass());
                        logProviderMismatch(clazz, scopeName, "JAXRS");
                    }
                } else {
                    if (!validRequestScopeList.contains(scopeName)) { //means this is @ApplicationScoped in CDI
                        logResourceMismatch(clazz, "PerRequest", scopeName, "CDI");
                    }

                }
            } else {

                if (shouldHandle(clazz, false)) {
                    p.setRuntimeType(RuntimeType.IMPLICITBEAN);
                    resourcesManagedbyCDI.put(clazz, null);
                }
                continue;

            }

        }
        for (ProviderResourceInfo o : singletonProviderAndPathInfos) {
            /**
             * CDI customizer only check if the POJO type bean is CDI bean
             * because when EJB priority is higher than CDI, engine will take the bean as EJB but not CDI,
             * that means EJB already processes it, CDI should not process it again,
             * then CDI should not cache the bean's info in resourcesManagedbyCDI
             */
            if (o.getRuntimeType() != RuntimeType.POJO)
                continue;

            Class<?> clazz = o.getProviderResourceClass();
            if (!hasValidConstructor(clazz, true)) {
                continue;
            }

            Bean<?> bean = null;
            try {
                bean = getBeanFromCDI(clazz);
            } catch (Exception e1) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "ManagedObjectFactory failed to create bean", e1);
                }
            }

            if (bean != null) {

                String scopeName = bean.getScope().getName();
                o.setRuntimeType(RuntimeType.CDI);
                resourcesManagedbyCDI.put(o.getProviderResourceClass(), null);
                if (o.isJaxRsProvider()) {
                    if (validSingletonScopeList.contains(scopeName)) {
                        logProviderMismatch(clazz, scopeName, "CDI");
                    }
                    //else report warning, keep using provider from rs: change to use RuntimeType.POJO
                    else {
                        o.setRuntimeType(RuntimeType.POJO);
                        resourcesManagedbyCDI.remove(clazz);
                        logProviderMismatch(clazz, scopeName, "JAXRS");
                    }

                    //Old check is this, need verify by using FAT:
                    //if CDI Scope is APPLICATION_SCOPE or DEPENDENT_SCOPE, report warning and no action: get provider from CDI
                    //else report warning and no action: get provider from CDI

                } else {
                    if (!validSingletonScopeList.contains(scopeName)) { // means CDI is per-request, then modify cxfPRHolder to per-request as well.
                        cxfPRHolder.removeResouceProvider(clazz);//remove from original ResourceProvider map and re-add the new one.
                        cxfPRHolder.addResouceProvider(clazz, new PerRequestResourceProvider(clazz));
                        logResourceMismatch(clazz, "Singleton", scopeName, "CDI");
                    }

                }
            } else {
                if (shouldHandle(clazz, false)) {
                    o.setRuntimeType(RuntimeType.IMPLICITBEAN);
                    resourcesManagedbyCDI.put(clazz, null);
                }
                continue;
            }

        }

        context.setContextObject(resourcesManagedbyCDI);

    }
@ Override public void onPrepareProviderResource ( BeanCustomizerContext context ) { EndpointInfo endpointInfo = context . getEndpointInfo ( ) ; Set < ProviderResourceInfo > perRequestProviderAndPathInfos = endpointInfo . getPerRequestProviderAndPathInfos ( ) ; Set < ProviderResourceInfo > singletonProviderAndPathInfos = endpointInfo . getSingletonProviderAndPathInfos ( ) ; Map < Class < ? > , ManagedObject < ? > > resourcesManagedbyCDI = ( Map < Class < ? > , ManagedObject < ? > > ) context . getContextObject ( ) ; if ( resourcesManagedbyCDI == null || ! ( resourcesManagedbyCDI instanceof ThreadBasedHashMap ) ) { resourcesManagedbyCDI = new ThreadBasedHashMap ( ) ; } CXFJaxRsProviderResourceHolder cxfPRHolder = context . getCxfRPHolder ( ) ; for ( ProviderResourceInfo p : perRequestProviderAndPathInfos ) { if ( p . getRuntimeType ( ) != RuntimeType . POJO ) continue ; Class < ? > clazz = p . getProviderResourceClass ( ) ; if ( ! hasValidConstructor ( clazz , false ) ) { continue ; } Bean < ? > bean = null ; try { bean = getBeanFromCDI ( clazz ) ; } catch ( Exception e1 ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "ManagedObjectFactory failed to create bean" , e1 ) ; } } if ( bean != null ) { String scopeName = bean . getScope ( ) . getName ( ) ; p . setRuntimeType ( RuntimeType . CDI ) ; resourcesManagedbyCDI . put ( p . getProviderResourceClass ( ) , null ) ; if ( p . isJaxRsProvider ( ) ) { if ( validSingletonScopeList . contains ( scopeName ) ) { logProviderMismatch ( clazz , scopeName , "CDI" ) ; } else { p . setRuntimeType ( RuntimeType . POJO ) ; resourcesManagedbyCDI . remove ( p . getProviderResourceClass ( ) ) ; logProviderMismatch ( clazz , scopeName , "JAXRS" ) ; } } else { if ( ! validRequestScopeList . contains ( scopeName ) ) { logResourceMismatch ( clazz , "PerRequest" , scopeName , "CDI" ) ; } } } else { if ( shouldHandle ( clazz , false ) ) { p . setRuntimeType ( RuntimeType . IMPLICITBEAN ) ; resourcesManagedbyCDI . put ( clazz , null ) ; } continue ; } } for ( ProviderResourceInfo o : singletonProviderAndPathInfos ) { if ( o . getRuntimeType ( ) != RuntimeType . POJO ) continue ; Class < ? > clazz = o . getProviderResourceClass ( ) ; if ( ! hasValidConstructor ( clazz , true ) ) { continue ; } Bean < ? > bean = null ; try { bean = getBeanFromCDI ( clazz ) ; } catch ( Exception e1 ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "ManagedObjectFactory failed to create bean" , e1 ) ; } } if ( bean != null ) { String scopeName = bean . getScope ( ) . getName ( ) ; o . setRuntimeType ( RuntimeType . CDI ) ; resourcesManagedbyCDI . put ( o . getProviderResourceClass ( ) , null ) ; if ( o . isJaxRsProvider ( ) ) { if ( validSingletonScopeList . contains ( scopeName ) ) { logProviderMismatch ( clazz , scopeName , "CDI" ) ; } else { o . setRuntimeType ( RuntimeType . POJO ) ; resourcesManagedbyCDI . remove ( clazz ) ; logProviderMismatch ( clazz , scopeName , "JAXRS" ) ; } } else { if ( ! validSingletonScopeList . contains ( scopeName ) ) { cxfPRHolder . removeResouceProvider ( clazz ) ; cxfPRHolder . addResouceProvider ( clazz , new PerRequestResourceProvider ( clazz ) ) ; logResourceMismatch ( clazz , "Singleton" , scopeName , "CDI" ) ; } } } else { if ( shouldHandle ( clazz , false ) ) { o . setRuntimeType ( RuntimeType . IMPLICITBEAN ) ; resourcesManagedbyCDI . put ( clazz , null ) ; } continue ; } } context . setContextObject ( resourcesManagedbyCDI ) ; }
/*
(non-Javadoc)

@see com.ibm.ws.jaxrs20.api.JaxRsFactoryBeanCustomizer#onPrepareProviderResource(com.ibm.ws.jaxrs20.api.JaxRsFactoryBeanCustomizer.BeanCustomizerContext)