Search in sources :

Example 1 with Conversation

use of javax.enterprise.context.Conversation in project wicket by apache.

the class ConversationPropagator method onUrlMapped.

@Override
public void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url) {
    // no need to propagate the conversation to packaged resources, they should never change
    if (handler instanceof ResourceReferenceRequestHandler) {
        if (((ResourceReferenceRequestHandler) handler).getResourceReference() instanceof PackageResourceReference) {
            return;
        }
    }
    Conversation conversation = getConversation(cycle);
    if (conversation == null || conversation.isTransient()) {
        return;
    }
    if (propagation.propagatesViaParameters(handler)) {
        // propagate cid to bookmarkable pages via urls
        logger.debug("Propagating non-transient conversation {} via url", conversation.getId());
        url.setQueryParameter(CID, conversation.getId());
    }
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) Conversation(javax.enterprise.context.Conversation)

Example 2 with Conversation

use of javax.enterprise.context.Conversation in project wicket by apache.

the class ConversationPropagator method onRequestHandlerScheduled.

@Override
public void onRequestHandlerScheduled(RequestCycle cycle, IRequestHandler handler) {
    // propagate current non-transient conversation to the newly scheduled page
    Conversation conversation = getConversation(cycle);
    if (conversation == null || conversation.isTransient()) {
        return;
    }
    Page page = getPage(handler);
    if (page != null) {
        if (propagation.propagatesViaPage(page, handler)) {
            // propagate a conversation across non-bookmarkable page instances
            setConversationOnPage(conversation, page);
        }
    }
    if (propagation.propagatesViaParameters(handler)) {
        // propagate cid to a scheduled bookmarkable page
        logger.debug("Propagating non-transient conversation {} via page parameters of handler {}", conversation.getId(), handler);
        PageParameters parameters = getPageParameters(handler);
        if (parameters != null) {
            parameters.set(CID, conversation.getId());
        }
    }
}
Also used : Conversation(javax.enterprise.context.Conversation) Page(org.apache.wicket.Page) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters)

Example 3 with Conversation

use of javax.enterprise.context.Conversation in project wicket by apache.

the class ConversationPropagator method onDetach.

@Override
public void onDetach(RequestCycle cycle) {
    Conversation conversation = getConversation(cycle);
    if (conversation != null) {
        logger.debug("Deactivating conversation {}", conversation.getId());
        for (IRequestCycleListener listener : application.getRequestCycleListeners()) {
            if (listener instanceof ICdiAwareRequestCycleListener) {
                ((ICdiAwareRequestCycleListener) listener).onBeforeConversationDeactivated(cycle);
            }
        }
        container.deactivateConversationalContext(cycle);
        cycle.setMetaData(CONVERSATION_STARTED_KEY, null);
    }
}
Also used : IRequestCycleListener(org.apache.wicket.request.cycle.IRequestCycleListener) Conversation(javax.enterprise.context.Conversation)

Example 4 with Conversation

use of javax.enterprise.context.Conversation in project core by weld.

the class ConversationPropagationFilter method wrapResponse.

private ServletResponse wrapResponse(HttpServletResponse response, final String requestPath) {
    return new HttpServletResponseWrapper(response) {

        @Override
        public void sendRedirect(String path) throws IOException {
            FacesContext context = FacesContext.getCurrentInstance();
            if (context != null) {
                // this is a JSF request
                ConversationContext conversationContext = instance(contextId).select(HttpConversationContext.class).get();
                if (conversationContext.isActive()) {
                    Conversation conversation = conversationContext.getCurrentConversation();
                    if (!conversation.isTransient()) {
                        path = new FacesUrlTransformer(path, context).toRedirectViewId().toActionUrl().appendConversationIdIfNecessary(conversationContext.getParameterName(), conversation.getId()).encode();
                    }
                }
            }
            super.sendRedirect(path);
        }
    };
}
Also used : FacesContext(javax.faces.context.FacesContext) FacesUrlTransformer(org.jboss.weld.module.jsf.FacesUrlTransformer) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) Conversation(javax.enterprise.context.Conversation) HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext) ConversationContext(org.jboss.weld.context.ConversationContext) HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext)

Example 5 with Conversation

use of javax.enterprise.context.Conversation in project core by weld.

the class ConversationTestPhaseListener method beforePhase.

public void beforePhase(PhaseEvent event) {
    BeanManagerImpl beanManager;
    try {
        beanManager = BeanManagerProxy.unwrap((BeanManager) new InitialContext().lookup("java:comp/BeanManager"));
    } catch (NamingException e) {
        throw new RuntimeException("Error looking up java:comp/BeanManager ", e);
    }
    if (event.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES)) {
        try {
            beanManager.getContext(ConversationScoped.class);
            activeBeforeApplyRequestValues = true;
        } catch (ContextNotActiveException e) {
            activeBeforeApplyRequestValues = false;
        }
    }
    if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
        Conversation conversation = beanManager.instance().select(Conversation.class).get();
        HttpServletResponse response = (HttpServletResponse) event.getFacesContext().getExternalContext().getResponse();
        response.addHeader(CID_HEADER_NAME, conversation.getId() == null ? " null" : conversation.getId());
        response.addHeader(LONG_RUNNING_HEADER_NAME, String.valueOf(!conversation.isTransient()));
        response.addHeader(Cloud.RAINED_HEADER_NAME, new Boolean(beanManager.instance().select(Cloud.class).get().isRained()).toString());
        response.addHeader(ACTIVE_BEFORE_APPLY_REQUEST_VALUES_HEADER_NAME, new Boolean(activeBeforeApplyRequestValues).toString());
    }
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) HttpServletResponse(javax.servlet.http.HttpServletResponse) NamingException(javax.naming.NamingException) Conversation(javax.enterprise.context.Conversation) BeanManager(javax.enterprise.inject.spi.BeanManager) InitialContext(javax.naming.InitialContext)

Aggregations

Conversation (javax.enterprise.context.Conversation)9 Page (org.apache.wicket.Page)3 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)3 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)2 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)1 NonexistentConversationException (javax.enterprise.context.NonexistentConversationException)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 FacesContext (javax.faces.context.FacesContext)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)1 IRequestCycleListener (org.apache.wicket.request.cycle.IRequestCycleListener)1 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)1 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)1 ConversationContext (org.jboss.weld.context.ConversationContext)1 BoundConversationContext (org.jboss.weld.context.bound.BoundConversationContext)1 BoundRequest (org.jboss.weld.context.bound.BoundRequest)1