Author: ehillenius
Date: Fri Apr 13 00:50:29 2007
New Revision: 528379
URL: http://svn.apache.org/viewvc?view=rev&rev=528379
Log:
fixes for session and request cycle creation
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java?view=diff&rev=528379&r1=528378&r2=528379
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Application.java
Fri Apr 13 00:50:29 2007
@@ -79,15 +79,15 @@
* override getHomePage() to provide this property value.
*
* <li><b>Settings </b>- Application settings are partitioned into sets of
- * related settings using interfaces in the org.apache.wicket.settings
package. These
- * interfaces are returned by the following methods, which should be used to
- * configure framework settings for your application: getApplicationSettings(),
- * getDebugSettings(), getExceptionSettings(), getMarkupSettings(),
- * getPageSettings(), getRequestCycleSettings(), getSecuritySettings and
- * getSessionSettings(). These settings are configured by default through the
- * constructor or internalInit methods. Default the application is configured
- * for DEVELOPMENT. You can configure this globally to DEPLOYMENT or override
- * specific settings by implementing the init() method.
+ * related settings using interfaces in the org.apache.wicket.settings package.
+ * These interfaces are returned by the following methods, which should be used
+ * to configure framework settings for your application:
+ * getApplicationSettings(), getDebugSettings(), getExceptionSettings(),
+ * getMarkupSettings(), getPageSettings(), getRequestCycleSettings(),
+ * getSecuritySettings and getSessionSettings(). These settings are configured
+ * by default through the constructor or internalInit methods. Default the
+ * application is configured for DEVELOPMENT. You can configure this globally
to
+ * DEPLOYMENT or override specific settings by implementing the init() method.
*
* <li><b>Shared Resources </b>- Resources added to an Application's
* SharedResources have application-wide scope and can be referenced using a
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java?view=diff&rev=528379&r1=528378&r2=528379
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/Session.java
Fri Apr 13 00:50:29 2007
@@ -238,15 +238,49 @@
Session session = (Session)current.get();
if (session == null)
{
- final RequestCycle cycle = RequestCycle.get();
- session =
Application.get().getSessionFactory().newSession(cycle.getRequest(),
- cycle.getResponse());
- set(session);
+ session = findOrCreate();
}
return session;
}
/**
+ * Locate the session for the client of this request in the
+ * [EMAIL PROTECTED] ISessionStore} or create a new one and attach it
when none could
+ * be located and sets it as the current instance for this thread.
+ * Typically, clients never touch this method, but rather use
+ * [EMAIL PROTECTED] Session#get()}, which does the locating implicitly
when not yet
+ * set as a thread local.
+ *
+ * @return The session for the client of this request or a new, unbound
+ */
+ public static final Session findOrCreate()
+ {
+ RequestCycle requestCycle = RequestCycle.get();
+ if (requestCycle == null)
+ {
+ throw new IllegalStateException(
+ "you can only locate or create sessions
in the context of a request cycle");
+ }
+ Application application = Application.get();
+ ISessionStore sessionStore = application.getSessionStore();
+ Session session =
sessionStore.lookup(requestCycle.getRequest());
+
+ if (session == null)
+ {
+ // Create session using session factory
+ session =
application.getSessionFactory().newSession(requestCycle.getRequest(),
+ requestCycle.getResponse());
+ // Set the current session
+ // execute any attach logic now
+ session.attach();
+ }
+
+ set(session);
+
+ return session;
+ }
+
+ /**
* THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
* <p>
* Sets session for calling thread.
@@ -985,6 +1019,16 @@
private final String attributeForPageMapName(final String pageMapName)
{
return pageMapAttributePrefix + pageMapName;
+ }
+
+ /**
+ * Any attach logic for session subclasses. Called when a session is
set for
+ * the thread. Note that this is done on demand (lazily): as long as the
+ * session isn't being used, it is not located or created and this
method is
+ * not called.
+ */
+ protected void attach()
+ {
}
/**
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java?view=diff&rev=528379&r1=528378&r2=528379
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
Fri Apr 13 00:50:29 2007
@@ -495,7 +495,7 @@
application, wicketRequest, wicketResponse);
// Construct session
- this.wicketSession =
this.application.getSession(this.wicketRequest, this.wicketResponse);
+ this.wicketSession = (WebSession)Session.findOrCreate();
// Set request cycle so it won't detach automatically and clear
messages
// we want to check
@@ -517,7 +517,7 @@
this.wicketRequest =
this.application.newWebRequest(servletRequest);
this.wicketResponse =
this.application.newWebResponse(servletResponse);
createRequestCycle();
- this.wicketSession = this.application.getSession(wicketRequest,
wicketResponse);
+ this.wicketSession = (WebSession)Session.findOrCreate();
this.application.getSessionStore().bind(wicketRequest,
wicketSession);
wicketResponse.setAjax(wicketRequest.isAjax());
}
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java?view=diff&rev=528379&r1=528378&r2=528379
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
Fri Apr 13 00:50:29 2007
@@ -670,44 +670,6 @@
}
/**
- * Gets a WebSession object from the HttpServletRequest, creating a new
one
- * if it doesn't already exist.
- *
- * @param request
- * The web request
- * @param response
- * The web response
- * @return The session object
- */
- final WebSession getSession(final WebRequest request, final WebResponse
response)
- {
- ISessionStore sessionStore = getSessionStore();
- Session session = sessionStore.lookup(request);
-
- if (session == null)
- {
- // Create session using session factory
- session = getSessionFactory().newSession(request,
response);
- }
-
- WebSession webSession;
- if (session instanceof WebSession)
- {
- webSession = (WebSession)session;
- }
- else
- {
- throw new WicketRuntimeException("Session created by a
WebApplication session factory "
- + "must be a subclass of WebSession");
- }
-
- // Set session attribute name and attach/reattach http servlet
session
- webSession.initForRequest();
-
- return webSession;
- }
-
- /**
* Log that this application is started.
*/
final void logStarted()
@@ -767,7 +729,7 @@
{
return getRequestCycleFactory().newRequestCycle(this, request,
response);
}
-
+
// TODO remove after deprecation release
/**
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java?view=diff&rev=528379&r1=528378&r2=528379
==============================================================================
---
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java
(original)
+++
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java
Fri Apr 13 00:50:29 2007
@@ -64,17 +64,6 @@
}
/**
- * Initializes this session for a request.
- */
- public final void initForRequest()
- {
- // Set the current session
- set(this);
-
- attach();
- }
-
- /**
* Invalidates this session at the end of the current request. If you
need
* to invalidate the session immediately, you can do this by calling
* invalidateNow(), however this will remove all Wicket components from
this
@@ -108,13 +97,6 @@
public final boolean isSessionInvalidated()
{
return sessionInvalidated;
- }
-
- /**
- * Any attach logic for session subclasses.
- */
- protected void attach()
- {
}
/**