Notify the security collaborator for pre-invoke. This method handles
exception mapping for EJBSecurityCollaborator that throw
EJBAccessException rather than the legacy CSIAccessException.
965620
private Object notifySecurityCollaboratorPreInvoke(EJBSecurityCollaborator<?> collaborator, EJBRequestData request) throws CSIException {
        try {
            return collaborator.preInvoke(request);
        } catch (EJBAccessException ex) {
            // The CSI exception created here will eventually be mapped back to an
            // EJBAccessException, so avoid setting the cause so that we don't end
            // up with an EJBAccessException chained to an EJBAccessException.
            // Also, security actually throws an 'internal' subclass of
            // EJBAccessException that will not deserialize on a client.
            CSIAccessException csiEx = new CSIAccessException(ex.getMessage());
            csiEx.setStackTrace(ex.getStackTrace());
            throw csiEx;
        } catch (RuntimeException ex) {
            throw ex;
        } catch (CSIException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new CSIException("", ex);
        }
    }
205404
@Override
    public void onPrepareProviderResource(BeanCustomizerContext context) {

        EndpointInfo endpointInfo = context.getEndpointInfo();
        Set<ProviderResourceInfo> perRequestProviderAndPathInfos = endpointInfo.getPerRequestProviderAndPathInfos();
        Set<ProviderResourceInfo> singletonProviderAndPathInfos = endpointInfo.getSingletonProviderAndPathInfos();

        //The resources map may already exist on the context.  If it does we will want to add to it.
        Map<Class<?>, ManagedObject<?>> resourcesManagedbyCDI = (Map<Class<?>, ManagedObject<?>>)context.getContextObject();
        if (resourcesManagedbyCDI == null || !(resourcesManagedbyCDI instanceof ThreadBasedHashMap)) {
            resourcesManagedbyCDI = new ThreadBasedHashMap();//HashMap<Class<?>, ManagedObject<?>>();
        }

        CXFJaxRsProviderResourceHolder cxfPRHolder = context.getCxfRPHolder();
        for (ProviderResourceInfo p : perRequestProviderAndPathInfos) {
            /**
             * CDI customizer only check if the POJO type bean is CDI bean
             * because when EJB priority is higher than CDI, engine will take the bean as EJB but not CDI,
             * that means EJB already processes it, CDI should not process it again,
             * then CDI should not cache the bean's info in resourcesManagedbyCDI
             */
            if (p.getRuntimeType() != RuntimeType.POJO)
                continue;

            Class<?> clazz = p.getProviderResourceClass();
            if (!hasValidConstructor(clazz, false)) {
                continue;
            }

            Bean<?> bean = null;
            try {
                bean = getBeanFromCDI(clazz);
            } catch (Exception e1) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "ManagedObjectFactory failed to create bean", e1);
                }
            }

            if (bean != null) {

                String scopeName = bean.getScope().getName();
                p.setRuntimeType(RuntimeType.CDI);
                resourcesManagedbyCDI.put(p.getProviderResourceClass(), null);

                if (p.isJaxRsProvider()) {
                    //if CDI Scope is APPLICATION_SCOPE or DEPENDENT_SCOPE, report warning and no action: get provider from CDI
                    if (validSingletonScopeList.contains(scopeName)) {
                        logProviderMismatch(clazz, scopeName, "CDI");
                    }
                    //else report warning, keep using provider from rs: change to use RuntimeType.POJO
                    else {
                        p.setRuntimeType(RuntimeType.POJO);
                        resourcesManagedbyCDI.remove(p.getProviderResourceClass());
                        logProviderMismatch(clazz, scopeName, "JAXRS");
                    }
                } else {
                    if (!validRequestScopeList.contains(scopeName)) { //means this is @ApplicationScoped in CDI
                        logResourceMismatch(clazz, "PerRequest", scopeName, "CDI");
                    }

                }
            } else {

                if (shouldHandle(clazz, false)) {
                    p.setRuntimeType(RuntimeType.IMPLICITBEAN);
                    resourcesManagedbyCDI.put(clazz, null);
                }
                continue;

            }

        }
        for (ProviderResourceInfo o : singletonProviderAndPathInfos) {
            /**
             * CDI customizer only check if the POJO type bean is CDI bean
             * because when EJB priority is higher than CDI, engine will take the bean as EJB but not CDI,
             * that means EJB already processes it, CDI should not process it again,
             * then CDI should not cache the bean's info in resourcesManagedbyCDI
             */
            if (o.getRuntimeType() != RuntimeType.POJO)
                continue;

            Class<?> clazz = o.getProviderResourceClass();
            if (!hasValidConstructor(clazz, true)) {
                continue;
            }

            Bean<?> bean = null;
            try {
                bean = getBeanFromCDI(clazz);
            } catch (Exception e1) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "ManagedObjectFactory failed to create bean", e1);
                }
            }

            if (bean != null) {

                String scopeName = bean.getScope().getName();
                o.setRuntimeType(RuntimeType.CDI);
                resourcesManagedbyCDI.put(o.getProviderResourceClass(), null);
                if (o.isJaxRsProvider()) {
                    if (validSingletonScopeList.contains(scopeName)) {
                        logProviderMismatch(clazz, scopeName, "CDI");
                    }
                    //else report warning, keep using provider from rs: change to use RuntimeType.POJO
                    else {
                        o.setRuntimeType(RuntimeType.POJO);
                        resourcesManagedbyCDI.remove(clazz);
                        logProviderMismatch(clazz, scopeName, "JAXRS");
                    }

                    //Old check is this, need verify by using FAT:
                    //if CDI Scope is APPLICATION_SCOPE or DEPENDENT_SCOPE, report warning and no action: get provider from CDI
                    //else report warning and no action: get provider from CDI

                } else {
                    if (!validSingletonScopeList.contains(scopeName)) { // means CDI is per-request, then modify cxfPRHolder to per-request as well.
                        cxfPRHolder.removeResouceProvider(clazz);//remove from original ResourceProvider map and re-add the new one.
                        cxfPRHolder.addResouceProvider(clazz, new PerRequestResourceProvider(clazz));
                        logResourceMismatch(clazz, "Singleton", scopeName, "CDI");
                    }

                }
            } else {
                if (shouldHandle(clazz, false)) {
                    o.setRuntimeType(RuntimeType.IMPLICITBEAN);
                    resourcesManagedbyCDI.put(clazz, null);
                }
                continue;
            }

        }

        context.setContextObject(resourcesManagedbyCDI);

    }
