Search in sources :

Example 36 with InvocationManager

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

the class TransactionalInterceptorBase method getCurrentInvocation.

ComponentInvocation getCurrentInvocation() {
    ServiceLocator serviceLocator = Globals.getDefaultHabitat();
    InvocationManager invocationManager = serviceLocator == null ? null : serviceLocator.getService(InvocationManager.class);
    return invocationManager == null ? null : invocationManager.getCurrentInvocation();
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) InvocationManager(org.glassfish.api.invocation.InvocationManager)

Example 37 with InvocationManager

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

the class InjectionServicesImpl method aroundInject.

@Override
public <T> void aroundInject(InjectionContext<T> injectionContext) {
    try {
        ServiceLocator serviceLocator = Globals.getDefaultHabitat();
        ComponentEnvManager compEnvManager = serviceLocator.getService(ComponentEnvManager.class);
        EjbContainerServices containerServices = serviceLocator.getService(EjbContainerServices.class);
        JndiNameEnvironment componentEnv = compEnvManager.getCurrentJndiNameEnvironment();
        if (componentEnv == null) {
            InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
            if (invMgr.getCurrentInvocation() != null) {
                componentEnv = (JndiNameEnvironment) invMgr.<ComponentInvocation>getCurrentInvocation().getJNDIEnvironment();
            }
        }
        ManagedBeanDescriptor mbDesc = null;
        JndiNameEnvironment injectionEnv = (JndiNameEnvironment) bundleContext;
        AnnotatedType annotatedType = injectionContext.getAnnotatedType();
        Class targetClass = annotatedType.getJavaClass();
        String targetClassName = targetClass.getName();
        Object target = injectionContext.getTarget();
        if (isInterceptor(targetClass) && (componentEnv != null && !componentEnv.equals(injectionEnv))) {
            // Resources injected into interceptors must come from the environment in which the interceptor is
            // intercepting, not the environment in which the interceptor resides (for everything else!)
            // Must use the injectionEnv to get the injection info to determine where in jndi to look for the objects to inject.
            // must use the current jndi component env to lookup the objects to inject
            injectionManager.inject(targetClass, target, injectionEnv, null, false);
        } else {
            if (componentEnv == null) {
                // throw new IllegalStateException("No valid EE environment for injection of " + targetClassName);
                System.err.println("No valid EE environment for injection of " + targetClassName);
                injectionContext.proceed();
                return;
            }
            if (componentEnv instanceof EjbDescriptor) {
                EjbDescriptor ejbDesc = (EjbDescriptor) componentEnv;
                if (containerServices.isEjbManagedObject(ejbDesc, targetClass)) {
                    injectionEnv = componentEnv;
                } else {
                    if (bundleContext instanceof EjbBundleDescriptor) {
                        // Check if it's a @ManagedBean class within an ejb-jar.  In that case,
                        // special handling is needed to locate the EE env dependencies
                        mbDesc = bundleContext.getManagedBeanByBeanClass(targetClassName);
                    }
                }
            }
            if (mbDesc != null) {
                injectionManager.injectInstance(target, mbDesc.getGlobalJndiName(), false);
            } else {
                if (injectionEnv instanceof EjbBundleDescriptor) {
                    // set the environment of the ejb bundle.
                    if (target == null) {
                        injectionManager.injectClass(targetClass, compEnvManager.getComponentEnvId(injectionEnv), false);
                    } else {
                        injectionManager.injectInstance(target, compEnvManager.getComponentEnvId(injectionEnv), false);
                    }
                } else {
                    if (target == null) {
                        injectionManager.injectClass(targetClass, injectionEnv, false);
                    } else {
                        injectionManager.injectInstance(target, injectionEnv, false);
                    }
                }
            }
        }
        injectionContext.proceed();
    } catch (InjectionException ie) {
        throw new IllegalStateException(ie.getMessage(), ie);
    }
}
Also used : InvocationManager(org.glassfish.api.invocation.InvocationManager) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) EjbContainerServices(org.glassfish.ejb.api.EjbContainerServices) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException)

Example 38 with InvocationManager

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

the class Web109Adapter method beforeHandle.

@Override
protected void beforeHandle() {
    final InvocationManager invocationMgr = V3Module.getInvocationManager();
    invocationMgr.preInvoke(invocation);
}
Also used : InvocationManager(org.glassfish.api.invocation.InvocationManager)

Example 39 with InvocationManager

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

the class WebServiceContextImpl method isUserInRole.

public boolean isUserInRole(String role) {
    WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
    ComponentInvocation.ComponentInvocationType EJBInvocationType = ComponentInvocation.ComponentInvocationType.EJB_INVOCATION;
    InvocationManager mgr = wscImpl.getInvocationManager();
    if ((mgr != null) && (EJBInvocationType.equals(mgr.getCurrentInvocation().getInvocationType()))) {
        EJBInvocation inv = (EJBInvocation) mgr.getCurrentInvocation();
        boolean res = inv.isCallerInRole(role);
        return res;
    }
    // This is a servlet endpoint
    boolean ret = this.jaxwsContextDelegate.isUserInRole(role);
    // handling for webservice with WS-Security
    if (!ret && secServ != null) {
        if (mgr.getCurrentInvocation().getContainer() instanceof WebModule) {
            Principal p = getUserPrincipal();
            ret = secServ.isUserInRole((WebModule) mgr.getCurrentInvocation().getContainer(), p, servletName, role);
        }
    }
    return ret;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) EJBInvocation(org.glassfish.ejb.api.EJBInvocation) WebModule(com.sun.enterprise.web.WebModule) Principal(java.security.Principal)

Example 40 with InvocationManager

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

the class WebServiceContextImpl method getUserPrincipal.

public Principal getUserPrincipal() {
    // This could be an EJB endpoint; check the threadlocal variable
    Principal p = (Principal) principal.get();
    if (p != null) {
        return p;
    }
    // This is a servlet endpoint
    p = this.jaxwsContextDelegate.getUserPrincipal();
    // handling for WebService with WS-Security
    if (p == null && secServ != null) {
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        InvocationManager mgr = wscImpl.getInvocationManager();
        boolean isWeb = ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION.equals(mgr.getCurrentInvocation().getInvocationType()) ? true : false;
        p = secServ.getUserPrincipal(isWeb);
    }
    return p;
}
Also used : InvocationManager(org.glassfish.api.invocation.InvocationManager) Principal(java.security.Principal)

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