Versions Compared

Key

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

...

Code Block
themeEclipse
private Session login() {
   String website = myConfigService.getParameter(WEBSITEKEY);
   Session session = mySessionManager.createSession(website, "username");
   return session;
}


Since R36 an alternative option is available. In R35 and earlier a common code structure used to ensure the presence of a Session was somewhere along the lines of:

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

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

//your logic here
...

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








Code Block
languagejava
themeEclipse
private Session login() {
   String website = myConfigService.getParameter(WEBSITEKEY);
   Session session = mySessionManager.createSession(website, "username");
   return session;
}