1355264
void sessionError(final SibRaMessagingEngineConnection connection,
            final ConsumerSession session, final Throwable throwable) {

        final String methodName = "sessionError";
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, methodName, new Object[] { connection,
                    session });
        }

        final SIDestinationAddress destination = session
                .getDestinationAddress();

        if (_remoteDestination) {

            /*
             * Output a message to the admin console and attempt to create a new
             * listener
             */

            SibTr.warning(TRACE, "CONSUMER_FAILED_CWSIV0770", new Object[] {
                    destination.getDestinationName(),
                    _endpointConfiguration.getBusName(), this, throwable });

            try {

                createListener(connection);

            } catch (final ResourceException exception) {

                // No FFDC code needed

            }

        } else {

            if (SibRaEngineComponent.isMessagingEngineReloading(connection
                    .getConnection().getMeUuid())) {

                /*
                 * Output a warning to the admin console and close the
                 * connection - will be recreated during engineReloaded if
                 * required
                 */

                SibTr.warning(TRACE, "FAILURE_DURING_RELOAD_CWSIV0774",
                        new Object[] { throwable,
                                destination.getDestinationName(),
                                connection.getConnection().getMeName(),
                                destination.getBusName(), this });

                closeConnection(connection.getConnection().getMeUuid());

            } else {

                /*
                 * Output a message to the admin console and deactivate the
                 * endpoint
                 */

                SibTr.error(TRACE, "SESSION_ERROR_CWSIV0766", new Object[] {
                        throwable, destination.getDestinationName(),
                        connection.getConnection().getMeName(),
                        destination.getBusName(), this });

                deactivate();

            }

        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, methodName);
        }

    }
