Search in sources :

Example 16 with BindingConfiguration

use of org.jboss.as.ee.component.BindingConfiguration in project wildfly by wildfly.

the class EjbJndiBindingsDeploymentUnitProcessor method registerControlPointBinding.

private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
    final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
    final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
    final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
    final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
    final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
    componentDescription.getConfigurators().add((context, description, configuration) -> {
        viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
        configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
    });
    //we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
    //as it will also reject local lookups as well, although in general local code should never be looking up the
    //exported bindings
    //the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
    final InjectionSource is = new InjectionSource() {

        @Override
        public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
            final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
            delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
            injector.inject(new ManagedReferenceFactory() {

                @Override
                public ManagedReference getReference() {
                    ControlPoint cp = controlPointInjectedValue.getValue();
                    try {
                        RunResult res = cp.beginRequest();
                        if (res != RunResult.RUN) {
                            throw EjbLogger.ROOT_LOGGER.containerSuspended();
                        }
                        try {
                            return delegateInjection.getValue().getReference();
                        } finally {
                            cp.requestComplete();
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
    };
    moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) ManagedReference(org.jboss.as.naming.ManagedReference) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) InjectionSource(org.jboss.as.ee.component.InjectionSource) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) RunResult(org.wildfly.extension.requestcontroller.RunResult) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 17 with BindingConfiguration

use of org.jboss.as.ee.component.BindingConfiguration in project wildfly by wildfly.

the class EjbRefProcessor method processDescriptorEntries.

/**
     * Resolves ejb-ref and ejb-local-ref elements
     *
     *
     * @param deploymentUnit
     * @param environment               The environment to resolve the elements for
     * @param componentDescription
     *@param classLoader               The deployment class loader
     * @param deploymentReflectionIndex The reflection index
     * @param applicationClasses    @return The bindings for the environment entries
     */
protected List<BindingConfiguration> processDescriptorEntries(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ResourceInjectionTarget resourceInjectionTarget, final ComponentDescription componentDescription, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
    List<BindingConfiguration> bindingDescriptions = new ArrayList<BindingConfiguration>();
    EJBReferencesMetaData ejbRefs = remoteEnvironment.getEjbReferences();
    if (ejbRefs != null) {
        for (EJBReferenceMetaData ejbRef : ejbRefs) {
            String name = ejbRef.getEjbRefName();
            String ejbName = ejbRef.getLink();
            String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
            String remoteInterface = ejbRef.getRemote();
            String home = ejbRef.getHome();
            Class<?> remoteInterfaceType = null;
            //if a home is specified this is the type that is bound
            if (!isEmpty(home)) {
                try {
                    remoteInterfaceType = ClassLoadingUtils.loadClass(home, deploymentUnit);
                } catch (ClassNotFoundException e) {
                    throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, home);
                }
            } else if (!isEmpty(remoteInterface)) {
                try {
                    remoteInterfaceType = ClassLoadingUtils.loadClass(remoteInterface, deploymentUnit);
                } catch (ClassNotFoundException e) {
                    throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, remoteInterface);
                }
            }
            if (!name.startsWith("java:")) {
                name = environment.getDefaultContext() + name;
            }
            // our injection (source) comes from the local (ENC) lookup, no matter what.
            LookupInjectionSource injectionSource = new LookupInjectionSource(name);
            //add any injection targets
            remoteInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, remoteInterfaceType);
            final BindingConfiguration bindingConfiguration;
            EjbInjectionSource ejbInjectionSource = null;
            if (!isEmpty(lookup)) {
                if (!lookup.startsWith("java:")) {
                    bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, remoteInterfaceType));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
                }
            } else {
                if (remoteInterfaceType == null) {
                    throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbRefForInjectionTarget(name, resourceInjectionTarget);
                }
                if (!isEmpty(ejbName)) {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, remoteInterfaceType.getName(), name, deploymentUnit, appclient));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(remoteInterfaceType.getName(), name, deploymentUnit, appclient));
                }
            }
            if (ejbInjectionSource != null) {
                deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
            }
            bindingDescriptions.add(bindingConfiguration);
        }
    }
    if (remoteEnvironment instanceof Environment && !appclient) {
        EJBLocalReferencesMetaData ejbLocalRefs = ((Environment) remoteEnvironment).getEjbLocalReferences();
        if (ejbLocalRefs != null) {
            for (EJBLocalReferenceMetaData ejbRef : ejbLocalRefs) {
                String name = ejbRef.getEjbRefName();
                String ejbName = ejbRef.getLink();
                String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
                String localInterface = ejbRef.getLocal();
                String localHome = ejbRef.getLocalHome();
                Class<?> localInterfaceType = null;
                //if a home is specified this is the type that is bound
                if (!isEmpty(localHome)) {
                    try {
                        localInterfaceType = ClassLoadingUtils.loadClass(localHome, deploymentUnit);
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localHome);
                    }
                } else if (!isEmpty(localInterface)) {
                    try {
                        localInterfaceType = ClassLoadingUtils.loadClass(localInterface, deploymentUnit);
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localInterface);
                    }
                }
                if (!name.startsWith("java:")) {
                    name = environment.getDefaultContext() + name;
                }
                // our injection (source) comes from the local (ENC) lookup, no matter what.
                LookupInjectionSource injectionSource = new LookupInjectionSource(name);
                //add any injection targets
                localInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, localInterfaceType);
                if (localInterfaceType == null) {
                    throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbLocalRefForInjectionTarget(name, resourceInjectionTarget);
                }
                final BindingConfiguration bindingConfiguration;
                EjbInjectionSource ejbInjectionSource = null;
                if (!isEmpty(lookup)) {
                    if (!lookup.startsWith("java:")) {
                        bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, localInterfaceType));
                    } else {
                        bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
                    }
                } else if (!isEmpty(ejbName)) {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, localInterfaceType.getName(), name, deploymentUnit, appclient));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(localInterfaceType.getName(), name, deploymentUnit, appclient));
                }
                if (ejbInjectionSource != null) {
                    deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
                }
                bindingDescriptions.add(bindingConfiguration);
            }
        }
    }
    return bindingDescriptions;
}
Also used : RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) EJBLocalReferenceMetaData(org.jboss.metadata.javaee.spec.EJBLocalReferenceMetaData) ArrayList(java.util.ArrayList) EJBReferenceMetaData(org.jboss.metadata.javaee.spec.EJBReferenceMetaData) Environment(org.jboss.metadata.javaee.spec.Environment) RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) EJBReferencesMetaData(org.jboss.metadata.javaee.spec.EJBReferencesMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) EJBLocalReferencesMetaData(org.jboss.metadata.javaee.spec.EJBLocalReferencesMetaData)

