private ComponentInvocation.ComponentInvocationType getCurrentComponentType() { return getCurrentComponentInvocation().getInvocationType(); }
private Object getEJBContextObject() { // Cannot store EjbContainerUtilImpl.getInstance() in an instance // variable because it shouldn't be accessed before EJB container // is initialized. // NamedNamingObjectProxy is initialized on the first lookup. ComponentInvocation currentInv = EjbContainerUtilImpl.getInstance().getCurrentInvocation(); if(currentInv == null) { throw new IllegalStateException("no current invocation"); } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { throw new IllegalStateException ("Illegal invocation type for EJB Context : " + currentInv.getInvocationType()); } return ((EjbInvocation) currentInv).context; } }
private Object getEJBContextObject() { // Cannot store EjbContainerUtilImpl.getInstance() in an instance // variable because it shouldn't be accessed before EJB container // is initialized. // NamedNamingObjectProxy is initialized on the first lookup. ComponentInvocation currentInv = EjbContainerUtilImpl.getInstance().getCurrentInvocation(); if(currentInv == null) { throw new IllegalStateException("no current invocation"); } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { throw new IllegalStateException ("Illegal invocation type for EJB Context : " + currentInv.getInvocationType()); } return ((EjbInvocation) currentInv).context; } }
public Object getEJBContextObject(String contextType) { ComponentInvocation currentInv = invMgr.getCurrentInvocation(); if(currentInv == null) { throw new IllegalStateException("no current invocation"); } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { throw new IllegalStateException ("Illegal invocation type for EJB Context : " + currentInv.getInvocationType()); } EjbInvocation ejbInv = (EjbInvocation) currentInv; Object returnObject = ejbInv.context; if( contextType.equals("javax.ejb.TimerService") ) { if (EJBTimerService.getEJBTimerService() == null ) { throw new IllegalStateException("EJB Timer Service not " + "available"); } returnObject = new EJBTimerServiceWrapper (EJBTimerService.getEJBTimerService(), (EJBContextImpl) ejbInv.context); } return returnObject; }
private Object getTimerServiceWrapper() { // Cannot store EjbContainerUtilImpl.getInstance() in an instance // variable because it shouldn't be accessed before EJB container // is initialized. // NamedNamingObjectProxy is initialized on the first lookup. ComponentInvocation currentInv = EjbContainerUtilImpl.getInstance().getCurrentInvocation(); if(currentInv == null) { throw new IllegalStateException("no current invocation"); } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { throw new IllegalStateException ("Illegal invocation type for EJB Context : " + currentInv.getInvocationType()); } EJBTimerService ejbTimerService = EJBTimerService.getEJBTimerService(); if( ejbTimerService == null ) { throw new IllegalStateException("EJB Timer Service not " + "available"); } return new EJBTimerServiceWrapper (ejbTimerService, (EJBContextImpl) ((EjbInvocation) currentInv).context); } }
private PhysicalEntityManagerWrapper findExtendedEMFromInvList(EntityManagerFactory emf) { PhysicalEntityManagerWrapper em = null; ComponentInvocation compInv = (ComponentInvocation) invocationManager.getCurrentInvocation(); if (compInv != null) { if (compInv.getInvocationType() == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { EjbInvocation ejbInv = (EjbInvocation) compInv; if (ejbInv.context instanceof SessionContextImpl) { SessionContextImpl ctxImpl = (SessionContextImpl) ejbInv.context; if (ctxImpl.container instanceof StatefulSessionContainer) { em = ctxImpl.getExtendedEntityManager(emf); } } } } return em; }
private EntityManager findExtendedEMFromInvList(EntityManagerFactory emf) { EntityManager em = null; ComponentInvocation compInv = (ComponentInvocation) invocationManager.getCurrentInvocation(); if (compInv != null) { if (compInv.getInvocationType() == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { EjbInvocation ejbInv = (EjbInvocation) compInv; if (ejbInv.context instanceof SessionContextImpl) { SessionContextImpl ctxImpl = (SessionContextImpl) ejbInv.context; if (ctxImpl.container instanceof StatefulSessionContainer) { em = ctxImpl.getExtendedEntityManager(emf); } } } } return em; }
/** * PreInvoke Transaction configuration for Servlet Container. * BaseContainer.preInvokeTx() handles all this for CMT EJB. * * Compensate that JavaEEInstanceListener.handleBeforeEvent( * BEFORE_SERVICE_EVENT) * gets called before WSIT WSTX Service pipe associates a JTA txn with * incoming thread. * * Precondition: assumes JTA transaction already associated with current * thread. */ public void preInvokeTx(boolean checkServletInvocation) { final ComponentInvocation inv = invocationManager.getCurrentInvocation(); if (inv != null && (!checkServletInvocation || inv.getInvocationType() == ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION)){ try { // Required side effect: note that // enlistComponentResources calls // ComponentInvocation.setTransaction(currentJTATxn). // If this is not correctly set, managed XAResource connections // are not auto enlisted when they are created. transactionManager.enlistComponentResources(); } catch (java.rmi.RemoteException re) { throw new IllegalStateException(re); } } }
public Object getEJBContextObject(String contextType) { ComponentInvocation currentInv = invMgr.getCurrentInvocation(); if(currentInv == null) { throw new IllegalStateException("no current invocation"); } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { throw new IllegalStateException ("Illegal invocation type for EJB Context : " + currentInv.getInvocationType()); } EjbInvocation ejbInv = (EjbInvocation) currentInv; Object returnObject = ejbInv.context; if( contextType.equals("javax.ejb.TimerService") ) { if (ejbContainerUtil == null) { ejbContainerUtil = habitat.getByContract(EjbContainerUtil.class); } if (ejbContainerUtil == null ) { throw new IllegalStateException("EJB Timer Service not " + "available. And EjbContainerUtil is null"); } if (ejbContainerUtil.getEJBTimerService() == null ) { throw new IllegalStateException("EJB Timer Service not " + "available"); } returnObject = new EJBTimerServiceWrapper (ejbContainerUtil.getEJBTimerService(), (EJBContextImpl) ejbInv.context); } return returnObject; }
private Object getTimerServiceWrapper() { // Cannot store EjbContainerUtilImpl.getInstance() in an instance // variable because it shouldn't be accessed before EJB container // is initialized. // NamedNamingObjectProxy is initialized on the first lookup. ComponentInvocation currentInv = EjbContainerUtilImpl.getInstance().getCurrentInvocation(); if(currentInv == null) { throw new IllegalStateException("no current invocation"); } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) { throw new IllegalStateException ("Illegal invocation type for EJB Context : " + currentInv.getInvocationType()); } EJBTimerService ejbTimerService = EjbContainerUtilImpl.getInstance().getEJBTimerService(); if( ejbTimerService == null ) { throw new IllegalStateException("EJB Timer Service not " + "available"); } return new EJBTimerServiceWrapper (ejbTimerService, (EJBContextImpl) ((EjbInvocation) currentInv).context); } }
public EntityManager lookupExtendedEntityManager(EntityManagerFactory emf) { EntityManager em = null; ComponentInvocation inv = invMgr.getCurrentInvocation(); if( (inv != null) && (inv.getInvocationType() == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION )) { Object obj = inv.getContainer(); if (obj instanceof JavaEEContainer) { em = ((JavaEEContainer) obj).lookupExtendedEntityManager(emf); } } return em; }
/** * PostInvoke Transaction configuration for Servlet Container. * BaseContainer.preInvokeTx() handles all this for CMT EJB. * * Precondition: assumed called prior to current transcation being * suspended or released. * * @param suspend indicate whether the delisting is due to suspension or * transaction completion(commmit/rollback) */ public void postInvokeTx(boolean suspend, boolean checkServletInvocation) { final ComponentInvocation inv = invocationManager.getCurrentInvocation(); if (inv != null && (!checkServletInvocation || inv.getInvocationType() == ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION)) { try { transactionManager.delistComponentResources(suspend); } catch (java.rmi.RemoteException re) { throw new IllegalStateException(re); } finally { inv.setTransaction(null); } } }
/** * 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(); } } }
if (inv.getInvocationType() == ComponentInvocationType.SERVICE_STARTUP) { v.setInvocationAttribute(ComponentInvocationType.SERVICE_STARTUP); return; ComponentInvocationType invType = inv.getInvocationType();
/** * Lookup physical EntityManagerFactory based on current component * invocation. * @param invMgr invocationmanager * @param emfUnitName unit name of entity manager factory or null if not * specified. * @return EntityManagerFactory or null if no matching factory could be * found. **/ static EntityManagerFactory lookupEntityManagerFactory(InvocationManager invMgr, ComponentEnvManager compEnvMgr, String emfUnitName) { ComponentInvocation inv = invMgr.getCurrentInvocation(); EntityManagerFactory emf = null; if( inv != null ) { Object desc = compEnvMgr.getCurrentJndiNameEnvironment(); if (desc != null) { emf = lookupEntityManagerFactory(inv.getInvocationType(), emfUnitName, desc); } } return emf; }
/** * Lookup physical EntityManagerFactory based on current component * invocation. * @param invMgr invocationmanager * @param emfUnitName unit name of entity manager factory or null if not * specified. * @return EntityManagerFactory or null if no matching factory could be * found. **/ static EntityManagerFactory lookupEntityManagerFactory(InvocationManager invMgr, ComponentEnvManager compEnvMgr, String emfUnitName) { ComponentInvocation inv = invMgr.getCurrentInvocation(); EntityManagerFactory emf = null; if( inv != null ) { Object desc = compEnvMgr.getCurrentJndiNameEnvironment(); if (desc != null) { emf = lookupEntityManagerFactory(inv.getInvocationType(), emfUnitName, desc); } } return emf; }
/** * <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 getNamingEnvironment() throws InjectionException { ComponentInvocation inv = invokeMgr.getCurrentInvocation(); if (inv != null) { if (inv.getInvocationType()== ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION) { JndiNameEnvironment componentEnv = (JndiNameEnvironment) inv.jndiEnvironment; if (componentEnv != null) { return componentEnv; } else { throw new InjectionException("No descriptor registered for " + " current invocation : " + inv); } } else { throw new InjectionException("Wrong invocation type"); } } else { throw new InjectionException("null invocation context"); } }
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; }
if (parentInv.getInvocationType() == ComponentInvocationType.SERVLET_INVOCATION) { inv.setComponentInvocationType(parentInv.getInvocationType()); inv.instance = null; inv.container = parentInv.getContainerContext(); inv.transaction = null; result.add(inv); } else if (parentInv.getInvocationType() != ComponentInvocationType.EJB_INVOCATION) { cpy.setComponentInvocationType(parentInv.getInvocationType()); cpy.instance = parentInv.getInstance(); cpy.container = parentInv.getContainerContext();
public boolean isUserInRole(String role) { WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance(); InvocationManager mgr = wscImpl.getInvocationManager(); if (ComponentInvocation.ComponentInvocationType.EJB_INVOCATION.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 != null && mgr.getCurrentInvocation() != null) { if (mgr.getCurrentInvocation().getContainer() instanceof WebModule) { Principal p = getUserPrincipal(); ret = secServ.isUserInRole((WebModule)mgr.getCurrentInvocation().getContainer(), p, servletName, role); } } } return ret; }