@Override
 public Object processInvocation(final InterceptorContext context) throws Exception {
   final Object instance = context.getPrivateData(ComponentInstance.class).getInstance();
   try {
     return method.invoke(instance, context.getPrivateData(PARAMETERS_KEY));
   } catch (InvocationTargetException e) {
     throw Interceptors.rethrow(e.getCause());
   }
 }
  @Override
  public Object processInvocation(InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);

    // if a session bean is participating in a transaction, it
    // is an error for a client to invoke the remove method
    // on the session object's home or component interface.
    final ComponentView view = context.getPrivateData(ComponentView.class);
    if (view != null) {
      Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
      if (viewType != null) {
        // this means it is an EJB 2.x view
        // which is not allowed to remove while enrolled in a TX
        final StatefulTransactionMarker marker =
            context.getPrivateData(StatefulTransactionMarker.class);
        if (marker != null && !marker.isFirstInvocation()) {
          throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
        }
      }
    }
    // just log a WARN and throw back the original exception
    if (component instanceof StatefulSessionComponent == false) {
      throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
    }
    final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
    Object invocationResult = null;
    try {
      // proceed
      invocationResult = context.proceed();
    } catch (Exception e) {
      // Exception caught during call to @Remove method. Handle it appropriately

      // If it's an application exception and if the @Remove method has set "retainIfException" to
      // true
      // then just throw back the exception and don't remove the session instance.
      if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod())
          && this.retainIfException) {
        throw e;
      }
      // otherwise, just remove it and throw back the original exception
      final StatefulSessionComponentInstance statefulComponentInstance =
          (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
      final SessionID sessionId = statefulComponentInstance.getId();
      statefulComponent.removeSession(sessionId);
      throw e;
    }
    final StatefulSessionComponentInstance statefulComponentInstance =
        (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
    final SessionID sessionId = statefulComponentInstance.getId();
    // just remove the session because of a call to @Remove method
    statefulComponent.removeSession(sessionId);
    // return the invocation result
    return invocationResult;
  }
 public boolean wasCancelCalled() throws IllegalStateException {
   final CancellationFlag flag = context.getPrivateData(CancellationFlag.class);
   if (flag != null) {
     return flag.get();
   }
   return super.wasCancelCalled();
 }
 /**
  * Processes an incoming invocation and checks for the presence of a remote transaction associated
  * with the invocation context.
  *
  * @param context The invocation context
  * @return
  * @throws Exception
  */
 @Override
 public Object processInvocation(InterceptorContext context) throws Exception {
   final RemotingAttachments remotingAttachments =
       context.getPrivateData(RemotingAttachments.class);
   final TransactionManager transactionManager =
       this.ejbRemoteTransactionsRepository.getTransactionManager();
   Transaction originatingRemoteTx = null;
   if (remotingAttachments != null) {
     // get the transaction attachment
     final byte[] transactionIDBytes = remotingAttachments.getPayloadAttachment(0x0001);
     // A (remote) tx is associated with the invocation, so propogate it appropriately
     if (transactionIDBytes != null) {
       final TransactionID transactionID = TransactionID.createTransactionID(transactionIDBytes);
       // if it's UserTransaction then create or resume the UserTransaction corresponding to the ID
       if (transactionID instanceof UserTransactionID) {
         this.createOrResumeUserTransaction((UserTransactionID) transactionID);
       } else if (transactionID instanceof XidTransactionID) {
         this.createOrResumeXidTransaction((XidTransactionID) transactionID);
       }
       // the invocation was associated with a remote tx, so keep a flag so that we can
       // suspend (on this thread) the originating tx when returning from the invocation
       originatingRemoteTx = transactionManager.getTransaction();
     }
   }
   try {
     // we are done with any tx propogation setup, let's move on
     return context.proceed();
   } finally {
     // suspend the originating remote tx on this thread now that the invocation has been done
     if (originatingRemoteTx != null) {
       transactionManager.suspend();
     }
   }
 }
  @Override
  public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    try {

      return interceptorContext.proceed();
    } finally {
      StatefulSessionComponentInstance sfsb =
          (StatefulSessionComponentInstance)
              interceptorContext.getPrivateData(ComponentInstance.class);
      SFSBContextHandleImpl sfsbContextHandle = new SFSBContextHandleImpl(sfsb);
      List<EntityManager> readyToClose = SFSBXPCMap.getINSTANCE().remove(sfsbContextHandle);
      if (readyToClose != null && readyToClose.size() > 0) {
        for (EntityManager entityManager : readyToClose) {
          if (entityManager instanceof ExtendedEntityManager) {
            // TODO:  continue iterating through remaining entity managers and chain any exceptions
            ((ExtendedEntityManager) entityManager).containerClose();
          } else {
            throw new RuntimeException(
                "can only close SFSB XPC entity manager that are instances of ExtendedEntityManager"
                    + entityManager.getClass().getName());
          }
        }
      }
    }
  }
  /** @return The primary key of the current EJB, or null if not applicable */
  private Object currentPrimaryKey() {

    final InterceptorContext context = CurrentInvocationContext.get();

    if (context == null) {
      return null;
    }
    return context.getPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY);
  }
 @Override
 public Object getInstance() {
   // get the current invocation context and the EJBComponent out of it
   final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
   final EJBComponent ejbComponent =
       (EJBComponent) currentInvocationContext.getPrivateData(Component.class);
   if (ejbComponent == null) {
     throw MESSAGES.failToGetEjbComponent(currentInvocationContext);
   }
   return ejbComponent.getTimerService();
 }
 @Override
 public Object processInvocation(InterceptorContext context) throws Exception {
   final Method invokedMethod = context.getMethod();
   final ComponentViewInstance componentViewInstance =
       context.getPrivateData(ComponentViewInstance.class);
   // For a lifecycle interception, the ComponentViewInstance (and the invoked business interface)
   // will be null.
   // On a normal method invocation, the invoked business interface will be obtained from the
   // ComponentViewInstance
   final Class<?> invokedBusinessInterface =
       componentViewInstance == null ? null : componentViewInstance.getViewClass();
   Object[] parameters = context.getParameters();
   SessionInvocationContext sessionInvocationContext =
       new CustomSessionInvocationContext(
           lifecycleCallback, context, invokedBusinessInterface, invokedMethod, parameters);
   context.putPrivateData(InvocationContext.class, sessionInvocationContext);
   CurrentInvocationContext.push(sessionInvocationContext);
   try {
     return context.proceed();
   } finally {
     CurrentInvocationContext.pop();
     context.putPrivateData(InvocationContext.class, null);
   }
 }
Example #9
0
 public Object processInvocation(final InterceptorContext context) throws Exception {
   context.getPrivateData(ComponentViewInstance.class).destroy();
   return null;
 }
Example #10
0
 public Object processInvocation(final InterceptorContext context) throws Exception {
   ComponentView view = context.getPrivateData(ComponentView.class);
   return view.invoke(context);
 }
 protected SessionID getSessionIdOf(final InterceptorContext ctx) {
   final StatefulSessionComponentInstance instance =
       (StatefulSessionComponentInstance) ctx.getPrivateData(ComponentInstance.class);
   return instance.getId();
 }
 @Override
 public SessionContext getEJBContext() {
   return ((SessionBeanComponentInstance) context.getPrivateData(ComponentInstance.class))
       .getSessionContext();
 }
 @Override
 public SessionBeanComponent getComponent() {
   // return (SessionBeanComponent) super.getComponent();
   // this is faster
   return (SessionBeanComponent) context.getPrivateData(Component.class);
 }
 @Override
 public Object processInvocation(InterceptorContext context) throws Exception {
   return super.invoke(
       (TransactionalInvocationContext) context.getPrivateData(InvocationContext.class));
 }