Search in sources :

Example 6 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class TimerWrapper method checkCallPermission.

/**
 * Verify that Timer method access is allowed from this context.
 * This method is static so that TimerHandle can call it even
 * before it has created a TimerWrapper instance.
 */
private static void checkCallPermission() throws IllegalStateException {
    // Can't store a static ref because in embedded container it can be
    // changed by server restart
    EjbContainerUtil ejbContainerUtil = EjbContainerUtilImpl.getInstance();
    EJBTimerService timerService = EJBTimerService.getEJBTimerService();
    if (timerService == null) {
        throw new IllegalStateException("EJBTimerService is not available");
    }
    ComponentInvocation inv = ejbContainerUtil.getCurrentInvocation();
    if (inv == null) {
        throw new IllegalStateException("Invocation cannot be null");
    }
    ComponentInvocation.ComponentInvocationType invType = inv.getInvocationType();
    if (invType == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
        if (inv instanceof EjbInvocation) {
            ComponentContext context = ((EjbInvocation) inv).context;
            // Delegate check to EJB context.  Let any
            // IllegalStateException bubble up.
            context.checkTimerServiceMethodAccess();
        }
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentContext(com.sun.ejb.ComponentContext) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 7 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class J2EEInstanceListener method handleAfterEvent.

private void handleAfterEvent(InstanceEvent event, InstanceEvent.EventType eventType) {
    Wrapper wrapper = event.getWrapper();
    Context context = (Context) wrapper.getParent();
    if (!(context instanceof WebModule)) {
        return;
    }
    WebModule wm = (WebModule) context;
    Object instance;
    if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT) {
        instance = event.getFilter();
    } else {
        instance = event.getServlet();
    }
    if (instance == null) {
        return;
    }
    // Emit monitoring probe event
    if (instance instanceof Servlet) {
        if (eventType == InstanceEvent.EventType.AFTER_INIT_EVENT) {
            wm.servletInitializedEvent(wrapper.getName());
        } else if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
            wm.servletDestroyedEvent(wrapper.getName());
        }
    }
    // EE invocation context
    try {
        if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT && !DefaultServlet.class.equals(instance.getClass()) && !JspServlet.class.equals(instance.getClass())) {
            injectionMgr.destroyManagedObject(instance, false);
        }
    } catch (InjectionException ie) {
        String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
        msg = MessageFormat.format(msg, new Object[] { eventType, wm });
        _logger.log(Level.SEVERE, msg, ie);
    }
    ComponentInvocation inv = new WebComponentInvocation(wm, instance);
    try {
        im.postInvoke(inv);
    } catch (Exception ex) {
        String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
        msg = MessageFormat.format(msg, new Object[] { eventType, wm });
        throw new RuntimeException(msg, ex);
    } finally {
        if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
            if (tm != null) {
                tm.componentDestroyed(instance, inv);
            }
        } else if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT || eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
            // Emit monitoring probe event
            if (eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
                ServletResponse response = event.getResponse();
                int status = -1;
                if (response != null && response instanceof HttpServletResponse) {
                    status = ((HttpServletResponse) response).getStatus();
                }
                wm.afterServiceEvent(wrapper.getName(), status);
            }
            // BEGIN IASRI# 4646060
            if (im.getCurrentInvocation() == null) {
                // END IASRI# 4646060
                try {
                    // clear security context
                    Realm ra = context.getRealm();
                    if (ra != null && (ra instanceof RealmInitializer)) {
                        // cleanup not only securitycontext but also PolicyContext
                        ((RealmInitializer) ra).logout();
                    }
                } catch (Exception ex) {
                    String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
                    msg = MessageFormat.format(msg, new Object[] { eventType, wm });
                    _logger.log(Level.SEVERE, msg, ex);
                }
                if (tm != null) {
                    try {
                        if (tm.getTransaction() != null) {
                            tm.rollback();
                        }
                        tm.cleanTxnTimeout();
                    } catch (Exception ex) {
                    }
                }
            }
            if (tm != null) {
                tm.componentDestroyed(instance, inv);
            }
        }
    }
}
Also used : AppServSecurityContext(com.sun.enterprise.security.integration.AppServSecurityContext) ServerContext(org.glassfish.internal.api.ServerContext) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) RealmInitializer(com.sun.enterprise.security.integration.RealmInitializer) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebModule(com.sun.enterprise.web.WebModule) String(java.lang.String) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) JspServlet(org.apache.jasper.servlet.JspServlet) Servlet(javax.servlet.Servlet) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) DefaultServlet(org.apache.catalina.servlets.DefaultServlet)

Example 8 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class WebContainerListener method postInvoke.

private void postInvoke(WebModule ctx) {
    WebModule wm = (WebModule) ctx;
    ComponentInvocation inv = new WebComponentInvocation(wm);
    invocationMgr.postInvoke(inv);
}
Also used : WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebModule(com.sun.enterprise.web.WebModule)

Example 9 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class AbstractJMSContextManager method cleanup.

// Close and remove the JMSContext instances
@PreDestroy
public synchronized void cleanup() {
    ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
    InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
    ComponentInvocation currentInv = invMgr.getCurrentInvocation();
    for (Entry<String, JMSContextEntry> entry : contexts.entrySet()) {
        JMSContextEntry contextEntry = entry.getValue();
        String ipId = contextEntry.getInjectionPointId();
        JMSContext context = contextEntry.getCtx();
        if (context != null) {
            ComponentInvocation inv = contextEntry.getComponentInvocation();
            if (inv != null && currentInv != inv)
                invMgr.preInvoke(inv);
            try {
                context.close();
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, localStrings.getLocalString("JMSContext.impl.close", "Closed JMSContext instance associated with id {0}: {1}.", ipId, context.toString()));
                }
            } catch (Exception e) {
                logger.log(Level.SEVERE, localStrings.getLocalString("JMSContext.impl.close.failure", "Failed to close JMSContext instance associated with id {0}: {1}.", ipId, context.toString()), e);
            } finally {
                if (inv != null && currentInv != inv)
                    invMgr.postInvoke(inv);
            }
        }
    }
    contexts.clear();
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) JMSContext(javax.jms.JMSContext) PreDestroy(javax.annotation.PreDestroy)

Example 10 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation 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)

Aggregations

ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)67 InvocationManager (org.glassfish.api.invocation.InvocationManager)13 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)8 EjbInvocation (com.sun.ejb.EjbInvocation)7 InvocationException (org.glassfish.api.invocation.InvocationException)7 SecurityContext (com.sun.enterprise.security.SecurityContext)6 WebModule (com.sun.enterprise.web.WebModule)6 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)5 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)5 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)5 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)4 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)4 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)4 RemoteException (java.rmi.RemoteException)4 EJBInvocation (org.glassfish.ejb.api.EJBInvocation)4 ArrayList (java.util.ArrayList)3 NamingException (javax.naming.NamingException)3 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)3 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)3