Example 18 with BindingConfiguration

use of org.jboss.as.ee.component.BindingConfiguration in project wildfly by wildfly.

the class DefaultDataSourceBindingProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (DeploymentTypeMarker.isType(EAR, deploymentUnit)) {
        return;
    }
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final String defaultDataSource = moduleDescription.getDefaultResourceJndiNames().getDataSource();
    if (defaultDataSource == null) {
        return;
    }
    final LookupInjectionSource injectionSource = new LookupInjectionSource(defaultDataSource);
    if (DeploymentTypeMarker.isType(WAR, deploymentUnit)) {
        moduleDescription.getBindingConfigurations().add(new BindingConfiguration(MODULE_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
    } else {
        if (DeploymentTypeMarker.isType(APPLICATION_CLIENT, deploymentUnit)) {
            moduleDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
        }
        for (ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
            if (componentDescription.getNamingMode() == ComponentNamingMode.CREATE) {
                componentDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 19 with BindingConfiguration

use of org.jboss.as.ee.component.BindingConfiguration in project wildfly by wildfly.

the class PersistenceRefProcessor method getPersistenceUnitRefs.

/**
     * Resolves persistence-unit-ref
     *
     * @param environment               The environment to resolve the elements for
     * @param classLoader               The deployment class loader
     * @param deploymentReflectionIndex The reflection index
     * @return The bindings for the environment entries
     */
private List<BindingConfiguration> getPersistenceUnitRefs(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
    final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
    if (environment.getEnvironment() == null) {
        return bindingConfigurations;
    }
    PersistenceUnitReferencesMetaData persistenceUnitRefs = environment.getEnvironment().getPersistenceUnitRefs();
    if (persistenceUnitRefs != null) {
        if (persistenceUnitRefs.size() > 0) {
            JPADeploymentMarker.mark(deploymentUnit);
        }
        for (PersistenceUnitReferenceMetaData puRef : persistenceUnitRefs) {
            String name = puRef.getName();
            String persistenceUnitName = puRef.getPersistenceUnitName();
            String lookup = puRef.getLookupName();
            if (!isEmpty(lookup) && !isEmpty(persistenceUnitName)) {
                throw JpaLogger.ROOT_LOGGER.cannotSpecifyBoth("<lookup-name>", lookup, "persistence-unit-name", persistenceUnitName, "<persistence-unit-ref/>", resourceInjectionTarget);
            }
            if (!name.startsWith("java:")) {
                name = environment.getDefaultContext() + name;
            }
            // our injection (source) comes from the local (ENC) lookup, no matter what.
            LookupInjectionSource injectionSource = new LookupInjectionSource(name);
            //add any injection targets
            processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, puRef, EntityManagerFactory.class);
            BindingConfiguration bindingConfiguration = null;
            if (!isEmpty(lookup)) {
                bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
            } else {
                InjectionSource puBindingSource = this.getPersistenceUnitBindingSource(deploymentUnit, persistenceUnitName);
                bindingConfiguration = new BindingConfiguration(name, puBindingSource);
            }
            bindingConfigurations.add(bindingConfiguration);
        }
    }
    return bindingConfigurations;
}
Also used : PersistenceUnitReferenceMetaData(org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData) PersistenceUnitReferencesMetaData(org.jboss.metadata.javaee.spec.PersistenceUnitReferencesMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) ArrayList(java.util.ArrayList) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource)

Example 20 with BindingConfiguration

use of org.jboss.as.ee.component.BindingConfiguration in project wildfly by wildfly.

the class JPAAnnotationProcessor method processMethod.

private void processMethod(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
    final String methodName = methodInfo.name();
    if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
        eeModuleClassDescription.setInvalid(JpaLogger.ROOT_LOGGER.setterMethodOnlyAnnotation(annotation.name().toString(), methodInfo));
        return;
    }
    final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4);
    final AnnotationValue declaredNameValue = annotation.value("name");
    final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
    final String localContextName;
    if (declaredName == null || declaredName.isEmpty()) {
        localContextName = methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix;
    } else {
        localContextName = declaredName;
    }
    final String injectionType = methodInfo.args()[0].name().toString();
    final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription);
    if (bindingSource != null) {
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource);
        eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration);
        // setup the injection configuration
        final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString());
        // source is always local ENC jndi name
        final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
        final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
        eeModuleClassDescription.addResourceInjection(injectionConfiguration);
    }
}
Also used : MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) AnnotationValue(org.jboss.jandex.AnnotationValue) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Aggregations

BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)25 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)15 InjectionSource (org.jboss.as.ee.component.InjectionSource)12 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)10 ArrayList (java.util.ArrayList)7 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)5 ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)5 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)5 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)5 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)5 FixedInjectionSource (org.jboss.as.ee.component.FixedInjectionSource)4 AnnotationValue (org.jboss.jandex.AnnotationValue)4 Module (org.jboss.modules.Module)4 HashMap (java.util.HashMap)3 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)3 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)3 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 EnvEntryInjectionSource (org.jboss.as.ee.component.EnvEntryInjectionSource)3 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)3