Author: struberg
Date: Sun May 3 18:44:25 2015
New Revision: 1677477
URL: http://svn.apache.org/r1677477
Log:
OWB-1050 further improve Conversation handling
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
openwebbeans/trunk/webbeans-web/pom.xml
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/EndWebBeansConfigurationListener.java
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java?rev=1677477&r1=1677476&r2=1677477&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
Sun May 3 18:44:25 2015
@@ -65,6 +65,8 @@ public class ConversationImpl implements
*/
private long lastAccessTime = 0L;
+ private transient Throwable problemDuringCreation = null;
+
/**
* This instance is under used and by which threads, Atomicinteger would
be great but then contract of ContextsService but be enhanced to
* be compatible wih WBPhaseListeners. Using thread allow to call iUseIt()
multiple times.
@@ -252,6 +254,15 @@ public class ConversationImpl implements
return "Conversation with id [ " + id + " ]";
}
+ public Throwable getProblemDuringCreation()
+ {
+ return problemDuringCreation;
+ }
+
+ public void setProblemDuringCreation(Throwable problemDuringCreation)
+ {
+ this.problemDuringCreation = problemDuringCreation;
+ }
/**
* Initialize a few fields on deserialisation
Modified: openwebbeans/trunk/webbeans-web/pom.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/pom.xml?rev=1677477&r1=1677476&r2=1677477&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/pom.xml (original)
+++ openwebbeans/trunk/webbeans-web/pom.xml Sun May 3 18:44:25 2015
@@ -44,6 +44,13 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <!-- we actually only need that in the ITs, but that way it's
easier for the IDE -->
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.2.1</version>
+ <scope>${httpclient.version}</scope>
+ </dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
Modified:
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/EndWebBeansConfigurationListener.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/EndWebBeansConfigurationListener.java?rev=1677477&r1=1677476&r2=1677477&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/EndWebBeansConfigurationListener.java
(original)
+++
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/EndWebBeansConfigurationListener.java
Sun May 3 18:44:25 2015
@@ -18,7 +18,6 @@
*/
package org.apache.webbeans.servlet;
-import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.context.spi.Context;
@@ -129,7 +128,6 @@ public class EndWebBeansConfigurationLis
boolean mustDestroy = ensureRequestScope();
this.lifeCycle.getContextService().endContext(SessionScoped.class,
event.getSession());
-
this.lifeCycle.getContextService().endContext(ConversationScoped.class,
event.getSession());
if (mustDestroy)
{
Modified:
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1677477&r1=1677476&r2=1677477&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
(original)
+++
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Sun May 3 18:44:25 2015
@@ -63,8 +63,15 @@ public class WebContextsService extends
private static final String OWB_SESSION_CONTEXT_ATTRIBUTE_NAME =
"openWebBeansSessionContext";
+ /**
+ * This request attribute gets set when an illegal conversation id or busy
conversation access
+ * gets discovered. In that case we need to throw an Exception and provide
+ * a fresh transient conversation. This attribute gets set when exactly
that happens.
+ */
+ private static final String
OWB_REQUEST_TRANSIENT_CONVERSATION_ATTRIBUTE_NAME =
"org.apache.webbeans.web.transient_conversation";
+
/**Current request context*/
- protected static ThreadLocal<RequestContext> requestContexts = null;
+ protected static ThreadLocal<ServletRequestContext> requestContexts = null;
/**Current session context*/
protected static ThreadLocal<SessionContext> sessionContexts = null;
@@ -90,7 +97,7 @@ public class WebContextsService extends
/**Initialize thread locals*/
static
{
- requestContexts = new ThreadLocal<RequestContext>();
+ requestContexts = new ThreadLocal<ServletRequestContext>();
sessionContexts = new ThreadLocal<SessionContext>();
conversationContexts = new ThreadLocal<ConversationContext>();
@@ -237,7 +244,7 @@ public class WebContextsService extends
{
return applicationContext;
}
- else if(supportsConversation &&
scopeType.equals(ConversationScoped.class))
+ else if(scopeType.equals(ConversationScoped.class))
{
return getConversationContext(true);
}
@@ -346,7 +353,7 @@ public class WebContextsService extends
// cleanup open conversations first
if (supportsConversation)
{
- cleanupConversations();
+ cleanupConversations(conversationContexts.get());
}
//Get context
@@ -387,11 +394,6 @@ public class WebContextsService extends
}
- private void cleanupConversations()
- {
- cleanupConversations(conversationContexts.get());
- }
-
/**
* Creates the session context at the session start.
* Or assign a
@@ -473,6 +475,11 @@ public class WebContextsService extends
// Destroy context
if (context != null)
{
+ if (supportsConversation)
+ {
+ //X TODO get all conversations stored in the Session and mark
them as transient
+ //X TODO also set the current conversation (if any) to
transient
+ }
context.destroy();
webBeansContext.getBeanManagerImpl().fireEvent(payload != null ?
payload : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
}
@@ -616,9 +623,9 @@ public class WebContextsService extends
* Get current request ctx.
* @return request context
*/
- public RequestContext getRequestContext(boolean create)
+ public ServletRequestContext getRequestContext(boolean create)
{
- RequestContext requestContext = requestContexts.get();
+ ServletRequestContext requestContext = requestContexts.get();
if (requestContext == null && create)
{
initRequestContext(null);
@@ -658,15 +665,21 @@ public class WebContextsService extends
String conversationId =
webBeansContext.getConversationService().getConversationId();
if (conversationId != null &&
conversationContext.getConversation().isTransient())
{
- throw new NonexistentConversationException("Propogated
conversation with cid=" + conversationId +
- " cannot be restored. It creates a new transient
conversation.");
+ if (markAsTemporaryTransientConversation())
+ {
+ throw new NonexistentConversationException("Propogated
conversation with cid=" + conversationId +
+ " cannot be restored. It creates a new transient
conversation.");
+ }
}
if (conversationContext.getConversation().iUseIt() > 1)
{
- //Throw Busy exception
- throw new BusyConversationException("Propogated conversation
with cid=" + conversationId +
- " is used by other request. It creates a new transient
conversation");
+ if (markAsTemporaryTransientConversation())
+ {
+ //Throw Busy exception
+ throw new BusyConversationException("Propogated
conversation with cid=" + conversationId +
+ " is used by other request. It creates a new
transient conversation");
+ }
}
}
@@ -674,6 +687,28 @@ public class WebContextsService extends
}
/**
+ * Remember for this request that a fresh transient conversation got
created.
+ * @return {@code false} if this request already got marked previously,
{@code true} if we are the first to set the marker
+ */
+ private boolean markAsTemporaryTransientConversation()
+ {
+ HttpServletRequest servletRequest =
requestContexts.get().getServletRequest();
+ if (servletRequest != null)
+ {
+ String marker = (String)
servletRequest.getAttribute(OWB_REQUEST_TRANSIENT_CONVERSATION_ATTRIBUTE_NAME);
+ if (marker != null)
+ {
+ return false;
+ }
+
+ // if not then we need to mark it
+
servletRequest.setAttribute(OWB_REQUEST_TRANSIENT_CONVERSATION_ATTRIBUTE_NAME,
"true");
+ }
+
+ return true;
+ }
+
+ /**
* Try to lazily start the sessionContext
*/
private void lazyStartSessionContext()