use of com.sun.enterprise.container.common.spi.ManagedBeanManager in project Payara by payara.
the class InternalInterceptorBindingImpl method registerInterceptor.
public void registerInterceptor(Object systemInterceptor) {
InvocationManager invManager = services.getService(InvocationManager.class);
ComponentInvocation currentInv = invManager.getCurrentInvocation();
if (currentInv == null) {
throw new IllegalStateException("no current invocation");
} else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION) {
throw new IllegalStateException("Illegal invocation type : " + currentInv.getInvocationType() + ". This operation is only available from a web app context");
}
ComponentEnvManager compEnvManager = services.getService(ComponentEnvManager.class);
JndiNameEnvironment env = compEnvManager.getCurrentJndiNameEnvironment();
BundleDescriptor webBundle = (BundleDescriptor) env;
ModuleDescriptor moduleDesc = webBundle.getModuleDescriptor();
// Register interceptor for EJB components
if (EjbContainerUtilImpl.isInitialized()) {
Collection<EjbBundleDescriptor> ejbBundles = moduleDesc.getDescriptor().getExtensionsDescriptors(EjbBundleDescriptor.class);
if (ejbBundles.size() == 1) {
EjbBundleDescriptor ejbBundle = ejbBundles.iterator().next();
for (EjbDescriptor ejb : ejbBundle.getEjbs()) {
BaseContainer container = EjbContainerUtilImpl.getInstance().getContainer(ejb.getUniqueId());
container.registerSystemInterceptor(systemInterceptor);
}
}
}
// Register interceptor for any managed beans
// TODO Handle 299-enabled case
ManagedBeanManager managedBeanManager = services.getService(ManagedBeanManager.class, "ManagedBeanManagerImpl");
managedBeanManager.registerRuntimeInterceptor(systemInterceptor, webBundle);
}
use of com.sun.enterprise.container.common.spi.ManagedBeanManager in project Payara by payara.
the class AppClientContainer method completePreparation.
/**
* Gets the ACC ready so the main class can run.
* This can be followed, immediately or after some time, by either an
* invocation of {@link #launch(java.lang.String[]) or
* by the JVM invoking the client's main method (as would happen during
* a <code>java -jar theClient.jar</code> launch.
*
* @throws java.lang.Exception
*/
private void completePreparation(final Instrumentation inst) throws NamingException, IOException, InstantiationException, IllegalAccessException, InjectionException, ClassNotFoundException, SAXParseException, NoSuchMethodException, UserError {
if (state != State.INSTANTIATED) {
throw new IllegalStateException();
}
/*
* Attach any names defined in the app client. Validate the descriptor
* first, then use it to bind names in the app client. This order is
* important - for example, to set up message destination refs correctly.
*/
client.validateDescriptor();
final ApplicationClientDescriptor desc = client.getDescriptor(classLoader);
componentId = componentEnvManager.bindToComponentNamespace(desc);
/*
* Arrange for cleanup now instead of during launch() because in some use cases
* the JVM will invoke the client's main method itself and launch will
* be skipped.
*/
cleanup = Cleanup.arrangeForShutdownCleanup(logger, habitat, desc);
/*
* Allow pre-destroy handling to work on the main class during clean-up.
*/
cleanup.setInjectionManager(injectionManager, clientMainClassSetting.clientMainClass);
/*
* If this app client contains persistence unit refs, then initialize
* the PU handling.
*/
Collection<? extends PersistenceUnitDescriptor> referencedPUs = desc.findReferencedPUs();
if (referencedPUs != null && !referencedPUs.isEmpty()) {
ProviderContainerContractInfoImpl pcci = new ProviderContainerContractInfoImpl((ACCClassLoader) getClassLoader(), inst, client.getAnchorDir(), connectorRuntime);
for (PersistenceUnitDescriptor puDesc : referencedPUs) {
PersistenceUnitLoader pul = new PersistenceUnitLoader(puDesc, pcci);
desc.addEntityManagerFactory(puDesc.getName(), pul.getEMF());
}
cleanup.setEMFs(pcci.emfs());
}
cleanup.setConnectorRuntime(connectorRuntime);
prepareURLStreamHandling();
// This is required for us to enable interrupt jaxws service
// creation calls
System.setProperty("javax.xml.ws.spi.Provider", "com.sun.enterprise.webservice.spi.ProviderImpl");
// InjectionManager's injectClass will be called from getMainMethod
// Load any managed beans
ManagedBeanManager managedBeanManager = habitat.getService(ManagedBeanManager.class);
managedBeanManager.loadManagedBeans(desc.getApplication());
cleanup.setManagedBeanManager(managedBeanManager);
/**
* We don't really need the main method here but we do need the side-effects.
*/
getMainMethod();
state = State.PREPARED;
}
use of com.sun.enterprise.container.common.spi.ManagedBeanManager in project Payara by payara.
the class InjectionManagerImpl method createManagedObject.
/**
* Create a managed object for the given class. The object will be injected and if invokePostConstruct is true,
* any @PostConstruct methods on the instance's class(and super-classes) will be invoked after injection. The returned
* object can be cast to the clazz type but is not necessarily a direct reference to the managed instance. All
* invocations on the returned object should be on its public methods.
*
* It is the responsibility of the caller to destroy the returned object by calling destroyManagedObject(Object
* managedObject).
*
* @param clazz
* Class to be instantiated
* @param invokePostConstruct
* if true, invoke any @PostConstruct methods on the instance's class(and super-classes) after injection.
* @return managed object
* @throws InjectionException
*/
public <T> T createManagedObject(Class<T> clazz, boolean invokePostConstruct) throws InjectionException {
T managedObject = null;
try {
ManagedBean managedBeanAnn = clazz.getAnnotation(ManagedBean.class);
ManagedBeanManager managedBeanMgr = serviceLocator.getService(ManagedBeanManager.class);
if (managedBeanAnn != null) {
// EE style @ManagedBean
// Create , inject, and call PostConstruct (if necessary) via managed bean manager
managedObject = managedBeanMgr.createManagedBean(clazz, invokePostConstruct);
} else {
JCDIService jcdiService = serviceLocator.getService(JCDIService.class);
if ((jcdiService != null) && jcdiService.isCurrentModuleJCDIEnabled()) {
// Create , inject, and call PostConstruct (if necessary) via managed bean manager
managedObject = managedBeanMgr.createManagedBean(clazz, invokePostConstruct);
} else {
// Not in a 299-enabled module and not annoated with @ManagedBean, so
// just instantiate using new and perform injection
Constructor<T> noArgCtor = clazz.getConstructor();
managedObject = noArgCtor.newInstance();
// Inject and call PostConstruct if necessary
injectInstance(managedObject, invokePostConstruct);
}
}
} catch (Exception e) {
throw new InjectionException(localStrings.getLocalString("injection-manager.error-creating-managed-object", "Error creating managed object for class: {0}", clazz), e);
}
return managedObject;
}
use of com.sun.enterprise.container.common.spi.ManagedBeanManager in project Payara by payara.
the class JavaModuleNamingProxy method getJavaModuleOrAppEJB.
private Object getJavaModuleOrAppEJB(String name) throws NamingException {
String newName = null;
Object returnValue = null;
if (habitat != null) {
ComponentEnvManager namingMgr = habitat.getService(ComponentEnvManager.class);
if (namingMgr != null) {
JndiNameEnvironment env = namingMgr.getCurrentJndiNameEnvironment();
BundleDescriptor bd = null;
if (env instanceof EjbDescriptor) {
bd = ((EjbDescriptor) env).getEjbBundleDescriptor();
} else if (env instanceof BundleDescriptor) {
bd = (BundleDescriptor) env;
}
if (bd != null) {
Application app = bd.getApplication();
String appName = null;
if (!app.isVirtual()) {
appName = app.getAppName();
}
String moduleName = bd.getModuleDescriptor().getModuleName();
StringBuffer javaGlobalName = new StringBuffer("java:global/");
if (name.startsWith(JAVA_APP_CONTEXT)) {
if (appName != null) {
javaGlobalName.append(appName);
javaGlobalName.append("/");
}
// Replace java:app/ with the fully-qualified global portion
int javaAppLength = JAVA_APP_CONTEXT.length();
javaGlobalName.append(name.substring(javaAppLength));
} else {
if (appName != null) {
javaGlobalName.append(appName);
javaGlobalName.append("/");
}
javaGlobalName.append(moduleName);
javaGlobalName.append("/");
// Replace java:module/ with the fully-qualified global portion
int javaModuleLength = JAVA_MODULE_CONTEXT.length();
javaGlobalName.append(name.substring(javaModuleLength));
}
newName = javaGlobalName.toString();
}
}
}
if (newName != null) {
try {
if (processType == ProcessType.ACC) {
ManagedBeanManager mbMgr = habitat.getService(ManagedBeanManager.class);
try {
returnValue = mbMgr.getManagedBean(newName);
} catch (Exception e) {
NamingException ne = new NamingException("Error creating ACC managed bean " + newName);
ne.initCause(e);
throw ne;
}
}
if (returnValue == null) {
returnValue = ic.lookup(newName);
}
} catch (NamingException ne) {
_logger.log(Level.FINE, newName + " Unable to map " + name + " to derived name " + newName, ne);
}
}
return returnValue;
}
use of com.sun.enterprise.container.common.spi.ManagedBeanManager in project Payara by payara.
the class ManagedBeanNamingProxy method create.
public Object create(javax.naming.Context ic) throws javax.naming.NamingException {
Object managedBean = null;
try {
ManagedBeanManager managedBeanMgr = habitat.getService(ManagedBeanManager.class);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
// Create managed bean instance
Class managedBeanClass = loader.loadClass(managedBeanDesc.getBeanClassName());
managedBean = managedBeanMgr.createManagedBean(managedBeanDesc, managedBeanClass);
} catch (Exception e) {
javax.naming.NamingException ne = new javax.naming.NamingException(e.getMessage());
ne.initCause(e);
throw ne;
}
return managedBean;
}
Aggregations