Search in sources :

Example 1 with JndiNameEnvironment

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;
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 2 with JndiNameEnvironment

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;
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment)

Example 3 with JndiNameEnvironment

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");
    }
}
Also used : JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) JavaEEContextUtil(org.glassfish.internal.api.JavaEEContextUtil) Deployment(org.glassfish.internal.deployment.Deployment) NamingException(javax.naming.NamingException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) InitialContext(javax.naming.InitialContext) PostConstruct(javax.annotation.PostConstruct)

Example 4 with JndiNameEnvironment

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());
}
Also used : JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) SecurityContext(com.sun.enterprise.security.SecurityContext) RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan)

Example 5 with JndiNameEnvironment

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;
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Aggregations

JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)14 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)8 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)7 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)6 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)5 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)4 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)3 ComponentEnvManager (com.sun.enterprise.container.common.spi.util.ComponentEnvManager)2 NamingException (javax.naming.NamingException)2 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)2 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)2 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)1 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)1 ManagedBeanDescriptor (com.sun.enterprise.deployment.ManagedBeanDescriptor)1 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)1 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)1 WebService (com.sun.enterprise.deployment.WebService)1 WebServicesDescriptor (com.sun.enterprise.deployment.WebServicesDescriptor)1 SecurityContext (com.sun.enterprise.security.SecurityContext)1 SystemHandlerDelegate (com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate)1