use of org.jboss.weld.context.ConversationContext 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 org.jboss.weld.context.ConversationContext in project core by weld.
the class ConversationContextActivator method deactivateConversationContext.
protected void deactivateConversationContext(HttpServletRequest request) {
try {
ConversationContext conversationContext = httpConversationContext();
if (conversationContext.isActive()) {
// Only deactivate the context if one is already active, otherwise we get Exceptions
if (conversationContext instanceof LazyHttpConversationContextImpl) {
LazyHttpConversationContextImpl lazyConversationContext = (LazyHttpConversationContextImpl) conversationContext;
if (!lazyConversationContext.isInitialized()) {
// if this lazy conversation has not been touched yet, just deactivate it
lazyConversationContext.deactivate();
processDestructionQueue(request);
return;
}
}
boolean isTransient = conversationContext.getCurrentConversation().isTransient();
if (ConversationLogger.LOG.isTraceEnabled()) {
if (isTransient) {
ConversationLogger.LOG.cleaningUpTransientConversation();
} else {
ConversationLogger.LOG.cleaningUpConversation(conversationContext.getCurrentConversation().getId());
}
}
if (isTransient) {
conversationBeforeDestroyedEvent.fire(request);
}
conversationContext.invalidate();
conversationContext.deactivate();
if (isTransient) {
conversationDestroyedEvent.fire(request);
}
processDestructionQueue(request);
}
} catch (Exception e) {
ServletLogger.LOG.unableToDeactivateContext(httpConversationContext(), request);
ServletLogger.LOG.catchingDebug(e);
}
}
use of org.jboss.weld.context.ConversationContext in project core by weld.
the class ContextTest method testCallToConversationWithContextNotActive.
/*
* description = "WELD-348"
*/
@Test
public void testCallToConversationWithContextNotActive() {
ConversationContext conversationContext;
try {
conversationContext = Utils.getActiveContext(beanManager, ConversationContext.class);
} catch (ContextNotActiveException e) {
conversationContext = Utils.getReference(beanManager, HttpConversationContext.class);
}
new WorkInInactiveContext(conversationContext) {
@Override
protected void work() {
try {
Utils.getReference(beanManager, Conversation.class).getId();
Assert.fail("Expected ContextNotActiveException, but no exception was thrown");
} catch (ContextNotActiveException e) {
// Expected
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Expected ContextNotActiveException, but another exception was thrown: " + e);
}
try {
Utils.getReference(beanManager, Conversation.class).getTimeout();
Assert.fail();
} catch (ContextNotActiveException e) {
// Expected
} catch (Exception e) {
Assert.fail();
}
try {
Utils.getReference(beanManager, Conversation.class).begin();
Assert.fail();
} catch (ContextNotActiveException e) {
// Expected
} catch (Exception e) {
Assert.fail();
}
try {
Utils.getReference(beanManager, Conversation.class).begin("foo");
Assert.fail();
} catch (ContextNotActiveException e) {
// Expected
} catch (Exception e) {
Assert.fail();
}
try {
Utils.getReference(beanManager, Conversation.class).end();
Assert.fail();
} catch (ContextNotActiveException e) {
// Expected
} catch (Exception e) {
Assert.fail();
}
try {
Utils.getReference(beanManager, Conversation.class).isTransient();
Assert.fail();
} catch (ContextNotActiveException e) {
// Expected
} catch (Exception e) {
Assert.fail();
}
try {
Utils.getReference(beanManager, Conversation.class).setTimeout(0);
assert false;
} catch (ContextNotActiveException e) {
// Expected
} catch (Exception e) {
Assert.fail();
}
}
}.run();
}
use of org.jboss.weld.context.ConversationContext in project core by weld.
the class ConversationImpl method notifyConversationContext.
private void notifyConversationContext() {
ConversationContext context = getActiveConversationContext();
if (context instanceof AbstractConversationContext) {
AbstractConversationContext<?, ?> abstractConversationContext = (AbstractConversationContext<?, ?>) context;
abstractConversationContext.conversationPromotedToLongRunning(this);
}
}
use of org.jboss.weld.context.ConversationContext in project core by weld.
the class ConversationAwareViewHandler method getActionURL.
/**
* Allow the delegate to produce the action URL. If the conversation is
* long-running, append the conversation id request parameter to the query
* string part of the URL, but only if the request parameter is not already
* present.
* <p/>
* This covers form actions Ajax calls, and redirect URLs (which we want) and
* link hrefs (which we don't)
*
* @see {@link ViewHandler#getActionURL(FacesContext, String)}
*/
@Override
public String getActionURL(FacesContext facesContext, String viewId) {
if (contextId == null) {
if (facesContext.getAttributes().containsKey(Container.CONTEXT_ID_KEY)) {
contextId = (String) facesContext.getAttributes().get(Container.CONTEXT_ID_KEY);
} else {
contextId = RegistrySingletonProvider.STATIC_INSTANCE;
}
}
String actionUrl = super.getActionURL(facesContext, viewId);
final ConversationContext ctx = getConversationContext(contextId);
if (ctx != null && ctx.isActive() && !getSource().equals(Source.BOOKMARKABLE) && !ctx.getCurrentConversation().isTransient()) {
return new FacesUrlTransformer(actionUrl, facesContext).appendConversationIdIfNecessary(getConversationContext(contextId).getParameterName(), ctx.getCurrentConversation().getId()).getUrl();
} else {
return actionUrl;
}
}
Aggregations