logging updated

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/session-checker@93542 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-03-26 09:55:09 +00:00
parent 27c7afcaa5
commit bd032a0ecb
3 changed files with 64 additions and 9 deletions

View File

@ -17,7 +17,7 @@ import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class CheckSession {
private final int MILLI_SECONDS = 45 * 1000; //45 seconds
private final int MILLI_SECONDS = 55 * 1000; //(milli)seconds
//for css and images
private CheckSessionBundle images = GWT.create(CheckSessionBundle.class);
@ -92,7 +92,7 @@ public class CheckSession {
boolean userValid = ( username != null) ? true : false;
boolean scopeValid = (scope != null) ? true : false;
if (! (userValid && scopeValid) ) {
if (! (userValid && scopeValid) ) { //if session expired
mask(true);
stopPolling();
if (showSessionExpiredDialog) {
@ -106,6 +106,10 @@ public class CheckSession {
eventBus.fireEvent(new SessionTimeoutEvent(result));
}
}
else if (result.isDevMode()) {
GWT.log("Stopping polling because i think you're in development mode and not in a real portal");
stopPolling();
}
}
else {
GWT.log("result null");

View File

@ -17,32 +17,64 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
*/
@SuppressWarnings("serial")
public class SessionCheckerServiceImpl extends RemoteServiceServlet implements SessionCheckerService {
private static final Logger _log = LoggerFactory.getLogger(SessionCheckerServiceImpl.class);
private static final String FIRST_TIME = "FIRST_TIME_DEV_MODE";
/**
* the current ASLSession
* @return .
*/
private ASLSession getASLSession() {
try {
String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
return SessionManager.getInstance().getASLSession(sessionID, user);
}
catch (NullPointerException e) {
_log.warn("Session is null, perhaps you refreshed your application");
return null;
}
}
@Override
public SessionInfoBean checkSession() {
if (isFirstTime() == null)
setFirstTimeCheck(true);
ASLSession session = getASLSession();
if (session == null)
return new SessionInfoBean("","", true); //you are in development mode and refreshed the browser
String user = session.getUsername();
String scope = session.getScope();
_log.trace("Session checked for " + user + " at " + new Date());
//check devMode
if (user == null && isFirstTime()) {
_log.warn("Stopping session polling as you are in dev mode (I think, am I wrong?)");
return new SessionInfoBean("","", true); //tells that you are in development mode (you must be unless you're session expires in less than a minute)
}
//else
setFirstTimeCheck(false);
_log.trace("Session check OK for " + user + " at " + new Date());
if (user == null || user.compareTo("") == 0) {
_log.warn("User is null at " + new Date());
_log.warn("User is null at " + new Date());
}
if (scope == null || scope.compareTo("") == 0) {
_log.warn("Scope is null at " + new Date());
}
return new SessionInfoBean(session.getUsername(), session.getScope());
}
private void setFirstTimeCheck(boolean isFirstTime) {
//_log.trace("setFirstTimeCheck " + isFirstTime);
this.getThreadLocalRequest().getSession().setAttribute(FIRST_TIME, isFirstTime);
}
private Boolean isFirstTime() {
Boolean toReturn = (Boolean) this.getThreadLocalRequest().getSession().getAttribute(FIRST_TIME);
//_log.trace("isFirstTime() " + toReturn);
return toReturn;
}
}

View File

@ -7,7 +7,7 @@ public class SessionInfoBean implements Serializable {
private String username;
private String scope;
private boolean isDevMode;
public SessionInfoBean() {
super();
@ -20,6 +20,15 @@ public class SessionInfoBean implements Serializable {
this.scope = scope;
}
public SessionInfoBean(String username, String scope, boolean isDevMode) {
super();
this.username = username;
this.scope = scope;
this.isDevMode = isDevMode;
}
public String getUsername() {
return username;
@ -39,6 +48,16 @@ public class SessionInfoBean implements Serializable {
public void setScope(String scope) {
this.scope = scope;
}
public boolean isDevMode() {
return isDevMode;
}
public void setDevMode(boolean isDevMode) {
this.isDevMode = isDevMode;
}
}