use of org.jboss.as.ejb3.component.EJBViewDescription in project wildfly by wildfly.
the class SessionBeanHomeProcessor method configureHome.
private void configureHome(final DeploymentPhaseContext phaseContext, final ComponentDescription componentDescription, final SessionBeanComponentDescription ejbComponentDescription, final EJBViewDescription homeView, final EJBViewDescription ejbObjectView) {
homeView.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
//loop over methods looking for create methods:
for (Method method : configuration.getProxyFactory().getCachedMethods()) {
if (method.getName().startsWith("create")) {
//we have a create method
if (ejbObjectView == null) {
throw EjbLogger.ROOT_LOGGER.invalidEjbLocalInterface(componentDescription.getComponentName());
}
Method initMethod = resolveInitMethod(ejbComponentDescription, method);
final SessionBeanHomeInterceptorFactory factory = new SessionBeanHomeInterceptorFactory(initMethod);
//add a dependency on the view to create
configuration.getDependencies().add(new DependencyConfigurator<ViewService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ViewService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(ejbObjectView.getServiceName(), ComponentView.class, factory.getViewToCreate());
}
});
//add the interceptor
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0 && ((EJBViewDescription) description).getMethodIntf() == MethodIntf.HOME) {
final Class<?> ejbObjectClass;
try {
ejbObjectClass = ClassLoadingUtils.loadClass(ejbObjectView.getViewClassName(), context.getDeploymentUnit());
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getComponentName());
}
final EjbMetadataInterceptor factory = new EjbMetadataInterceptor(ejbObjectClass, configuration.getViewClass().asSubclass(EJBHome.class), null, true, componentDescription instanceof StatelessComponentDescription);
//add a dependency on the view to create
componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
}
});
//add the interceptor
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(factory), InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, InvalidRemoveExceptionMethodInterceptor.FACTORY, InterceptorOrder.View.INVALID_METHOD_EXCEPTION);
} else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Handle.class) {
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, HomeRemoveInterceptor.FACTORY, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
}
}
}
});
}
use of org.jboss.as.ejb3.component.EJBViewDescription in project wildfly by wildfly.
the class EJBComponentDescription method setupRemoteViewInterceptors.
private void setupRemoteViewInterceptors(final EJBViewDescription view) {
if (view.getMethodIntf() == MethodIntf.REMOTE || view.getMethodIntf() == MethodIntf.HOME) {
view.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
configuration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.REMOTE_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
}
}
});
if (view.getMethodIntf() == MethodIntf.HOME) {
view.getConfigurators().add(new ViewConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
final String earApplicationName = componentConfiguration.getComponentDescription().getModuleDescription().getEarApplicationName();
configuration.setViewInstanceFactory(new RemoteHomeViewInstanceFactory(earApplicationName, componentConfiguration.getModuleName(), componentConfiguration.getComponentDescription().getModuleDescription().getDistinctName(), componentConfiguration.getComponentName()));
}
}
});
}
// add the remote tx propagating interceptor
view.getConfigurators().add(new EJBRemoteTransactionsViewConfigurator());
}
}
use of org.jboss.as.ejb3.component.EJBViewDescription in project wildfly by wildfly.
the class TransactionAttributeMergingProcessor method handleAnnotations.
@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
processTransactionAttributeAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
processTransactionTimeoutAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
for (ViewDescription view : componentConfiguration.getViews()) {
try {
final Class<?> viewClass = module.getClassLoader().loadClass(view.getViewClassName());
EJBViewDescription ejbView = (EJBViewDescription) view;
processTransactionAttributeAnnotation(applicationClasses, deploymentReflectionIndex, viewClass, ejbView.getMethodIntf(), componentConfiguration);
processTransactionTimeoutAnnotation(applicationClasses, deploymentReflectionIndex, viewClass, ejbView.getMethodIntf(), componentConfiguration);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadEjbViewClass(e);
}
}
}
use of org.jboss.as.ejb3.component.EJBViewDescription in project wildfly by wildfly.
the class EjbIIOPDeploymentUnitProcessor method processEjb.
private void processEjb(final EJBComponentDescription componentDescription, final DeploymentReflectionIndex deploymentReflectionIndex, final Module module, final ServiceTarget serviceTarget, final IIOPMetaData iiopMetaData) {
componentDescription.setExposedViaIiop(true);
// Create bean method mappings for container invoker
final EJBViewDescription remoteView = componentDescription.getEjbRemoteView();
final Class<?> remoteClass;
try {
remoteClass = ClassLoadingUtils.loadClass(remoteView.getViewClassName(), module);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
}
final EJBViewDescription homeView = componentDescription.getEjbHomeView();
final Class<?> homeClass;
try {
homeClass = ClassLoadingUtils.loadClass(homeView.getViewClassName(), module);
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
}
componentDescription.getEjbHomeView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
componentDescription.getEjbRemoteView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
final InterfaceAnalysis remoteInterfaceAnalysis;
try {
// TODO: change all this to use the deployment reflection index
remoteInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(remoteClass);
} catch (RMIIIOPViolationException e) {
throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
}
final Map<String, SkeletonStrategy> beanMethodMap = new HashMap<String, SkeletonStrategy>();
final AttributeAnalysis[] remoteAttrs = remoteInterfaceAnalysis.getAttributes();
for (int i = 0; i < remoteAttrs.length; i++) {
final OperationAnalysis op = remoteAttrs[i].getAccessorAnalysis();
if (op != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", op.getJavaName(), op.getIDLName());
// translate to the deployment reflection index method
// TODO: this needs to be fixed so it just returns the correct method
final Method method = translateMethod(deploymentReflectionIndex, op);
beanMethodMap.put(op.getIDLName(), new SkeletonStrategy(method));
final OperationAnalysis setop = remoteAttrs[i].getMutatorAnalysis();
if (setop != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", setop.getJavaName(), setop.getIDLName());
// translate to the deployment reflection index method
// TODO: this needs to be fixed so it just returns the correct method
final Method realSetmethod = translateMethod(deploymentReflectionIndex, setop);
beanMethodMap.put(setop.getIDLName(), new SkeletonStrategy(realSetmethod));
}
}
}
final OperationAnalysis[] ops = remoteInterfaceAnalysis.getOperations();
for (int i = 0; i < ops.length; i++) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", ops[i].getJavaName(), ops[i].getIDLName());
beanMethodMap.put(ops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, ops[i])));
}
// Initialize repository ids of remote interface
final String[] beanRepositoryIds = remoteInterfaceAnalysis.getAllTypeIds();
// Create home method mappings for container invoker
final InterfaceAnalysis homeInterfaceAnalysis;
try {
// TODO: change all this to use the deployment reflection index
homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeClass);
} catch (RMIIIOPViolationException e) {
throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
}
final Map<String, SkeletonStrategy> homeMethodMap = new HashMap<String, SkeletonStrategy>();
final AttributeAnalysis[] attrs = homeInterfaceAnalysis.getAttributes();
for (int i = 0; i < attrs.length; i++) {
final OperationAnalysis op = attrs[i].getAccessorAnalysis();
if (op != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", op.getJavaName(), op.getIDLName());
homeMethodMap.put(op.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, op)));
final OperationAnalysis setop = attrs[i].getMutatorAnalysis();
if (setop != null) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", setop.getJavaName(), setop.getIDLName());
homeMethodMap.put(setop.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, setop)));
}
}
}
final OperationAnalysis[] homeops = homeInterfaceAnalysis.getOperations();
for (int i = 0; i < homeops.length; i++) {
EjbLogger.DEPLOYMENT_LOGGER.debugf(" %s%n %s", homeops[i].getJavaName(), homeops[i].getIDLName());
homeMethodMap.put(homeops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, homeops[i])));
}
// Initialize repository ids of home interface
final String[] homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
final EjbIIOPService service = new EjbIIOPService(beanMethodMap, beanRepositoryIds, homeMethodMap, homeRepositoryIds, settingsService.isUseQualifiedName(), iiopMetaData, module);
final ServiceBuilder<EjbIIOPService> builder = serviceTarget.addService(componentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), service);
builder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
builder.addDependency(homeView.getServiceName(), ComponentView.class, service.getHomeView());
builder.addDependency(remoteView.getServiceName(), ComponentView.class, service.getRemoteView());
builder.addDependency(CorbaORBService.SERVICE_NAME, ORB.class, service.getOrb());
builder.addDependency(POARegistry.SERVICE_NAME, POARegistry.class, service.getPoaRegistry());
builder.addDependency(CorbaPOAService.INTERFACE_REPOSITORY_SERVICE_NAME, POA.class, service.getIrPoa());
builder.addDependency(CorbaNamingService.SERVICE_NAME, NamingContextExt.class, service.getCorbaNamingContext());
builder.addDependency(IORSecConfigMetaDataService.SERVICE_NAME, IORSecurityConfigMetaData.class, service.getIORSecConfigMetaDataInjectedValue());
builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoaderInjectedValue());
builder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, TransactionManagerService.class, service.getTransactionManagerInjectedValue());
builder.install();
}
use of org.jboss.as.ejb3.component.EJBViewDescription in project wildfly by wildfly.
the class EjbJndiBindingsDeploymentUnitProcessor method setupJNDIBindings.
/**
* Sets up jndi bindings for each of the views exposed by the passed <code>sessionBean</code>
*
* @param sessionBean The session bean
* @param deploymentUnit The deployment unit containing the session bean
*/
private void setupJNDIBindings(EJBComponentDescription sessionBean, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final Collection<ViewDescription> views = sessionBean.getViews();
if (views == null || views.isEmpty()) {
EjbLogger.DEPLOYMENT_LOGGER.noJNDIBindingsForSessionBean(sessionBean.getEJBName());
return;
}
// In case of Jakarta Enterprise Beans bindings, appname == .ear file name/application-name set in the application.xml (if it's an .ear deployment)
// NOTE: Do NOT use the app name from the EEModuleDescription.getApplicationName() because the Jakarta EE spec has a different and conflicting meaning for app name
// (where app name == module name in the absence of a .ear). Use EEModuleDescription.getEarApplicationName() instead
final String applicationName = sessionBean.getModuleDescription().getEarApplicationName();
// default to empty string
final String distinctName = sessionBean.getModuleDescription().getDistinctName();
final String globalJNDIBaseName = "java:global/" + (applicationName != null ? applicationName + "/" : "") + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
final String appJNDIBaseName = "java:app/" + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
final String moduleJNDIBaseName = "java:module/" + sessionBean.getEJBName();
final String remoteExportedJNDIBaseName = "java:jboss/exported/" + (applicationName != null ? applicationName + "/" : "") + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
final String ejbNamespaceBindingBaseName = "ejb:" + (applicationName != null ? applicationName : "") + "/" + sessionBean.getModuleName() + "/" + (!"".equals(distinctName) ? distinctName + "/" : "") + sessionBean.getEJBName();
// the base ServiceName which will be used to create the ServiceName(s) for each of the view bindings
final StringBuilder jndiBindingsLogMessage = new StringBuilder();
jndiBindingsLogMessage.append(System.lineSeparator()).append(System.lineSeparator());
// now create the bindings for each view under the java:global, java:app and java:module namespaces
EJBViewDescription ejbViewDescription = null;
for (ViewDescription viewDescription : views) {
boolean isEjbNamespaceBindingBaseName = false;
ejbViewDescription = (EJBViewDescription) viewDescription;
if (appclient && ejbViewDescription.getMethodIntf() != MethodIntf.REMOTE && ejbViewDescription.getMethodIntf() != MethodIntf.HOME) {
continue;
}
if (ejbViewDescription.getMethodIntf() != MethodIntf.REMOTE) {
isEjbNamespaceBindingBaseName = true;
}
if (!ejbViewDescription.hasJNDIBindings())
continue;
final String viewClassName = ejbViewDescription.getViewClassName();
// java:global bindings
final String globalJNDIName = globalJNDIBaseName + "!" + viewClassName;
registerBinding(sessionBean, viewDescription, globalJNDIName);
logBinding(jndiBindingsLogMessage, globalJNDIName);
// java:app bindings
final String appJNDIName = appJNDIBaseName + "!" + viewClassName;
registerBinding(sessionBean, viewDescription, appJNDIName);
logBinding(jndiBindingsLogMessage, appJNDIName);
// java:module bindings
final String moduleJNDIName = moduleJNDIBaseName + "!" + viewClassName;
registerBinding(sessionBean, viewDescription, moduleJNDIName);
logBinding(jndiBindingsLogMessage, moduleJNDIName);
// If it a remote or (remote) home view then bind the java:jboss/exported jndi names for the view
if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE || ejbViewDescription.getMethodIntf() == MethodIntf.HOME) {
final String remoteJNDIName = remoteExportedJNDIBaseName + "!" + viewClassName;
if (RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
registerControlPointBinding(sessionBean, viewDescription, remoteJNDIName, deploymentUnit);
} else {
registerBinding(sessionBean, viewDescription, remoteJNDIName);
}
logBinding(jndiBindingsLogMessage, remoteJNDIName);
}
// log Jakarta Enterprise Beans's ejb:/ namespace binding
final String ejbNamespaceBindingName = sessionBean.isStateful() ? ejbNamespaceBindingBaseName + "!" + viewClassName + "?stateful" : ejbNamespaceBindingBaseName + "!" + viewClassName;
if (!isEjbNamespaceBindingBaseName) {
logBinding(jndiBindingsLogMessage, ejbNamespaceBindingName);
}
}
// as can be seen by the examples in 4.4.2.1
if (views.size() == 1) {
final EJBViewDescription viewDescription = (EJBViewDescription) views.iterator().next();
if (ejbViewDescription.hasJNDIBindings()) {
// java:global binding
registerBinding(sessionBean, viewDescription, globalJNDIBaseName);
logBinding(jndiBindingsLogMessage, globalJNDIBaseName);
// java:app binding
registerBinding(sessionBean, viewDescription, appJNDIBaseName);
logBinding(jndiBindingsLogMessage, appJNDIBaseName);
// java:module binding
registerBinding(sessionBean, viewDescription, moduleJNDIBaseName);
logBinding(jndiBindingsLogMessage, moduleJNDIBaseName);
}
}
// log the jndi bindings
EjbLogger.DEPLOYMENT_LOGGER.jndiBindings(sessionBean.getEJBName(), deploymentUnit, jndiBindingsLogMessage);
}
Aggregations