Search in sources :

Example 21 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class SingletonComponentDescription method createConfiguration.

@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
    ComponentConfiguration singletonComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
    // setup the component create service
    singletonComponentConfiguration.setComponentCreateServiceFactory(new SingletonComponentCreateServiceFactory(this.isInitOnStartup(), dependsOn));
    if (isExplicitSecurityDomainConfigured()) {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
                String contextID = deploymentUnit.getName();
                if (deploymentUnit.getParent() != null) {
                    contextID = deploymentUnit.getParent().getName() + "!" + contextID;
                }
                EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
                if (isSecurityDomainKnown()) {
                    final HashMap<Integer, InterceptorFactory> elytronInterceptorFactories = getElytronInterceptorFactories(contextID, ejbComponentDescription.isEnableJacc());
                    elytronInterceptorFactories.forEach((priority, elytronInterceptorFactory) -> configuration.addPostConstructInterceptor(elytronInterceptorFactory, priority));
                } else {
                    configuration.addPostConstructInterceptor(new SecurityContextInterceptorFactory(isExplicitSecurityDomainConfigured(), false, contextID), InterceptorOrder.View.SECURITY_CONTEXT);
                }
            }
        });
    }
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            if (isInitOnStartup()) {
                final StartupCountdown startupCountdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
                configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new StartupCountDownInterceptor(startupCountdown)), InterceptorOrder.ComponentPostConstruct.STARTUP_COUNTDOWN_INTERCEPTOR);
            }
        }
    });
    if (getTransactionManagementType().equals(TransactionManagementType.CONTAINER)) {
        //we need to add the transaction interceptor to the lifecycle methods
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
                InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
                if (interceptorConfig.getPostConstruct() != null) {
                    configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), true), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                }
                configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), true), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                configuration.addTimeoutViewInterceptor(TimerCMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
            }
        });
    } else {
        // add the bmt interceptor
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                configuration.addPostConstructInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                configuration.addPreDestroyInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                // add the bmt interceptor factory
                configuration.addComponentInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
            }
        });
    }
    return singletonComponentConfiguration;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ConcurrencyManagementType(javax.ejb.ConcurrencyManagementType) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) LifecycleCMTTxInterceptor(org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor) HashMap(java.util.HashMap) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) StatelessWriteReplaceInterceptor(org.jboss.as.ejb3.component.session.StatelessWriteReplaceInterceptor) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) InterceptorOrder(org.jboss.as.ee.component.interceptors.InterceptorOrder) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) Method(java.lang.reflect.Method) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) ModuleLoader(org.jboss.modules.ModuleLoader) MetadataCompleteMarker(org.jboss.as.ee.metadata.MetadataCompleteMarker) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ContainerManagedConcurrencyInterceptorFactory(org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptorFactory) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown) StatelessRemoteViewInstanceFactory(org.jboss.as.ejb3.component.session.StatelessRemoteViewInstanceFactory) SecurityContextInterceptorFactory(org.jboss.as.ejb3.security.SecurityContextInterceptorFactory) TimerCMTTxInterceptor(org.jboss.as.ejb3.tx.TimerCMTTxInterceptor) EjbBMTInterceptor(org.jboss.as.ejb3.tx.EjbBMTInterceptor) Attachments(org.jboss.as.ee.component.Attachments) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) List(java.util.List) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EjbLogger(org.jboss.as.ejb3.logging.EjbLogger) ServiceName(org.jboss.msc.service.ServiceName) ViewDescription(org.jboss.as.ee.component.ViewDescription) Collections(java.util.Collections) TransactionManagementType(javax.ejb.TransactionManagementType) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) HashMap(java.util.HashMap) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ContainerManagedConcurrencyInterceptorFactory(org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptorFactory) StatelessRemoteViewInstanceFactory(org.jboss.as.ejb3.component.session.StatelessRemoteViewInstanceFactory) SecurityContextInterceptorFactory(org.jboss.as.ejb3.security.SecurityContextInterceptorFactory) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) SecurityContextInterceptorFactory(org.jboss.as.ejb3.security.SecurityContextInterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown)

Example 22 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class SingletonComponentDescription method addViewSerializationInterceptor.

