using LibertyJaxRsServerFactoryBean.performInvocation to support POJO, EJB, CDI resource
555477
@Override
    protected Object performInvocation(Exchange exchange, Object serviceObject, Method m, Object[] paramArray) throws Exception {
        paramArray = insertExchange(m, paramArray, exchange);
        return this.libertyJaxRsServerFactoryBean.performInvocation(exchange, serviceObject, m, paramArray);
    }
894665
@Override
    public SessionFactory buildSessionFactory() throws HibernateException {

        // set the class loader to load Groovy classes

        // work around for HHH-2624
        SessionFactory sessionFactory;

        Object classLoaderObject = getProperties().get(AvailableSettings.CLASSLOADERS);
        ClassLoader appClassLoader;

        if(classLoaderObject instanceof ClassLoader) {
            appClassLoader = (ClassLoader) classLoaderObject;
        }
        else {
            appClassLoader = getClass().getClassLoader();
        }

        ConfigurationHelper.resolvePlaceHolders(getProperties());

        final GrailsDomainBinder domainBinder = new GrailsDomainBinder(
                dataSourceName,
                sessionFactoryBeanName,
                hibernateMappingContext
        );

        List<Class> annotatedClasses = new ArrayList<>();
        for (PersistentEntity persistentEntity : hibernateMappingContext.getPersistentEntities()) {
            Class javaClass = persistentEntity.getJavaClass();
            if(javaClass.isAnnotationPresent(Entity.class)) {
                annotatedClasses.add(javaClass);
            }
        }

        if(!additionalClasses.isEmpty()) {
            for (Class additionalClass : additionalClasses) {
                if(GormEntity.class.isAssignableFrom(additionalClass)) {
                    hibernateMappingContext.addPersistentEntity(additionalClass);
                }
            }
        }

        addAnnotatedClasses( annotatedClasses.toArray(new Class[annotatedClasses.size()]));

        ClassLoaderService classLoaderService = new ClassLoaderServiceImpl(appClassLoader) {
            @Override
            public <S> Collection<S> loadJavaServices(Class<S> serviceContract) {
                if(MetadataContributor.class.isAssignableFrom(serviceContract)) {
                    if(metadataContributor != null) {
                        return (Collection<S>) Arrays.asList(domainBinder, metadataContributor);
                    }
                    else {
                        return Collections.singletonList((S) domainBinder);
                    }
                }
                else {
                    return super.loadJavaServices(serviceContract);
                }
            }
        };
        EventListenerIntegrator eventListenerIntegrator = new EventListenerIntegrator(hibernateEventListeners, eventListeners);
        BootstrapServiceRegistry bootstrapServiceRegistry = createBootstrapServiceRegistryBuilder()
                                                                    .applyIntegrator(eventListenerIntegrator)
                                                                    .applyIntegrator(new MetadataIntegrator())
                                                                    .applyClassLoaderService(classLoaderService)
                                                                    .build();
        StrategySelector strategySelector = bootstrapServiceRegistry.getService(StrategySelector.class);

        strategySelector.registerStrategyImplementor(
                PropertyAccessStrategy.class, "traitProperty", TraitPropertyAccessStrategy.class
        );

        setSessionFactoryObserver(new SessionFactoryObserver() {
            private static final long serialVersionUID = 1;
            public void sessionFactoryCreated(SessionFactory factory) {}
            public void sessionFactoryClosed(SessionFactory factory) {
                if (serviceRegistry != null) {
                    ((ServiceRegistryImplementor)serviceRegistry).destroy();
                }
            }
        });

        StandardServiceRegistryBuilder standardServiceRegistryBuilder = createStandardServiceRegistryBuilder(bootstrapServiceRegistry)
                                                                                    .applySettings(getProperties());

        StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
        sessionFactory = super.buildSessionFactory(serviceRegistry);
        this.serviceRegistry = serviceRegistry;

        return sessionFactory;
    }
