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);
}
}
});
}
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);
}
}
});
}
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);
}
}
});
}
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;
}
}
}
}
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());
}
}
}
Aggregations