use of com.sun.enterprise.deployment.JndiNameEnvironment in project Payara by payara.
the class GlassFishInjectionProvider method getComponentEnvironment.
// --------------------------------------------------------- Private Methods
/**
* <p>
* This is based off of code in <code>InjectionManagerImpl</code>.
* </p>
*
* @return <code>JndiNameEnvironment</code>
* @throws InjectionException
* if we're unable to obtain the <code>JndiNameEnvironment</code>
*/
private JndiNameEnvironment getComponentEnvironment() throws InjectionException {
ComponentInvocation invocation = invocationManager.getCurrentInvocation();
if (invocation == null) {
throw new InjectionException("null invocation context");
}
if (invocation.getInvocationType() != SERVLET_INVOCATION) {
throw new InjectionException("Wrong invocation type");
}
JndiNameEnvironment componentEnvironment = (JndiNameEnvironment) invocation.getJndiEnvironment();
if (componentEnvironment == null) {
throw new InjectionException("No descriptor registered for " + " current invocation : " + invocation);
}
return componentEnvironment;
}
use of com.sun.enterprise.deployment.JndiNameEnvironment in project Payara by payara.
the class GlassFishInjectionProvider method getBundle.
private BundleDescriptor getBundle() {
JndiNameEnvironment componentEnvironment = compEnvManager.getCurrentJndiNameEnvironment();
BundleDescriptor bundle = null;
if (componentEnvironment instanceof BundleDescriptor) {
bundle = (BundleDescriptor) componentEnvironment;
}
if (bundle == null) {
throw new IllegalStateException("Invalid context for managed bean creation");
}
return bundle;
}
use of com.sun.enterprise.deployment.JndiNameEnvironment in project Payara by payara.
the class ClusteredCDIEventBusImpl method postConstruct.
@PostConstruct
void postConstruct() {
ctxUtil = Globals.getDefaultHabitat().getService(JavaEEContextUtil.class);
ExtendedDeploymentContext dc = Globals.getDefaultHabitat().getService(Deployment.class).getCurrentDeploymentContext();
ctxUtil.setInstanceComponentId(DOLUtils.getComponentEnvId((JndiNameEnvironment) DOLUtils.getCurrentBundleForContext(dc)));
try {
InitialContext ctx = new InitialContext();
managedExecutorService = (ManagedExecutorService) ctx.lookup("java:comp/DefaultManagedExecutorService");
} catch (NamingException ex) {
throw new RuntimeException(ex);
}
runtime.addCDIListener(this);
if (runtime.isClustered()) {
Logger.getLogger(ClusteredCDIEventBusImpl.class.getName()).log(Level.INFO, "Clustered CDI Event bus initialized");
}
}
use of com.sun.enterprise.deployment.JndiNameEnvironment in project Payara by payara.
the class ContextSetupProviderImpl method setup.
@Override
public ContextHandle setup(ContextHandle contextHandle) throws IllegalStateException {
if (!(contextHandle instanceof InvocationContext)) {
logger.log(Level.SEVERE, LogFacade.UNKNOWN_CONTEXT_HANDLE);
return null;
}
InvocationContext handle = (InvocationContext) contextHandle;
String appName = null;
if (handle.getInvocation() != null) {
appName = handle.getInvocation().getAppName();
}
if (appName == null && handle.getInvocation().getJNDIEnvironment() != null) {
appName = DOLUtils.getApplicationFromEnv((JndiNameEnvironment) handle.getInvocation().getJNDIEnvironment()).getName();
}
ClassLoader backupClassLoader = null;
if (appName == null) {
// try to get environment from component ID
if (handle.getInvocation().getComponentId() != null && compEnvMgr != null) {
JndiNameEnvironment currJndiEnv = compEnvMgr.getJndiNameEnvironment(handle.getInvocation().getComponentId());
if (currJndiEnv != null) {
com.sun.enterprise.deployment.Application appInfo = DOLUtils.getApplicationFromEnv(currJndiEnv);
if (appInfo != null) {
appName = appInfo.getName();
// cache JNDI environment
handle.getInvocation().setJNDIEnvironment(currJndiEnv);
backupClassLoader = appInfo.getClassLoader();
}
}
}
}
// Check whether the application component submitting the task is still running. Throw IllegalStateException if not.
if (!isApplicationEnabled(appName)) {
throw new IllegalStateException("Module " + appName + " is disabled");
}
ClassLoader resetClassLoader = null;
SecurityContext resetSecurityContext = null;
if (handle.getContextClassLoader() != null) {
resetClassLoader = Utility.setContextClassLoader(handle.getContextClassLoader());
} else if (backupClassLoader != null) {
resetClassLoader = Utility.setContextClassLoader(backupClassLoader);
}
if (handle.getSecurityContext() != null) {
resetSecurityContext = SecurityContext.getCurrent();
SecurityContext.setCurrent(handle.getSecurityContext());
}
ComponentInvocation invocation = handle.getInvocation();
if (invocation != null && !handle.isUseTransactionOfExecutionThread()) {
// Each invocation needs a ResourceTableKey that returns a unique hashCode for TransactionManager
invocation.setResourceTableKey(new PairKey(invocation.getInstance(), Thread.currentThread()));
invocationManager.preInvoke(invocation);
}
// Ensure that there is no existing transaction in the current thread
if (transactionManager != null) {
transactionManager.clearThreadTx();
}
if (requestTracing != null && requestTracing.isRequestTracingEnabled()) {
RequestTraceSpan span = constructConcurrentContextSpan(invocation);
requestTracing.startTrace(span);
}
if (stuckThreads != null) {
stuckThreads.registerThread(Thread.currentThread().getId());
}
return new InvocationContext(invocation, resetClassLoader, resetSecurityContext, handle.isUseTransactionOfExecutionThread());
}
use of com.sun.enterprise.deployment.JndiNameEnvironment in project Payara by payara.
the class ManagedBeanManagerImpl method getBundle.
private BundleDescriptor getBundle() {
ComponentEnvManager compEnvManager = habitat.getService(ComponentEnvManager.class);
JndiNameEnvironment env = compEnvManager.getCurrentJndiNameEnvironment();
BundleDescriptor bundle = null;
if (env instanceof BundleDescriptor) {
bundle = (BundleDescriptor) env;
} else if (env instanceof EjbDescriptor) {
bundle = (BundleDescriptor) ((EjbDescriptor) env).getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
}
if (bundle == null) {
throw new IllegalStateException("Invalid context for managed bean creation");
}
return bundle;
}
Aggregations