1069230
private void setXMLBeanInterface(String homeInterfaceName, String interfaceName) // F743-32443
    throws InjectionException
    {
        // If a home or business interface was specified in XML, then set that as
        // the injection type.  Both may be null if the XML just provides an
        // override of an annotation to add <ejb-link>... in which case the
        // injection class type will be set when the annotation is processed.

        // For performance, there is no need to load these classes until first
        // accessed, which might be never if there is a binding file, so just the
        // name will be set here. getInjectionClassType() is then overridden to load
        // the class when needed. Prior to EJB 3.0 these interfaces were completely
        // ignored, so this behavior allows EJB 2.1 apps to continue to function
        // even if they had garbage in their deployment descriptor.        d739281
        if (homeInterfaceName != null && homeInterfaceName.length() != 0) // d668376
        {
            ivHomeInterface = true;
            setInjectionClassTypeName(homeInterfaceName);

            if (isValidationLoggable())
            {
                loadClass(homeInterfaceName, isValidationFailable());
                loadClass(interfaceName, isValidationFailable());
            }
        }
        else if (interfaceName != null && interfaceName.length() != 0) // d668376
        {
            ivBeanInterface = true;
            setInjectionClassTypeName(interfaceName);

            if (isValidationLoggable())
            {
                loadClass(interfaceName, isValidationFailable());
            }
        }
    }
598702
public static void construct(BaseMessageEndpointFactory factory,
                                 MessageEndpointBase messageEndpointBase,
                                 int recoveryId,
                                 EJSContainer container,
                                 BeanMetaData beanMetaData,
                                 EJBPMICollaborator pmiBean,
                                 WrapperManager wrapperManager,
                                 boolean rrsTransactional) //d219252x
    {
        // Initialize superclass with the wrapper information.
        messageEndpointBase.container = container;
        messageEndpointBase.wrapperManager = wrapperManager;
        messageEndpointBase.beanId = new BeanId(factory, null, false);
        messageEndpointBase.bmd = beanMetaData;
        messageEndpointBase.ivPmiBean = pmiBean;
        messageEndpointBase.isolationAttrs = null;
        messageEndpointBase.ivCommon = null; // Not a cached wrapper.     d174057.2
        messageEndpointBase.isManagedWrapper = false; // Not a managed wrapper.    d174057.2
        messageEndpointBase.methodInfos = messageEndpointBase.bmd.localMethodInfos;
        messageEndpointBase.methodNames = messageEndpointBase.bmd.localMethodNames;
        messageEndpointBase.ivInterface = WrapperInterface.MESSAGE_LISTENER; // d366807

        // Initialize this objects instance variables.
        messageEndpointBase.ivRecoveryId = recoveryId;
        messageEndpointBase.ivMessageEndpointFactory = factory;
        messageEndpointBase.ivTransactionManager = EmbeddableTransactionManagerFactory.getTransactionManager();
        messageEndpointBase.ivRRSTransactional = rrsTransactional;

        //d456256 start
        // If there is only 1 method in the EJBMethodInfo for the
        // message listener interface, then set ivSingleMethodInterface
        // to true.
        if (messageEndpointBase.methodInfos.length == 1)
        {
            messageEndpointBase.ivSingleMethodInterface = true;
        }
        // d456256 end
    }
496262
@Override
    public final Handle createHandle(BeanId id)
                    throws RemoteException
    {
        EJSWrapper wrapper = null;
        homeEnabled();

        wrapper = getWrapper(id).getRemoteWrapper(); // f111627; //p116577

        if (!statelessSessionHome && !statefulSessionHome)
        {
            if (cvUsePortableClass) //p125891
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "createHandle():Creating portable HandleImpl"); //p125891

                // p116577 - start of change
                // Need to make EntityHandle class use only
                // SUN JDK or Java EE interfaces.  So, we need to pass EJBObject
                // stub to the EntityHandle constructor.
                return new HandleImpl((EJBObject) PortableRemoteObject.toStub(wrapper)); // F743-509.CodRev
                // p116577 - end of change
            }
            else
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "createHandle():Creating non-portable EntityHandle"); //p125891
                Properties pFake = null;
                return new EntityHandle(id, beanMetaData, pFake); //p125891 //d145386
            }
        }
        else
        {
            Object wrapperRef = container.getEJBRuntime().getRemoteReference(wrapper);
            EJBObject object = (EJBObject) PortableRemoteObject.narrow(wrapperRef, EJBObject.class);
            return container.sessionHandleFactory.create(object);
        }
    }
