Search in sources :

Example 16 with ViewDescription

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

the class StatelessComponentDescription 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, 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 17 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription 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 18 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription 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 19 with ViewDescription

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

the class EjbInjectionSource method resolve.

/**
     * Checks if this ejb injection has been resolved yet, and if not resolves it.
     */
private void resolve() {
    if (!resolved) {
        synchronized (this) {
            if (!resolved) {
                final Set<ViewDescription> views = getViews();
                final Set<EJBViewDescription> ejbsForViewName = new HashSet<EJBViewDescription>();
                for (final ViewDescription view : views) {
                    if (view instanceof EJBViewDescription) {
                        final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
                        // @EJB injection *shouldn't* consider the @WebService endpoint view or MDBs
                        if (viewType == MethodIntf.SERVICE_ENDPOINT || viewType == MethodIntf.MESSAGE_ENDPOINT) {
                            continue;
                        }
                        ejbsForViewName.add((EJBViewDescription) view);
                    }
                }
                if (ejbsForViewName.isEmpty()) {
                    if (beanName == null) {
                        error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, bindingName);
                    } else {
                        error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, beanName, bindingName);
                    }
                } else if (ejbsForViewName.size() > 1) {
                    if (beanName == null) {
                        error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, bindingName, ejbsForViewName);
                    } else {
                        error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, beanName, bindingName, ejbsForViewName);
                    }
                } else {
                    final EJBViewDescription description = ejbsForViewName.iterator().next();
                    final EJBViewDescription ejbViewDescription = (EJBViewDescription) description;
                    if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE || ejbViewDescription.getMethodIntf() == MethodIntf.HOME) {
                        final EJBComponentDescription componentDescription = (EJBComponentDescription) description.getComponentDescription();
                        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
                        final String earApplicationName = moduleDescription.getEarApplicationName();
                        final Value<ClassLoader> viewClassLoader = new Value<ClassLoader>() {

                            @Override
                            public ClassLoader getValue() throws IllegalStateException, IllegalArgumentException {
                                final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
                                return module != null ? module.getClassLoader() : null;
                            }
                        };
                        remoteFactory = new RemoteViewManagedReferenceFactory(earApplicationName, moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), description.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
                    }
                    final ServiceName serviceName = description.getServiceName();
                    resolvedViewName = serviceName;
                }
                resolved = true;
            }
        }
    }
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) Value(org.jboss.msc.value.Value) Module(org.jboss.modules.Module) HashSet(java.util.HashSet)

Example 20 with ViewDescription

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

the class JaxrsComponentDeployer method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (module == null) {
        return;
    }
    final ResteasyDeploymentData resteasy = deploymentUnit.getAttachment(JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA);
    if (resteasy == null) {
        return;
    }
    // right now I only support resources
    if (!resteasy.isScanResources())
        return;
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final ClassLoader loader = module.getClassLoader();
    for (final ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        Class<?> componentClass = null;
        try {
            componentClass = loader.loadClass(component.getComponentClassName());
        } catch (ClassNotFoundException e) {
            throw new DeploymentUnitProcessingException(e);
        }
        if (!GetRestful.isRootResource(componentClass))
            continue;
        if (isInstanceOf(component, SESSION_BEAN_DESCRIPTION_CLASS_NAME)) {
            if (isInstanceOf(component, STATEFUL_SESSION_BEAN_DESCRIPTION_CLASS_NAME)) {
                //using SFSB's as JAX-RS endpoints is not recommended, but if people really want to do it they can
                JAXRS_LOGGER.debugf("Stateful session bean %s is being used as a JAX-RS endpoint, this is not recommended", component.getComponentName());
                if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
                    //if possible just let CDI handle the integration
                    continue;
                }
            }
            Class<?>[] jaxrsType = GetRestful.getSubResourceClasses(componentClass);
            final String jndiName;
            if (component.getViews().size() == 1) {
                //only 1 view, just use the simple JNDI name
                jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
            } else {
                boolean found = false;
                String foundType = null;
                for (final ViewDescription view : component.getViews()) {
                    for (Class<?> subResource : jaxrsType) {
                        if (view.getViewClassName().equals(subResource.getName())) {
                            foundType = subResource.getName();
                            found = true;
                            break;
                        }
                    }
                    if (found) {
                        break;
                    }
                }
                if (!found) {
                    throw JAXRS_LOGGER.typeNameNotAnEjbView(Arrays.asList(jaxrsType), component.getComponentName());
                }
                jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName() + "!" + foundType;
            }
            JAXRS_LOGGER.debugf("Found JAX-RS Managed Bean: %s local jndi jaxRsTypeName: %s", component.getComponentClassName(), jndiName);
            StringBuilder buf = new StringBuilder();
            buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");
            resteasy.getScannedJndiComponentResources().add(buf.toString());
            // make sure its removed from list
            resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
        } else if (component instanceof ManagedBeanComponentDescription) {
            String jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
            JAXRS_LOGGER.debugf("Found JAX-RS Managed Bean: %s local jndi name: %s", component.getComponentClassName(), jndiName);
            StringBuilder buf = new StringBuilder();
            buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");
            resteasy.getScannedJndiComponentResources().add(buf.toString());
            // make sure its removed from list
            resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ViewDescription (org.jboss.as.ee.component.ViewDescription)21 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)15 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)15 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)14 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)14 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)14 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)14 Method (java.lang.reflect.Method)8 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)6 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)3 WriteReplaceInterface (org.jboss.as.ee.component.serialization.WriteReplaceInterface)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Module (org.jboss.modules.Module)3 HashSet (java.util.HashSet)2 ComponentView (org.jboss.as.ee.component.ComponentView)2 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)2 NamespaceViewConfigurator (org.jboss.as.ee.component.NamespaceViewConfigurator)2