436914
@Override
    public void notifyException(Throwable exception)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "notifyException", new Object[] { this, exception });

        // If an asynch consumer is registered we need to let them know something went wrong
        if (_asynchConsumerRegistered)
            _asynchConsumer.notifyExceptionListeners(exception, _consumerSession);

        this.lock();
        try
        {
            if (_waiting)
            {
                // We need to get the exception back to the synchronous consumer
                _notifiedException = exception;
                _waiter.signal();
            }
        } finally
        {
            this.unlock();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "notifyException");
    }
523300
private void throwQException(final QConnectorException e) {
		this.executor.execute(new Runnable() {
			
			@Override
			public void run() {
				QConnectorAsyncImpl.this.listener.exception(e);
			}
		});
	}
623963
@Override
    public void associateConnection(
                                    Object connection,
                                    ManagedConnectionFactory mcf,
                                    ConnectionRequestInfo cri) throws ResourceException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "associateConnection");
        }
        /*
         * Get the subject information
         */
        Subject subject = (containerManagedAuth ? getFinalSubject(cri, mcf, this) : null);
        // Give the security helper a chance to finalize what subject
        // should be used. When ThreadIdentitySupport = NOTALLOWED the
        // original subject will be unchanged.

        //subject = securityHelper.finalizeSubject(subject, cri, inuseCM.cmConfig);
        /*
         * Call associate connection
         */
        associateConnection(mcf, subject, cri, connection);
        if (isTraceOn && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "associateConnection");
        }
    }
42047
@Override
  public void reportRemoteCoronaJobTracker(
      String attempt,
      String host,
      int port,
      String sessionId) throws IOException {
    TaskAttemptID attemptId = TaskAttemptID.forName(attempt);
    synchronized (this) {
      checkAttempt(attemptId);
      initializeClientUnprotected(host, port, sessionId);
      this.notifyAll();
    }
  }
684595
private void postInvokeRolledbackException(EJSDeployedSupport s, CSITransactionRolledbackException ex) throws RemoteException {
        //---------------------------------------------------------------
        // Check to see if the application requested that this transaction
        // be rolled back. If so, we can report no exception so suppress
        // the rollback exception here.
        // Only applies if the beginner bean called setRollbackOnly
        // during the business method.                            d186801
        // Or, if the beginner threw an Application Exception     d199884
        // Except, don't supress for ejbTimeout.                LI2281.07
        //---------------------------------------------------------------

        //d140003.19 d186801
        if ((!s.ivBeginnerSetRollbackOnly &&
             (!s.began ||
              s.exType != ExceptionType.CHECKED_EXCEPTION))
            ||
            s.methodInfo.ivInterface == MethodInterface.TIMED_OBJECT) { //90514;;
                                                                                                                                                                           //d140003.19
            final boolean isTraceOn = TraceComponent.isAnyTracingEnabled(); // d532639.2
            if (isTraceOn && tc.isEventEnabled())
                Tr.event(tc, "postInvoke: transaction rollback in finally",
                         ex); //93496

            // If an exception occurred during beforeCompletion, then override
            // the cause set by TranStrategy since that one will contain
            // superfluous RuntimeException wrappers.          d109641.1 d616849.2
            if (s.currentTx != null &&
                s.currentTx.ivPostProcessingException != null) {
                // If there was an exception during post processing
                // (commit), then set it as an unchecked exception.
                // This will not override any exception that occurred
                // during the bean method.        PQ90221 d219086 d219086.1
                s.getExceptionMappingStrategy().setUncheckedException(s, s.currentTx.ivPostProcessingException);
                ex.detail = s.getRootCause();
            } else if (ex.detail == null) {
                ex.detail = s.getRootCause();//d140003.19
            }
            //d171654 make sure CSITRBException root cause not overwritten
            else {
                //d174358.1---------->
                Throwable exceptionToUse = s.getRootCause();//d140003.19

                if (exceptionToUse == null) {
                    s.rootEx = s.getExceptionMappingStrategy().findRootCause(ex.detail);
                } else {
                    // we have a checked or unchecked so use that per spec
                    ex.detail = exceptionToUse;
                }
                //<----------d174358.1
            } //<--------d171654

            // Perform standard exception mapping using the exception
            // mapping utilities (just like EJSDeployedSupport). This
            // will wrap the CSI exception in a
            // TransactionRolledBackException, which is the exception
            // required by the EJB spec, then that will be mapped to
            // a CORBA TRANSACTION_ROLLEDBACK exception, as required
            // by the ORB.  The ORB should convert the
            // TRANSACTION_ROLLEDBACK to a TransactionRolledBackException
            // on the client.  Note that the root cause will be lost,
            // but will be embeded as part of the message text.  d109641.1
            Exception crex = s.mapCSITransactionRolledBackException(ex); //d140003.19             // d113344

            // The above result should always be a TRANSACTION_ROLLEDBACK,
            // but this is coded just in case mapException is changed in
            // the future.                                       d109641.1
            if (crex instanceof RemoteException)
                throw (RemoteException) crex;
            else if (crex instanceof RuntimeException)
                throw (RuntimeException) crex;
        }
    }
