Is there a way to find out if a state is active without catching a ContextNotActiveException?

I would like to know if the context is included RequestScopedin the method or not.

Right now I'm doing this:

@Inject private BeanManager beanManager;

public boolean isRequestScopeActive() {
    try {
        if (beanManager.getContext(RequestScoped.class).isActive()) {
            return true;
        } else {
            return false;
        }
    } catch (final ContextNotActiveException e) {
        return false;
    }
}

It seems to me that it’s a little hard to catch ContextNotActiveExceptionto find out if the area is active or not.

Do you have a better way to find out the state (active or not) of a context in CDI?

+5
source share
1 answer

, , CDI 1.0, , ContextNotActiveException. , . . @Inject RequestScopedContextImpl rq; .isActive(), , .

+3

All Articles