1173114
private static Object findJarServiceProvider(String factoryId) throws ConfigurationError {
        String serviceId = "META-INF/services/" + factoryId;
        InputStream is = null;

        // First try the Context ClassLoader
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if (cl != null) {
            is = cl.getResourceAsStream(serviceId);
        }

        if (is == null) {
            cl = FactoryFinder.class.getClassLoader();
            is = cl.getResourceAsStream(serviceId);
        }

        if (is == null) {
            // No provider found
            return null;
        }

        if (debug) debugPrintln("found jar resource=" + serviceId + " using ClassLoader: " + cl);

        BufferedReader rd;
        try {
            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), DEFAULT_LINE_LENGTH);
        } catch (java.io.UnsupportedEncodingException e) {
            rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH);
        }

        String factoryClassName = null;
        try {
            // XXX Does not handle all possible input as specified by the
            // Jar Service Provider specification
            factoryClassName = rd.readLine();
        } catch (IOException x) {
            // No provider found
            return null;
        } finally {
            IoUtils.closeQuietly(rd);
        }

        if (factoryClassName != null &&
            ! "".equals(factoryClassName)) {
            if (debug) debugPrintln("found in resource, value="
                   + factoryClassName);

            return newInstance(factoryClassName, cl);
        }

        // No provider found
        return null;
    }
292152
static synchronized BeanFactoryId register(Class<?> clazz, Set<String> pathParams,
                                               List<RequestObjectResolver> objectResolvers) {
        final BeanFactoryId beanFactoryId = new BeanFactoryId(clazz, pathParams);
        if (!factories.containsKey(beanFactoryId)) {
            final AnnotatedBeanFactory<Object> factory = createFactory(beanFactoryId, objectResolvers);
            if (factory != null) {
                factories.put(beanFactoryId, factory);
                logger.debug("Registered a bean factory: {}", beanFactoryId);
            } else {
                factories.put(beanFactoryId, unsupportedBeanFactory);
            }
        }
        return beanFactoryId;
    }
543316
@Override
    public void run(C configuration, Environment environment) {
        checkArgument(environment != null, "Environment is null");
        environment.servlets().addServlet("CXF Servlet " + jaxwsEnvironment.getDefaultPath(),
                jaxwsEnvironment.buildServlet()).addMapping(servletPath);

        environment.lifecycle().addServerLifecycleListener(
                server -> jaxwsEnvironment.logEndpoints());

        String publishedEndpointUrlPrefix = getPublishedEndpointUrlPrefix(configuration);
        if(publishedEndpointUrlPrefix != null) {
            jaxwsEnvironment.setPublishedEndpointUrlPrefix(publishedEndpointUrlPrefix);
        }
    }
236393
private void registerJsfCdiToSpring(BeanDefinition definition) {

		if (definition instanceof AnnotatedBeanDefinition) {
			AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;

			String scopeName = null;
			// firstly check whether bean is defined via configuration
			if (annDef.getFactoryMethodMetadata() != null) {
				scopeName = deduceScopeName(annDef.getFactoryMethodMetadata());
			}
			else {
				// fallback to type
				scopeName = deduceScopeName(annDef.getMetadata());
			}

			if (scopeName != null) {
				definition.setScope(scopeName);

				log.debug("{} - Scope({})", definition.getBeanClassName(), scopeName.toUpperCase());
			}
		}
	}
83831
public void init()
    {
        LOG.info("Scanning esjps for REST implementations");
        try {
            if (!Context.isThreadActive()) {
                Context.begin(null, Context.Inheritance.Local);
                Context.getThreadContext().setRequestAttribute(CONTEXTHINT, true);
            }
            registerClasses(new EsjpScanner().scan(Path.class, Provider.class));
        } catch (final EFapsException e) {
            LOG.error("Catched EFapsException", e);
        }
        registerClasses(Compile.class);
        registerClasses(Update.class);
        registerClasses(RestEQLInvoker.class);
        registerClasses(RestContext.class);
        registerClasses(Search.class);
        registerClasses(ObjectMapperResolver.class);
        if (EFapsResourceConfig.LOG.isInfoEnabled() && !getClasses().isEmpty()) {
            final Set<Class<?>> rootResourceClasses = get(Path.class);
            if (rootResourceClasses.isEmpty()) {
                EFapsResourceConfig.LOG.info("No root resource classes found.");
            } else {
                logClasses("Root resource classes found:", rootResourceClasses);
            }

            final Set<Class<?>> providerClasses = get(Provider.class);
            if (providerClasses.isEmpty()) {
                EFapsResourceConfig.LOG.info("No provider classes found.");
            } else {
                logClasses("Provider classes found:", providerClasses);
            }
        }
        this.cachedClasses.clear();
        this.cachedClasses.addAll(getClasses());
    }
