Search in sources :

Example 1 with InvocationManager

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

the class JavaEEContextUtilImpl method pushContext.

/**
 * pushes Java EE invocation context
 *
 * @return the new context
 */
@Override
public Context pushContext() {
    ClassLoader oldClassLoader = Utility.getClassLoader();
    InvocationManager invMgr = serverContext.getInvocationManager();
    boolean invocationCreated = false;
    if (invMgr.getCurrentInvocation() == null && capturedInvocation != null) {
        ComponentInvocation newInvocation = capturedInvocation.clone();
        newInvocation.clearRegistry();
        invMgr.preInvoke(newInvocation);
        invocationCreated = true;
    }
    if (invocationCreated) {
        Utility.setContextClassLoader(getInvocationClassLoader());
    }
    return new ContextImpl.Context(oldClassLoader, invocationCreated ? invMgr.getCurrentInvocation() : null, invMgr);
}
Also used : BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) ServerContext(org.glassfish.internal.api.ServerContext) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager)

Example 2 with InvocationManager

use of org.glassfish.api.invocation.InvocationManager 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);
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) ManagedBeanManager(com.sun.enterprise.container.common.spi.ManagedBeanManager)

Example 3 with InvocationManager

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

the class WebModuleListener method configureJsp.

// ------------------------------------------------------- Private Methods
/**
 * Configure all JSP related aspects of the web module, including
 * any relevant TLDs as well as the jsp config settings of the
 * JspServlet (using the values from sun-web.xml's jsp-config).
 */
private void configureJsp(WebModule webModule) {
    ServletContext servletContext = webModule.getServletContext();
    servletContext.setAttribute("org.glassfish.jsp.isStandaloneWebapp", Boolean.valueOf(webModule.isStandalone()));
    // Find tld URI and set it to ServletContext attribute
    List<URI> appLibUris = webModule.getDeployAppLibs();
    Map<URI, List<String>> appLibTldMap = new HashMap<URI, List<String>>();
    if (appLibUris != null && appLibUris.size() > 0) {
        Pattern pattern = Pattern.compile("META-INF/.*\\.tld");
        for (URI uri : appLibUris) {
            List<String> entries = JarURIPattern.getJarEntries(uri, pattern);
            if (entries != null && entries.size() > 0) {
                appLibTldMap.put(uri, entries);
            }
        }
    }
    Collection<TldProvider> tldProviders = webContainer.getTldProviders();
    Map<URI, List<String>> tldMap = new HashMap<URI, List<String>>();
    for (TldProvider tldProvider : tldProviders) {
        // Skip any JSF related TLDs for non-JSF apps
        if ("jsfTld".equals(tldProvider.getName()) && !webModule.isJsfApplication()) {
            continue;
        }
        Map<URI, List<String>> tmap = tldProvider.getTldMap();
        if (tmap != null) {
            tldMap.putAll(tmap);
        }
    }
    tldMap.putAll(appLibTldMap);
    servletContext.setAttribute("com.sun.appserv.tld.map", tldMap);
    /*
         * Discover all TLDs that are known to contain listener
         * declarations, and store the resulting map as a
         * ServletContext attribute
         */
    Map<URI, List<String>> tldListenerMap = new HashMap<URI, List<String>>();
    for (TldProvider tldProvider : tldProviders) {
        // Skip any JSF related TLDs for non-JSF apps
        if ("jsfTld".equals(tldProvider.getName()) && !webModule.isJsfApplication()) {
            continue;
        }
        Map<URI, List<String>> tmap = tldProvider.getTldListenerMap();
        if (tmap != null) {
            tldListenerMap.putAll(tmap);
        }
    }
    tldListenerMap.putAll(appLibTldMap);
    servletContext.setAttribute("com.sun.appserv.tldlistener.map", tldListenerMap);
    ServiceLocator defaultServices = webContainer.getServerContext().getDefaultServices();
    // set services for jsf injection
    servletContext.setAttribute(Constants.HABITAT_ATTRIBUTE, defaultServices);
    SunWebAppImpl bean = webModule.getIasWebAppConfigBean();
    // Find the default jsp servlet
    Wrapper wrapper = (Wrapper) webModule.findChild(org.apache.catalina.core.Constants.JSP_SERVLET_NAME);
    if (wrapper == null) {
        return;
    }
    if (webModule.getTldValidation()) {
        wrapper.addInitParameter("enableTldValidation", "true");
    }
    if (bean != null && bean.getJspConfig() != null) {
        WebProperty[] props = bean.getJspConfig().getWebProperty();
        for (int i = 0; i < props.length; i++) {
            String pname = props[i].getAttributeValue("name");
            String pvalue = props[i].getAttributeValue("value");
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, LogFacade.JSP_CONFIG_PROPERTY, "[" + webModule.getID() + "] is [" + pname + "] = [" + pvalue + "]");
            }
            wrapper.addInitParameter(pname, pvalue);
        }
    }
    // Override any log setting with the container wide logging level
    wrapper.addInitParameter("logVerbosityLevel", getJasperLogLevel());
    ResourceInjectorImpl resourceInjector = new ResourceInjectorImpl(webModule);
    servletContext.setAttribute("com.sun.appserv.jsp.resource.injector", resourceInjector);
    // START SJSAS 6311155
    String sysClassPath = ASClassLoaderUtil.getModuleClassPath((ServiceLocator) defaultServices, webModule.getID(), null);
    // If the configuration flag usMyFaces is set, remove javax.faces.jar
    // from the system class path
    Boolean useMyFaces = (Boolean) servletContext.getAttribute("com.sun.faces.useMyFaces");
    if (useMyFaces != null && useMyFaces) {
        sysClassPath = sysClassPath.replace("javax.faces.jar", "$disabled$.raj");
        // jsf-connector.jar manifest has a Class-Path to javax.faces.jar
        sysClassPath = sysClassPath.replace("jsf-connector.jar", "$disabled$.raj");
    }
    // servletContext.getAttribute(("org.apache.catalina.jsp_classpath")
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, LogFacade.SYS_CLASSPATH, webModule.getID() + " is " + sysClassPath);
    }
    if (sysClassPath.equals("")) {
        // In embedded mode, services returns SingleModulesRegistry and
        // it has no modules.
        // Try "java.class.path" system property instead.
        sysClassPath = System.getProperty("java.class.path");
    }
    sysClassPath = trimSysClassPath(sysClassPath);
    wrapper.addInitParameter("com.sun.appserv.jsp.classpath", sysClassPath);
    // END SJSAS 6311155
    // Configure JSP monitoring
    servletContext.setAttribute("org.glassfish.jsp.monitor.probeEmitter", new JspProbeEmitterImpl(webModule));
    // Pass BeanManager's ELResolver as ServletContext attribute
    // (see IT 11168)
    InvocationManager invocationMgr = webContainer.getInvocationManager();
    WebComponentInvocation inv = new WebComponentInvocation(webModule);
    try {
        invocationMgr.preInvoke(inv);
        JCDIService jcdiService = defaultServices.getService(JCDIService.class);
        // JCDIService can be absent if weld integration is missing in the runtime, so check for null is needed.
        if (jcdiService != null && jcdiService.isCurrentModuleJCDIEnabled()) {
            jcdiService.setELResolver(servletContext);
        }
    } catch (NamingException e) {
    // Ignore
    } finally {
        invocationMgr.postInvoke(inv);
    }
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) JarURIPattern(com.sun.enterprise.util.net.JarURIPattern) Pattern(java.util.regex.Pattern) JspProbeEmitterImpl(com.sun.enterprise.web.jsp.JspProbeEmitterImpl) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) JCDIService(com.sun.enterprise.container.common.spi.JCDIService) HashMap(java.util.HashMap) ResourceInjectorImpl(com.sun.enterprise.web.jsp.ResourceInjectorImpl) InvocationManager(org.glassfish.api.invocation.InvocationManager) URI(java.net.URI) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServletContext(javax.servlet.ServletContext) ArrayList(java.util.ArrayList) List(java.util.List) NamingException(javax.naming.NamingException) TldProvider(org.glassfish.api.web.TldProvider)