564783
public void doInvocationCollaboratorsPreInvoke(IInvocationCollaborator[] webAppInvocationCollaborators,
            com.ibm.wsspi.webcontainer.metadata.WebComponentMetaData cmd) {

    }
348858
protected void preInvoke(Method m, Object [] args, String [] interceptorNames)
        throws InterceptorPivotException
    {
        //
        // If the implementation expects single threaded behavior and our container does
        // not guarantee it, then enforce it locally here
        //
        if (_invokeLock != null)
        {
            try { _invokeLock.acquire(); } catch (InterruptedException ie) { }
        }

        //
        // Process interceptors
        //
        if ( interceptorNames != null )
        {
            for ( String n : interceptorNames )
            {
                Interceptor i = ensureInterceptor( n );
                try
                {
                    i.preInvoke( this, m, args );
                }
                catch (InterceptorPivotException ipe)
                {
                    ipe.setInterceptorName(n);
                    throw ipe;
                }
            }
        }

        Vector<InvokeListener> invokeListeners = getInvokeListeners();
        if (invokeListeners.size() > 0)
        {
            for (InvokeListener listener : invokeListeners)
                listener.preInvoke(m, args);
        }
    }
732201
final public boolean doesJaccNeedsEJBArguments(EJSWrapperBase wrapper) {
        // Default to false in case Security Collaborator is not defined
        EJBSecurityCollaborator<?> securityCollaborator = ivSecurityCollaborator;
        boolean result = securityCollaborator != null && securityCollaborator.areRequestMethodArgumentsRequired();

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "doesJaccNeedsEJBArguments returning " + result);

        return result;
    }
1363473
@Override
    public void discardObject(EJBCache wrapperCache, Object key, Object ele)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "discardObject", new Object[] { key, ele });

        EJSWrapperCommon wrapperCommon = (EJSWrapperCommon) ele;
        wrapperCommon.disconnect(); // @MD20022C, F58064

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "discardObject");
    }
1196782
@Override
    public final Object preInvoke(EJSDeployedSupport s,
                                  ContainerTx tx) // d139352-2
                    throws RemoteException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "preInvoke");

        setState(POOLED, IN_METHOD);

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "preInvoke");
        return ivEjbInstance;
    }
47581
private void deliverAsynchExceptionToClient(Throwable throwable, String probeId) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "deliverAsynchExceptionToClient", throwable);

        if (!isComplete()) {
            if (alarm != null) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(this, tc, "Cancelling the alarm: " + alarm.toString());
                alarm.cancel();
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(this, tc, "Alarm cancelled");
            }

            if (!isComplete()) {
                //Deregister listener as we are now done with our receive.
                //Deregistration will probably fail in most cases so ignore any exceptions.
                try {
                    final MPConsumerSession mpSession = (MPConsumerSession) mainConsumer.getConsumerSession();
                    mpSession.getConnection().removeConnectionListener(this);
                } catch (SIException s) {
                    //No FFDC code needed as everything has likely gone wrong already at this point.
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        SibTr.debug(this, tc, s.getMessage(), s);
                }

                sendErrorToClient(throwable, probeId);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "deliverAsynchExceptionToClient");
    }
