Interface RequestContextController


public interface RequestContextController
The CDI container provides a built in instance of RequestContextController that is dependent scoped for the purposes of activating and deactivating. For example:
    @Inject
    private RequestContextController requestContextController;

    public void doRequest(String body) {
       // activate request context
       requestContextController.activate();

       // do work in a request context.

       // deactivate the request context
       requestContextController.deactivate();
    }
 
Once the request context has been deactivated, you may activate it once again, creating a brand new request context. The activated request context is bound to the current thread, any injection points targeting a request scoped bean will be satisfied with the same request scoped objects.
Since:
2.0
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Activates a RequestContext for the current thread if one is not already active.
    void
    Deactivates the current Request Context if it was activated by this context controller.
  • Method Details

    • activate

      boolean activate()
      Activates a RequestContext for the current thread if one is not already active.
      Returns:
      true if the context was activated by this invocation, false if not.
    • deactivate

      void deactivate() throws ContextNotActiveException
      Deactivates the current Request Context if it was activated by this context controller. If the context is active but was not activated by this controller, then it may not be deactivated by this controller, meaning this method will do nothing. If the context is not active, a ContextNotActiveException is thrown.
      Throws:
      ContextNotActiveException - if the context is not active