Search in sources :

Example 21 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class EjbWsContext method getMessageContext.

@Override
public MessageContext getMessageContext() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final MessageContext messageContext = threadContext.get(MessageContext.class);
    if (messageContext == null) {
        throw new IllegalStateException("Only calls on the service-endpoint have a MessageContext.");
    }
    return messageContext;
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) MessageContext(javax.xml.ws.handler.MessageContext)

Example 22 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class EjbWsContext method getMessageContext.

public MessageContext getMessageContext() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final MessageContext messageContext = threadContext.get(MessageContext.class);
    if (messageContext == null) {
        throw new IllegalStateException("Only calls on the service-endpoint have a MessageContext.");
    }
    return messageContext;
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) MessageContext(javax.xml.ws.handler.MessageContext)

Example 23 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class EjbWsContext method getAddressingSupport.

private AddressingSupport getAddressingSupport() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final AddressingSupport wsaSupport = threadContext.get(AddressingSupport.class);
    if (wsaSupport == null) {
        throw new IllegalStateException("Only calls on the service-endpoint can get the EndpointReference.");
    }
    return wsaSupport;
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) AddressingSupport(org.apache.openejb.core.webservices.AddressingSupport)

Example 24 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class MdbInstanceFactory method freeInstance.

/**
     * Frees an instance no longer needed by the resource adapter.  This method makes all the necessary lifecycle
     * callbacks and decrements the instance count.  This method should not be used to disposed of beans that have
     * thrown a system exception.  Instead the discardInstance method should be called.
     *
     * @param instance             the bean instance to free
     * @param ignoredInstanceCount
     */
public void freeInstance(final Instance instance, final boolean ignoredInstanceCount) {
    if (instance == null) {
        throw new NullPointerException("bean is null");
    }
    // decrement the instance count
    if (!ignoredInstanceCount) {
        synchronized (this) {
            instanceCount--;
        }
    }
    final ThreadContext callContext = ThreadContext.getThreadContext();
    final Operation originalOperation = callContext == null ? null : callContext.getCurrentOperation();
    final BaseContext.State[] originalAllowedStates = callContext == null ? null : callContext.getCurrentAllowedStates();
    try {
        // call post destroy method
        if (callContext != null) {
            callContext.setCurrentOperation(Operation.PRE_DESTROY);
        }
        final Method remove = instance.bean instanceof MessageDrivenBean ? MessageDrivenBean.class.getMethod("ejbRemove") : null;
        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove, Operation.PRE_DESTROY, callbackInterceptors, instance.interceptors);
        interceptorStack.invoke();
        if (instance.creationalContext != null) {
            instance.creationalContext.release();
        }
    } catch (final Throwable re) {
        MdbInstanceFactory.logger.error("The bean instance " + instance.bean + " threw a system exception:" + re, re);
    } finally {
        if (callContext != null) {
            callContext.setCurrentOperation(originalOperation);
            callContext.setCurrentAllowedStates(originalAllowedStates);
        }
    }
}
Also used : MessageDrivenBean(javax.ejb.MessageDrivenBean) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) ThreadContext(org.apache.openejb.core.ThreadContext) Operation(org.apache.openejb.core.Operation) Method(java.lang.reflect.Method)

Example 25 with ThreadContext

use of org.apache.openejb.core.ThreadContext in project tomee by apache.

the class AbstractSecurityService method getCallerPrincipal.

@Override
public Principal getCallerPrincipal() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    if (threadContext == null) {
        final Identity id = clientIdentity.get();
        if (id != null) {
            return getCallerPrincipal(id.getSubject().getPrincipals());
        }
        return null;
    }
    final SecurityContext securityContext = threadContext.get(SecurityContext.class);
    final Set<Principal> principals = securityContext.subject.getPrincipals();
    return getCallerPrincipal(principals);
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) CallerPrincipal(org.apache.openejb.spi.CallerPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.openejb.core.security.jaas.GroupPrincipal)

Aggregations

ThreadContext (org.apache.openejb.core.ThreadContext)62 BeanContext (org.apache.openejb.BeanContext)33 Method (java.lang.reflect.Method)19 OpenEJBException (org.apache.openejb.OpenEJBException)18 ApplicationException (org.apache.openejb.ApplicationException)10 InterceptorStack (org.apache.openejb.core.interceptor.InterceptorStack)10 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)10 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)10 EJBException (javax.ejb.EJBException)9 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 RemoteException (java.rmi.RemoteException)7 SystemInstance (org.apache.openejb.loader.SystemInstance)7 BeanTransactionPolicy (org.apache.openejb.core.transaction.BeanTransactionPolicy)6 JtaTransactionPolicy (org.apache.openejb.core.transaction.JtaTransactionPolicy)6 ArrayList (java.util.ArrayList)5 EJBAccessException (javax.ejb.EJBAccessException)5 EJBHome (javax.ejb.EJBHome)5 EJBLocalHome (javax.ejb.EJBLocalHome)5 EJBLocalObject (javax.ejb.EJBLocalObject)5