912244
@Override
    public void postInvoke(WebSecurityContext webSecurityContext) throws AuthenticationException {
        AuthStatus status = null;
        if (webSecurityContext != null) {
            JaspiAuthContext jaspiContext = (JaspiAuthContext) webSecurityContext.getJaspiAuthContext();
            if (!jaspiContext.runSecureResponse()) {
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "postInvoke", "skip secureResponse.");
                return;
            }
            MessageInfo msgInfo = (MessageInfo) jaspiContext.getMessageInfo();
            ServerAuthContext authContext = (ServerAuthContext) jaspiContext.getServerAuthContext();
            Subject serviceSubject = webSecurityContext.getReceivedSubject();
            try {
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "secureResponse with Jaspi",
                             new Object[] { "authContext=" + authContext, "serviceSubject=" + serviceSubject, msgInfo });

                status = authContext.secureResponse(msgInfo, serviceSubject);
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "secureResponse status: " + status);

                // TODO Which reply or exception?
                if (AuthStatus.SEND_SUCCESS != status &&

                    AuthStatus.SEND_FAILURE != status &&

                    AuthStatus.SEND_CONTINUE != status) {

                    if (tc.isDebugEnabled())
                        Tr.debug(tc, "secureResponse  AuthStatus=" + status);
                    String msg = "Unexpected AuthStatus received during secureResponse() status=" + status
                                 + ", MessageInfo=" + msgInfo + ", ServerAuthContext=" + authContext;
                    throw new AuthenticationException(msg);
                }
            } catch (AuthException e) {
                /*
                 * The runtime must perform whatever processing it requires to complete the processing of a request that failed after
                 * (or during) service invocation, and prior to communicating the invocation result to the client runtime. The runtime
                 * may send (without calling secureResponse) an appropriate response message of its choice. If a failure message is
                 * returned, it should indicate that the failure in request processing occurred after the service invocation.
                 */
                throw new AuthenticationException("JASPI authentication failed after invoking the requested target service.", e);
            }
        }
    }
133493
@Override
    public Object faultOnKey(EJBCache cache, Object key)
                    throws FaultException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "faultOnKey", key);

        ByteArray wrapperKey = (ByteArray) key;
        EJSWrapperCommon result = null; // f111627

        // Check if the beanId is already set on this key in which case
        // we can avoid the deserialize
        BeanId beanId = wrapperKey.getBeanId();

        try
        {
            if (beanId == null) {
                beanId = BeanId.getBeanId(wrapperKey, container); // d140003.12
            }
            result = container.createWrapper(beanId);
        } catch (InvalidBeanIdException ex)
        {
            FFDCFilter.processException(ex, CLASS_NAME + ".faultOnKey", "533", this);

            // If the nested exception is an EJBNotFoundException, then report
            // that the app is not started/installed, rather than just the
            // generic 'Malformed object key'.                            d356676.1
            Throwable cause = ex.getCause();
            if (cause instanceof EJBNotFoundException)
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                    Tr.event(tc, "Application Not Started", ex);
                throw new FaultException((EJBNotFoundException) cause,
                                "Application not started or not installed");
            }
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                Tr.event(tc, "Malformed object key", ex);
            throw new FaultException(ex, "Malformed object key");
        } catch (Exception ex)
        {
            FFDCFilter.processException(ex, CLASS_NAME + ".faultOnKey", "548", this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                Tr.event(tc, "Malformed object key", ex);
            throw new FaultException(ex, "Malformed object key");
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "faultOnKey");

        return result;
    }
1349472
@Override
    public void reportException(JMSException e) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "reportException", e);
        if (elRef.get() != null) {
            asyncExceptionTask.handleException(e);
        }
        else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "No exception listener is currently set for this connection.");
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "reportException");
    }