diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/AbstractDatasetDownloadServlet.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/AbstractDatasetDownloadServlet.java index 198c558b332c3ce6b2c57f4b304ca42e21100b4c..3e3f03c0fb79e1e4737909fcbe0e46554f3e596d 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/AbstractDatasetDownloadServlet.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/AbstractDatasetDownloadServlet.java @@ -75,8 +75,6 @@ abstract public class AbstractDatasetDownloadServlet extends HttpServlet private static final String THUMBNAIL_MODE_DISPLAY = "thumbnail"; - protected static final String SESSION_ID_PARAM = "sessionID"; - static final String DISPLAY_MODE_PARAM = "mode"; static final String BINARY_CONTENT_TYPE = "binary"; diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServlet.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServlet.java index d84bd2abfd3930439c7ec2fdb0c96341a7ec2eb1..737ad9a780bca3753d02aba731be4b0d72c99827 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServlet.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServlet.java @@ -228,9 +228,7 @@ public class DatasetDownloadServlet extends AbstractDatasetDownloadServlet File rootDir = createDataSetRootDirectory(dataSetCode, session); RenderingContext context = new RenderingContext(rootDir, requestParams.getURLPrefix(), - requestParams.getPathInfo() - - ); + requestParams.getPathInfo(), requestParams.tryGetSessionId()); return context; } @@ -272,7 +270,7 @@ public class DatasetDownloadServlet extends AbstractDatasetDownloadServlet final String urlPrefixWithDataset = requestURI.substring(0, requestURI.length() - pathInfo.length()); - final String sessionIDOrNull = request.getParameter(SESSION_ID_PARAM); + final String sessionIDOrNull = request.getParameter(Utils.SESSION_ID_PARAM); String displayMode = getDisplayMode(request); Boolean autoResolveOrNull = Boolean.valueOf(request.getParameter(AUTO_RESOLVE_KEY)); @@ -387,7 +385,8 @@ public class DatasetDownloadServlet extends AbstractDatasetDownloadServlet mainDataSets.get(0).getPath())); RenderingContext newRenderingContext = new RenderingContext(renderingContext.getRootDir(), - renderingContext.getUrlPrefix(), newRelativePath); + renderingContext.getUrlPrefix(), newRelativePath, + renderingContext.getSessionIdOrNull()); autoResolveRedirect(response, newRenderingContext); } else if (AutoResolveUtils.continueAutoResolving(requestParams.tryGetMainDataSetPattern(), dir)) @@ -400,7 +399,8 @@ public class DatasetDownloadServlet extends AbstractDatasetDownloadServlet String newRelativePath = pathPrefix + childName; RenderingContext newRenderingContext = new RenderingContext(renderingContext.getRootDir(), - renderingContext.getUrlPrefix(), newRelativePath); + renderingContext.getUrlPrefix(), newRelativePath, + renderingContext.getSessionIdOrNull()); autoResolveRedirect(response, newRenderingContext); } else { @@ -411,8 +411,12 @@ public class DatasetDownloadServlet extends AbstractDatasetDownloadServlet private static void autoResolveRedirect(HttpServletResponse response, RenderingContext newContext) throws IOException { + String urlPrefix = newContext.getUrlPrefix(); + String relativePathOrNull = newContext.getRelativePathOrNull(); + String sessionIdOrNull = newContext.getSessionIdOrNull(); final String newLocation = - DOWNLOAD_URL + newContext.getUrlPrefix() + "/" + newContext.getRelativePathOrNull(); + DOWNLOAD_URL + urlPrefix + "/" + relativePathOrNull + + Utils.createUrlParameterForSessionId("?", sessionIdOrNull); if (operationLog.isInfoEnabled()) { operationLog.info(String.format("Auto resolve redirect: '%s', context: %s", diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/RenderingContext.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/RenderingContext.java index 93a679376961afc1394af850babc4ac2db5d26fc..aaee62874cc7d972992a1e097b1a29a861c14cc0 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/RenderingContext.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/RenderingContext.java @@ -34,12 +34,15 @@ final class RenderingContext private String relativeParentPath; - RenderingContext(File rootDir, String urlPrefix, String relativePathOrNull) + private final String sessionIdOrNull; + + RenderingContext(File rootDir, String urlPrefix, String relativePathOrNull, String sessionIdOrNull) { this.rootDir = rootDir; this.relativePathOrNull = relativePathOrNull; this.file = rootDir; this.urlPrefix = urlPrefix; + this.sessionIdOrNull = sessionIdOrNull; if (relativePathOrNull != null && relativePathOrNull.length() > 0) { file = new File(rootDir, relativePathOrNull); @@ -76,6 +79,11 @@ final class RenderingContext return relativeParentPath; } + public String getSessionIdOrNull() + { + return sessionIdOrNull; + } + @Override public String toString() { diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/SimpleHTMLDirectoryRenderer.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/SimpleHTMLDirectoryRenderer.java index 7c740bd30fdcdbe95f10bfbb84947d9afb05e87d..78f458ee8d97f40bf64f4087970e0ce469159ab2 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/SimpleHTMLDirectoryRenderer.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/SimpleHTMLDirectoryRenderer.java @@ -51,7 +51,7 @@ final class SimpleHTMLDirectoryRenderer implements IDirectoryRenderer private static final Template ROW_TEMPLATE = new Template( - "<tr><td class='td_file'><a href='${path}?mode=simpleHtml'>${name}</td><td>${size}</td></tr>"); + "<tr><td class='td_file'><a href='${path}?mode=simpleHtml${sessionId}'>${name}</td><td>${size}</td></tr>"); private static final Template HEADER_TEMPLATE = new Template("<html><head>" + CSS + "</head><body>" + "<table> " + "${folder}" + ""); @@ -64,9 +64,12 @@ final class SimpleHTMLDirectoryRenderer implements IDirectoryRenderer private final String relativePathOrNull; + private final String sessionIdOrNull; + SimpleHTMLDirectoryRenderer(final RenderingContext context) { this.relativePathOrNull = context.getRelativePathOrNull(); + sessionIdOrNull = context.getSessionIdOrNull(); final String prefix = context.getUrlPrefix(); this.urlPrefix = prefix.endsWith("/") ? prefix : prefix + "/"; } @@ -111,6 +114,7 @@ final class SimpleHTMLDirectoryRenderer implements IDirectoryRenderer template.bind("path", urlPrefix + encodeURL(relativePath)); template.bind("name", name); template.bind("size", fileSize); + template.bind("sessionId", Utils.createUrlParameterForSessionId("&", sessionIdOrNull)); writer.println(template.createText()); } diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/Utils.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/Utils.java new file mode 100644 index 0000000000000000000000000000000000000000..02473b7b37597db1eb9c3327d1f8e92a41e3dcda --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/Utils.java @@ -0,0 +1,35 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.dss.generic.server; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class Utils +{ + + public static final String SESSION_ID_PARAM = "sessionID"; + + static String createUrlParameterForSessionId(String prefix, String sessionIdOrNull) + { + return sessionIdOrNull == null ? "" : prefix + Utils.SESSION_ID_PARAM + "=" + + sessionIdOrNull; + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java index 9ff6ddb75e76fd99c6a24914783526c48a473f4a..8ca295bdcfa58e7fcef191e6f0dbb0ace5329d5d 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java @@ -187,13 +187,31 @@ public class DatasetDownloadServletTest DatasetDownloadServlet servlet = createServlet(); servlet.doGet(request, response); assertEquals( - "<html><head><style type='text/css'> * { margin: 3px; }html { height: 100%; }body { height: 100%; font-family: verdana, tahoma, helvetica; font-size: 11px; text-align:left; }h1 { text-align: center; padding: 1em; color: #1E4E8F;}.td_hd { border: 1px solid #FFFFFF; padding 3px; background-color: #DDDDDD; height: 1.5em; }.div_hd { background-color: #1E4E8F; color: white; font-weight: bold; padding: 3px; }table { border-collapse: collapse; padding: 1em; }tr, td { font-family: verdana, tahoma, helvetica; font-size: 11px; }.td_file { font-family: verdana, tahoma, helvetica; font-size: 11px; height: 1.5em }.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0em auto -4em; }.footer { height: 4em; text-align: center; }</style></head><body><table> " + "<html><head><style type='text/css'> * { margin: 3px; }html { height: 100%; }" + + "body { height: 100%; font-family: verdana, tahoma, helvetica; " + + "font-size: 11px; text-align:left; }" + + "h1 { text-align: center; padding: 1em; color: #1E4E8F;}" + + ".td_hd { border: 1px solid #FFFFFF; padding 3px; " + + "background-color: #DDDDDD; height: 1.5em; }" + + ".div_hd { background-color: #1E4E8F; color: white; " + + "font-weight: bold; padding: 3px; }" + + "table { border-collapse: collapse; padding: 1em; }" + + "tr, td { font-family: verdana, tahoma, helvetica; font-size: 11px; }" + + ".td_file { font-family: verdana, tahoma, helvetica; " + + "font-size: 11px; height: 1.5em }" + + ".wrapper { min-height: 100%; height: auto !important; height: 100%;" + + " margin: 0em auto -4em; }" + + ".footer { height: 4em; text-align: center; }</style></head>" + + "<body><table> " + OSUtilities.LINE_SEPARATOR - + "<tr><td class='td_file'><a href='/datastore_server/1234-1/%2B+s+%25+%21+%23+%40?mode=simpleHtml'>+ s % ! # @</td><td></td></tr>" + + "<tr><td class='td_file'>" + + "<a href='/datastore_server/1234-1/%2B+s+%25+%21+%23+%40?mode=simpleHtml&sessionID=AV76CF'>" + + "+ s % ! # @</td><td></td></tr>" + OSUtilities.LINE_SEPARATOR - + "<tr><td class='td_file'><a href='/datastore_server/1234-1/read+me+%40home.txt?mode=simpleHtml'>read me @home.txt</td><td>12 bytes</td></tr>" - + OSUtilities.LINE_SEPARATOR - + "</table> </div> </body></html>" + + "<tr><td class='td_file'>" + + "<a href='/datastore_server/1234-1/read+me+%40home.txt?mode=simpleHtml&sessionID=AV76CF'>" + + "read me @home.txt</td><td>12 bytes</td></tr>" + + OSUtilities.LINE_SEPARATOR + "</table> </div> </body></html>" + OSUtilities.LINE_SEPARATOR + "", writer.toString()); assertEquals(getSessionCreationLogMessage() + OSUtilities.LINE_SEPARATOR + LOG_INFO + "Data set '1234-1' obtained from openBIS server." + OSUtilities.LINE_SEPARATOR @@ -208,7 +226,7 @@ public class DatasetDownloadServletTest context.checking(new Expectations() { { - one(request).getParameter(DatasetDownloadServlet.SESSION_ID_PARAM); + one(request).getParameter(Utils.SESSION_ID_PARAM); will(returnValue(EXAMPLE_SESSION_ID)); one(request).getParameter(DatasetDownloadServlet.DISPLAY_MODE_PARAM); @@ -577,7 +595,7 @@ public class DatasetDownloadServletTest private void prepareParseRequestURLNoSession(Expectations exp) { - exp.one(request).getParameter(DatasetDownloadServlet.SESSION_ID_PARAM); + exp.one(request).getParameter(Utils.SESSION_ID_PARAM); exp.will(Expectations.returnValue(null)); exp.allowing(request).getParameter(DatasetDownloadServlet.DISPLAY_MODE_PARAM); @@ -604,7 +622,7 @@ public class DatasetDownloadServletTest context.checking(new Expectations() { { - one(request).getParameter(DatasetDownloadServlet.SESSION_ID_PARAM); + one(request).getParameter(Utils.SESSION_ID_PARAM); will(returnValue(EXAMPLE_SESSION_ID)); one(request).getParameter(DatasetDownloadServlet.DISPLAY_MODE_PARAM); @@ -646,10 +664,10 @@ public class DatasetDownloadServletTest // For the logging of session-creating requests Vector<String> parameterNames = new Vector<String>(); - parameterNames.add(DatasetDownloadServlet.SESSION_ID_PARAM); + parameterNames.add(Utils.SESSION_ID_PARAM); one(request).getParameterNames(); will(Expectations.returnValue(parameterNames.elements())); - one(request).getParameter(DatasetDownloadServlet.SESSION_ID_PARAM); + one(request).getParameter(Utils.SESSION_ID_PARAM); will(returnValue(EXAMPLE_SESSION_ID)); DatabaseInstance databaseInstance = new DatabaseInstance();