@SuppressWarnings("unchecked") public static <C extends EJBContainer> C getEJBContainer(Invocation invocation) { // Because of Sun JDK we must cast it to something, or else there will be // no upper bound. return (C) EJBContainer.getEJBContainer(invocation.getAdvisor()); }
protected <C> C getContainer(Invocation invocation) { return (C) AbstractContainer.getContainer(invocation.getAdvisor()); }
protected <A extends Annotation> A getAnnotation(Invocation invocation, Method method, Class<A> annotationType) { Advisor advisor = invocation.getAdvisor(); A annotation = annotationType.cast(advisor.resolveAnnotation(method, annotationType)); if(annotation == null) annotation = annotationType.cast(advisor.resolveAnnotation(annotationType)); return annotation; }
private static TransactionAttributeType getTxType(Invocation invocation) { // Use the method tx attribute if we're invoking a business method, else the bean attribute Method method = null; if(invocation instanceof MethodInvocation) method = ((MethodInvocation) invocation).getActualMethod(); return getTxType(invocation.getAdvisor(), method); }
/** * Sets the TCCL to the classloader of the container so * that the invocation happens in the context of the * container's classloader. Finally upon return resets * the TCCL to the previous classloader. */ public Object invoke(Invocation invocation) throws Throwable { assert invocation instanceof EJBContainerInvocation : "Unexpected invocation type " + invocation.getClass() + " - expected " + EJBContainerInvocation.class; // get hold of the EJBContainer from the invocation EJBContainer ejbContainer = EJBContainer.getEJBContainer(invocation.getAdvisor()); ClassLoader ejbContainerClassloader = ejbContainer.getClassloader(); ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); // TODO: Review for security manager privileged blocks try { // Set the TCCL to the EJBContainer's classloader Thread.currentThread().setContextClassLoader(ejbContainerClassloader); // move on return invocation.invokeNext(); } finally { // reset to original TCCL Thread.currentThread().setContextClassLoader(previousClassLoader); } }
private static void check(String publicMethod, String specReferenceTxAttr) { // getRollbackOnly is not allowed during construction and injection EJB 3 4.4.1 and EJB 3 4.5.2 Invocation currentInvocation = CurrentInvocation.getCurrentInvocation(); if(currentInvocation == null) throw new IllegalStateException("It's not allowed to do " + publicMethod + " during construction and injection"); Advisor advisor = currentInvocation.getAdvisor(); String containerName = advisor.getName(); // EJB1.1 11.6.1: Must throw IllegalStateException if BMT TransactionManagementType type = TxUtil.getTransactionManagementType(advisor); if (type != TransactionManagementType.CONTAINER) throw new IllegalStateException("Container " + containerName + ": it is illegal to call " + publicMethod + " from BMT: " + type); if(isLifecycleCallback(currentInvocation)) throw new IllegalStateException(containerName + ": " + publicMethod + " not allowed during lifecycle callbacks (EJB3 4.4.1 & 4.5.2)"); // TODO: we should really ask a TxType object to handle getRollbackOnly() if(getTxType(currentInvocation) == TransactionAttributeType.SUPPORTS) throw new IllegalStateException(containerName + ": " + publicMethod + " not allowed with TransactionAttributeType.SUPPORTS (" + specReferenceTxAttr + ")"); }
protected static <T extends Annotation> T resolveAnnotation(Invocation invocation, Class<?> cls, Class<T> annotationType) { return ExtendedAdvisorHelper.getExtendedAdvisor(invocation.getAdvisor(), invocation.getTargetObject()).resolveAnnotation(cls, annotationType); } }
public static UserTransaction getUserTransaction(BeanContext<?> ctx) { Invocation invocation = CurrentInvocation.getCurrentInvocation(); // TODO: also not allowed during construction if(InvocationHelper.isInjection(invocation)) throw new IllegalStateException("getUserTransaction() not allowed during injection (EJB3 4.4.1 & 4.5.2)"); Advisor advisor = invocation.getAdvisor(); TransactionManagementType type = TxUtil.getTransactionManagementType(advisor); if (type != TransactionManagementType.BEAN) throw new IllegalStateException("Container " + advisor.getName() + ": it is illegal to inject UserTransaction into a CMT bean"); return new UserTransactionImpl(); }
/** * Checks if the passed exception is an application exception. If yes, then throws back the * exception as-is. Else, wraps the exception in a {@link EJBException} and throws the EJBException * * @param ex The exception to handle * @param invocation The invocation * @throws Exception Either the passed exception or an EJBException */ protected void handleException(Invocation invocation, Exception ex) throws Exception { if (ex == null) { return; } ApplicationException ae = (ApplicationException) invocation.getAdvisor().resolveAnnotation(ApplicationException.class); // it's an application exception, so just throw it back as-is if (ae != null) { throw ex; } if (ex instanceof EJBException) { throw (EJBException) ex; } else { throw new EJBException(ex); } } }
/** * @see org.jboss.aop.advice.Interceptor#invoke(org.jboss.aop.joinpoint.Invocation) */ public Object invoke(Invocation invocation) throws Throwable { EJBContainer container = EJBContainer.getEJBContainer(invocation.getAdvisor()); Lock lock = container.getInvocationLock(); // We intentionally do not use tryLock() since it does not respect lock fairness if (!lock.tryLock(0, TimeUnit.SECONDS)) { throw new DispatcherConnectException("EJB container is not completely started, or is stopped."); } try { return invocation.invokeNext(); } finally { lock.unlock(); } } }
public Object visit(ASTCFlow node, Object data) { AspectManager manager = null; if (invocation.getAdvisor() == null) manager = AspectManager.instance(); else manager = invocation.getAdvisor().getManager(); CFlowStack cflow = manager.getCFlowStack(node.getPointcutName()); //Use the current advisor to guess the classloader ClassLoader cl = invocation.getAdvisor().getClassLoader(); if (cl == null) { //Fall back to context classloader if null cl = SecurityActions.getContextClassLoader(); } if (cflow != null) return new Boolean(cflow.matches(getStack(), cl)); DynamicCFlow dcflow = manager.getDynamicCFlow(node.getPointcutName(), cl); return new Boolean(dcflow.shouldExecute(invocation)); } }
private InstanceAdvisor getInstanceAdvisor(Invocation invocation, Object targetObject) { if (targetObject instanceof Advised) { Advised advised = (Advised) targetObject; return advised._getInstanceAdvisor(); } Advisor advisor = invocation.getAdvisor(); if (advisor != null) { if (advisor instanceof InstanceAdvisor) { return (InstanceAdvisor) advisor; } if (advisor instanceof ClassProxyContainer && invocation instanceof ContainerProxyMethodInvocation) { ContainerProxyMethodInvocation pi = (ContainerProxyMethodInvocation)invocation; return pi.getProxy().getInstanceAdvisor(); } } return null; }
private InstanceAdvisor getInstanceAdvisor(Invocation invocation, Object targetObject) { if (targetObject instanceof Advised) { Advised advised = (Advised) targetObject; return advised._getInstanceAdvisor(); } Advisor advisor = invocation.getAdvisor(); if (advisor == null) { return null; } if (advisor instanceof InstanceAdvisor) { return (InstanceAdvisor) advisor; } if (advisor instanceof ClassProxyContainer && invocation instanceof ContainerProxyMethodInvocation) { ContainerProxyMethodInvocation pi = (ContainerProxyMethodInvocation)invocation; return pi.getProxy().getInstanceAdvisor(); } return null; }
public Object handleInvocation(Invocation invocation) throws Throwable { assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active"; String ejbName = invocation.getAdvisor().getName(); boolean exceptionThrown = false; try { return invocation.invokeNext(); } catch (Exception ex) { exceptionThrown = true; checkStatelessDone(invocation, ejbName, ex); throw ex; } finally { try { if (!exceptionThrown) checkStatelessDone(invocation, ejbName, null); } finally { tm.suspend(); } } }
public Object invoke(Invocation invocation) throws Throwable { if (lazyInterceptor == null) { synchronized (this) { if (lazyInterceptor == null) { if (factory.getType().isGeneratedOnly()) { lazyInterceptor = new GeneratedOnlyInterceptor(factory.getName(), factory); } else { lazyInterceptor = create(invocation.getAdvisor(), getJoinpoint(invocation)); if (lazyInterceptor == null) { lazyInterceptor = EMPTY_INTERCEPTOR; } } } } } return lazyInterceptor.invoke(invocation); }
String ejbName = invocation.getAdvisor().getName();
Advisor advisor = invocation.getAdvisor(); if (advisor == null)
Advisor advisor = invocation.getAdvisor(); if (advisor == null)
final Advisor advisor = invocation.getAdvisor(); final EJBContainer ejbContainer = EJBContainer.getEJBContainer(advisor); if (ejbContainer instanceof ServiceContainer || ejbContainer instanceof MessagingContainer)