diff --git a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploaderServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploaderServiceImpl.java index 8aa2cfb..52c64bc 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploaderServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploaderServiceImpl.java @@ -1,5 +1,6 @@ package org.gcube.portlets.widgets.workspaceuploader.server; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; @@ -61,7 +62,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement logger.info("returning uploader: "+uploader.getClientUploadKey() +" status: "+uploader.getUploadStatus() +", file: "+uploader.getFile().toString() +", progress: "+progress); - checkUploaderErasable(getThreadLocalRequest().getSession(), uploader); + checkUploaderErasable(this.getThreadLocalRequest(), uploader); return uploader; } @@ -73,7 +74,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement * @param httpSession the http session * @param uploader the uploader */ - private void checkUploaderErasable(final HttpSession httpSession, final WorkspaceUploaderItem uploader){ + private void checkUploaderErasable(final HttpServletRequest httpRequest, final WorkspaceUploaderItem uploader){ logger.trace("Checking Uploader erasable..."); if(uploader==null){ @@ -81,13 +82,15 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement return; } + final HttpSession session = httpRequest.getSession(); + new Thread(){ @Override public void run() { try { - logger.trace("Uploader: "+uploader.getClientUploadKey() +", is erasable?"); - WsUtil.eraseWorkspaceUploaderInSession(getThreadLocalRequest(), uploader); + logger.trace("Uploader: "+uploader.getClientUploadKey() +", is erasable? "+uploader.isErasable()); + WsUtil.eraseWorkspaceUploaderInSession(session, uploader); } catch (Exception e) { logger.warn("Error during checkUploaderErasable: ", e); diff --git a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/WsUtil.java index 9633dfc..6fd30b1 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/WsUtil.java @@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; - import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; @@ -75,7 +74,7 @@ public class WsUtil { ScopeProvider.instance.set(scope); return HomeLibrary.getUserWorkspace(username); } - + /** * Gets the workspace. * @@ -106,7 +105,7 @@ public class WsUtil { */ public static void putWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception { logger.trace("Put workspace uploader in session: "+uploader.getIdentifier() + ", STATUS: "+uploader.getUploadStatus()); - + if(uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty()) throw new Exception("Invalid uploader"); @@ -141,18 +140,14 @@ public class WsUtil { * @param uploader the uploader * @throws Exception the exception */ - public static void eraseWorkspaceUploaderInSession(final HttpServletRequest request, WorkspaceUploaderItem uploader) throws Exception + public static void eraseWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception { logger.trace("Erase WorkspaceUploader workspace uploader in session: "+uploader.getIdentifier() + ", erasable? "+uploader.isErasable()); - if(uploader==null || uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty()) throw new Exception("Invalid uploader"); - HttpSession httpSession = request.getSession(); - if(uploader.isErasable()){ - // session.setAttribute(uploader.getIdentifier(), null); httpSession.removeAttribute(uploader.getIdentifier()); logger.info("Erased uploader: "+uploader.getIdentifier()); } @@ -187,7 +182,7 @@ public class WsUtil { * @throws Exception the exception */ public static boolean setErasableWorkspaceUploaderInSession(final HttpServletRequest request, String uploaderIdentifier) throws Exception { - + HttpSession httpSession = request.getSession(); WorkspaceUploaderItem uploader = getWorkspaceUploaderInSession(request, uploaderIdentifier);