public void createRequest(@Observes Before event, WeldManager manager) {
    BoundRequestContext requestContext = manager.instance().select(BoundRequestContext.class).get();

    CDIRequestMap map = new CDIRequestMap();
    requestContext.associate(map);
    requestContext.activate();
    requestMap.set(map);
  }
Esempio n. 2
0
  @Override
  public void requestInitialized(final ServletRequestEvent evt) {
    final BoundRequestContext ctx = CDI.current().select(BoundRequestContext.class).get();
    final Map<String, Object> instanceMap = new HashMap<>();

    final ServletRequest req = evt.getServletRequest();
    req.setAttribute(CDI_CONTEXT, ctx);
    req.setAttribute(CDI_INSTANCE_MAP, instanceMap);

    ctx.associate(instanceMap);
    ctx.activate();
  }
Esempio n. 3
0
  @SuppressWarnings("unchecked")
  public void setup(Map<String, Object> properties) {
    try {
      final BeanManager manager =
          (BeanManager) new InitialContext().lookup(STANDARD_BEAN_MANAGER_JNDI_NAME);

      if (manager != null && Container.available()) {

        final Bean<BoundSessionContext> sessionContextBean =
            (Bean<BoundSessionContext>)
                manager.resolve(manager.getBeans(BoundSessionContext.class, BoundLiteral.INSTANCE));
        CreationalContext<?> ctx = manager.createCreationalContext(sessionContextBean);
        final BoundSessionContext sessionContext =
            (BoundSessionContext)
                manager.getReference(sessionContextBean, BoundSessionContext.class, ctx);
        sessionContext.associate(sessionContexts.get());
        sessionContext.activate();

        final Bean<BoundRequestContext> requestContextBean =
            (Bean<BoundRequestContext>)
                manager.resolve(manager.getBeans(BoundRequestContext.class, BoundLiteral.INSTANCE));
        ctx = manager.createCreationalContext(requestContextBean);
        final BoundRequestContext requestContext =
            (BoundRequestContext)
                manager.getReference(requestContextBean, BoundRequestContext.class, ctx);
        requestContext.associate(requestContexts.get());
        requestContext.activate();

        final Bean<BoundConversationContext> conversationContextBean =
            (Bean<BoundConversationContext>)
                manager.resolve(
                    manager.getBeans(BoundConversationContext.class, BoundLiteral.INSTANCE));
        ctx = manager.createCreationalContext(conversationContextBean);
        final BoundConversationContext conversationContext =
            (BoundConversationContext)
                manager.getReference(conversationContextBean, BoundConversationContext.class, ctx);
        BoundRequest request =
            new MutableBoundRequest(requestContexts.get(), sessionContexts.get());
        boundRequests.set(request);
        conversationContext.associate(request);
        conversationContext.activate();
      }
    } catch (NamingException e) {
      log.error("Failed to setup Weld contexts", e);
    }
  }