Example 4 with InvocationManager

use of org.glassfish.api.invocation.InvocationManager 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 5 with InvocationManager

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

the class AbstractJMSContextManager method getContext.

public synchronized JMSContext getContext(String ipId, String id, JMSContextMetadata metadata, ConnectionFactory connectionFactory) {
    JMSContextEntry contextEntry = contexts.get(id);
    JMSContext context = null;
    if (contextEntry == null) {
        context = createContext(ipId, metadata, connectionFactory);
        ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
        InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
        contexts.put(id, new JMSContextEntry(ipId, context, invMgr.getCurrentInvocation()));
    } else {
        context = contextEntry.getCtx();
    }
    return context;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) InvocationManager(org.glassfish.api.invocation.InvocationManager) JMSContext(javax.jms.JMSContext)

Aggregations

InvocationManager (org.glassfish.api.invocation.InvocationManager)40 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)13 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)9 NamingException (javax.naming.NamingException)9 Config (org.eclipse.microprofile.config.Config)8 InvocationException (org.glassfish.api.invocation.InvocationException)7 FallbackPolicy (fish.payara.microprofile.faulttolerance.interceptors.fallback.FallbackPolicy)5 AroundInvoke (javax.interceptor.AroundInvoke)5 Fallback (org.eclipse.microprofile.faulttolerance.Fallback)5 Retry (org.eclipse.microprofile.faulttolerance.Retry)5 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)5 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)4 ArrayList (java.util.ArrayList)4 NoSuchElementException (java.util.NoSuchElementException)4 EJBInvocation (org.glassfish.ejb.api.EJBInvocation)4 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)3 RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)3 Method (java.lang.reflect.Method)3 Context (javax.naming.Context)3 InitialContext (javax.naming.InitialContext)3