Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When an editor is working in the Workspace, the sessions are created automatically by the XperienCentral framework. For each request, XperienCentral identifies the user according to the cookie sent, together with the request, and creates a new XperienCentral session. This XperienCentral session is put on the top of the “session stack”. When the response is sent back to the client, this session is removed from the stacstack, therefore this session exists during the complete lifetime of the request.

...

Code Block
languagejava
themeEclipse
boolean sessionCreated = false;
Session session = mySessionManager.getActiveSession();

if (session == null) {
	session = mySessionManager.createSession();
	sessionCreated = true;
}

try {
// your logic here
...
} catch (Exception e) {
	// Handle the exception
} finally {
	if (sessionCreated) {
		session.close();
	}
}

The example above leads to a of duplicate code, both in XperienCentral and custom plugins. In R36 the SessionWrapper was introduced, which takes care of the Session creation for you. The example above can be changed to this:

Code Block
languagejava
themeEclipse
try (SessionWrapper sessionWrapper = new SessionWrapper(mySessionManager)) {
	Session session = sessionWrapper.getSession();
	// your logic here
} catch (IOException e) {
    // Handle the exception
}

Back to Top

...

languagejava
themeEclipse

...

Please note that the getSession() should be called outside of the try-with-resources statement. This is because the SessionWrapper should be in control of closing the session. If you place the sessionWrapper.getSession() within the try-with-resources the session might be auto-closed, leading to errors.



Back to Top