private void addViewSerializationInterceptor(final ViewDescription view) {
    view.setSerializable(true);
    view.setUseWriteReplace(true);
    view.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            final DeploymentReflectionIndex index = context.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
            ClassReflectionIndex classIndex = index.getClassIndex(WriteReplaceInterface.class);
            for (Method method : classIndex.getMethods()) {
                configuration.addClientInterceptor(method, StatelessWriteReplaceInterceptor.factory(configuration.getViewServiceName().getCanonicalName()), InterceptorOrder.Client.WRITE_REPLACE);
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) Method(java.lang.reflect.Method) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 23 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class StatefulComponentDescription method addViewSerializationInterceptor.

private void addViewSerializationInterceptor(final ViewDescription view) {
    view.setSerializable(true);
    view.setUseWriteReplace(true);
    view.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            final DeploymentReflectionIndex index = context.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
            ClassReflectionIndex classIndex = index.getClassIndex(WriteReplaceInterface.class);
            for (Method method : (Collection<Method>) classIndex.getMethods()) {
                configuration.addClientInterceptor(method, new StatefulWriteReplaceInterceptor.Factory(configuration.getViewServiceName().getCanonicalName()), InterceptorOrder.Client.WRITE_REPLACE);
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ComponentInstanceInterceptorFactory(org.jboss.as.ee.component.ComponentInstanceInterceptorFactory) Method(java.lang.reflect.Method) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 24 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class ReflectionUtils method getGetter.

static Method getGetter(final List<ClassReflectionIndex> classHierarchy, final String propertyName) {
    final String getterName = "get" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
    final String iserName = "is" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
    for (final ClassReflectionIndex classIndex : classHierarchy) {
        final Iterator<Method> methods = classIndex.getMethods().iterator();
        Method method = null;
        String methodName = null;
        while (methods.hasNext()) {
            method = methods.next();
            methodName = method.getName();
            if ((getterName.equals(methodName) || iserName.equals(methodName)) && method.getParameterTypes().length == 0) {
                return method;
            }
        }
    }
    final String className = classHierarchy.get(0).getIndexedClass().getName();
    throw SarLogger.ROOT_LOGGER.propertyMethodNotFound("Get", propertyName, className);
}
Also used : ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) Method(java.lang.reflect.Method)

Example 25 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class ApplicationClientStartProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final ApplicationClientMetaData appClientData = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA);
    final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    //setup the callback handler
    final CallbackHandler callbackHandler;
    if (appClientData != null && appClientData.getCallbackHandler() != null && !appClientData.getCallbackHandler().isEmpty()) {
        try {
            final Class<?> callbackClass = ClassLoadingUtils.loadClass(appClientData.getCallbackHandler(), module);
            callbackHandler = new RealmCallbackWrapper((CallbackHandler) callbackClass.newInstance());
        } catch (ClassNotFoundException e) {
            throw AppClientLogger.ROOT_LOGGER.couldNotLoadCallbackClass(appClientData.getCallbackHandler());
        } catch (Exception e) {
            throw AppClientLogger.ROOT_LOGGER.couldNotCreateCallbackHandler(appClientData.getCallbackHandler());
        }
    } else {
        callbackHandler = new DefaultApplicationClientCallbackHandler();
    }
    Boolean activate = deploymentUnit.getAttachment(AppClientAttachments.START_APP_CLIENT);
    if (activate == null || !activate) {
        return;
    }
    final Class<?> mainClass = deploymentUnit.getAttachment(AppClientAttachments.MAIN_CLASS);
    if (mainClass == null) {
        throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName());
    }
    final ApplicationClientComponentDescription component = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT);
    Method mainMethod = null;
    Class<?> klass = mainClass;
    while (klass != Object.class) {
        final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(klass);
        mainMethod = index.getMethod(void.class, "main", String[].class);
        if (mainMethod != null) {
            break;
        }
        klass = klass.getSuperclass();
    }
    if (mainMethod == null) {
        throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName(), mainClass);
    }
    final ApplicationClientStartService startService;
    final List<SetupAction> setupActions = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.OTHER_EE_SETUP_ACTIONS);
    if (connectionPropertiesUrl != null) {
        try {
            final File file = new File(connectionPropertiesUrl);
            final URL url;
            if (file.exists()) {
                url = file.toURI().toURL();
            } else {
                url = new URL(connectionPropertiesUrl);
            }
            Properties properties = new Properties();
            InputStream stream = null;
            try {
                stream = url.openStream();
                properties.load(stream);
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException e) {
                    //ignore
                    }
                }
            }
            final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
                startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
            }
        } catch (Exception e) {
            throw AppClientLogger.ROOT_LOGGER.exceptionLoadingEjbClientPropertiesURL(connectionPropertiesUrl, e);
        }
    } else {
        startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions, hostUrl, callbackHandler);
    }
    phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ApplicationClientStartService.SERVICE_NAME), startService).addDependency(ApplicationClientDeploymentService.SERVICE_NAME, ApplicationClientDeploymentService.class, startService.getApplicationClientDeploymentServiceInjectedValue()).addDependency(component.getCreateServiceName(), Component.class, startService.getApplicationClientComponent()).install();
}
Also used : DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) Properties(java.util.Properties) URL(java.net.URL) RealmCallbackWrapper(org.jboss.as.appclient.service.RealmCallbackWrapper) ApplicationClientComponentDescription(org.jboss.as.appclient.component.ApplicationClientComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Component(org.jboss.as.ee.component.Component) InputStream(java.io.InputStream) DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) SetupAction(org.jboss.as.server.deployment.SetupAction) Method(java.lang.reflect.Method) IOException(java.io.IOException) ApplicationClientStartService(org.jboss.as.appclient.service.ApplicationClientStartService) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) File(java.io.File)

Aggregations

ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)29 Method (java.lang.reflect.Method)24 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)11 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)8 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)5 ViewDescription (org.jboss.as.ee.component.ViewDescription)5 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)5 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)5 Module (org.jboss.modules.Module)5 ArrayList (java.util.ArrayList)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)4 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)4 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)4 WriteReplaceInterface (org.jboss.as.ee.component.serialization.WriteReplaceInterface)4 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)4 Map (java.util.Map)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3