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());
}
}
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());
}
}
}
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);
}
}
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);
}
};
}
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());
}
}
Aggregations