492240
public void enableMvc(ConfigurableListableBeanFactory factory, BundleContext context) {
        if (factory == null) {
            throw new IllegalArgumentException("Method argument factory must not be null.");
        }
        if (context == null) {
            throw new IllegalArgumentException("Method argument context must not be null.");
        }

        BundleAwareServletConfig servletConfig = new BundleAwareServletConfig(context);

        factory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext, servletConfig));
        factory.ignoreDependencyInterface(ServletContextAware.class);
        factory.ignoreDependencyInterface(ServletConfigAware.class);

        final BundleSpecificDispatcherServlet dispatcherServlet = createBundleSpecificDispatcherServlet(factory, servletConfig);
        factory.registerSingleton(generateNameFor(BundleSpecificDispatcherServlet.class), dispatcherServlet);
        this.mvcCapableBundles.put(context.getBundle(), dispatcherServlet);
    }
464610
public static void createJar(LibertyServer server, String dir, String jarName, boolean addJarResources, String... packageNames) throws Exception {
        String baseDir = DIR_PUBLISH + server.getServerName() + "/" + dir + "/";
        JavaArchive jar = null;
        if (jarName != null) {
            LOG.info("createJar : create jar " + jarName + ", jar includes resources : " + addJarResources);
            jar = ShrinkWrap.create(JavaArchive.class, jarName);
            if (packageNames != null) {
                for (String packageName : packageNames) {
                    if (packageName.contains(".jar.")) {
                        jar.addPackage(packageName);
                    }
                }
            }
            if (addJarResources)
                ShrinkHelper.addDirectory(jar, "test-applications/" + jarName + "/resources");
        }
        ShrinkHelper.exportArtifact(jar, DIR_PUBLISH + server.getServerName() + "/" + dir, true, true);
    }
1152444
@Override
	protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
		beanFactory.addBeanPostProcessor(
				new WebApplicationContextServletContextAwareProcessor(this));
		beanFactory.ignoreDependencyInterface(ServletContextAware.class);
		registerWebApplicationScopes();
	}
873173
@Override
    public final EQUIPPEDRESOLVESTAGETYPE loadPomFromClassLoaderResource(final String pathToPomResource)
            throws IllegalArgumentException, InvalidConfigurationFileException {
        final MavenWorkingSession session = this.getMavenWorkingSession();
        LoadPomTask.loadPomFromClassLoaderResource(pathToPomResource).execute(session);
        return this.createNewPomEquippedResolveStage();
    }
1067309
@Activate
    protected void activate(ComponentContext cc) throws Exception {

        RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
        //This is a workaroud to avoid invoking createWoodstoxFactory in org.apache.cxf.staxutils.StaxUtils.createXMLInputFactor
        AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
            @Override
            public Boolean run()
                            throws Exception
            {
                System.setProperty(StaxUtils.ALLOW_INSECURE_PARSER, "1"); // sets the bla property without throwing an exception -> ok
                return Boolean.TRUE;
            }
        });
        ClassLoader orignalClassLoader = THREAD_CONTEXT_ACCESSOR.getContextClassLoader(Thread.currentThread());
        try {
            //Make sure the current ThreadContextClassLoader is not an App classloader
            THREAD_CONTEXT_ACCESSOR.setContextClassLoader(Thread.currentThread(), JaxRsServiceActivator.class.getClassLoader());
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put("org.apache.cxf.bus.id", "Default Bus");
            Bus defaultBus = LibertyApplicationBusFactory.getInstance().createBus(null, properties);
            LibertyApplicationBusFactory.setDefaultBus(defaultBus);
        } finally {
            THREAD_CONTEXT_ACCESSOR.setContextClassLoader(Thread.currentThread(), orignalClassLoader);
        }

    }
1015038
public static void addWarToServerApps(LibertyServer server, String warName, boolean addWarResources, String jarName, boolean addJarResources,
                                          String... packageNames) throws Exception {
        addEarToServer(server, DIR_APPS, null, false, warName, addWarResources, jarName, addJarResources, packageNames);
    }
175054
private void initializeEntityConstructor(BeanMetaData bmd) throws EJBConfigurationException {
        try {
            bmd.ivEnterpriseBeanClassConstructor = bmd.enterpriseBeanClass.getConstructor((Class<?>[]) null);
        } catch (NoSuchMethodException e) {
            Tr.error(tc, "JIT_NO_DEFAULT_CTOR_CNTR5007E",
                     new Object[] { bmd.enterpriseBeanClassName, bmd.enterpriseBeanName });
            throw new EJBConfigurationException("CNTR5007E: The " + bmd.enterpriseBeanClassName + " bean class for the " + bmd.enterpriseBeanName +
                                                " bean does not have a public constructor that does not take parameters.");
        }
    }