From dba49e189f7eb75efb0bea7b7a76d62bca2e1ed5 Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Tue, 16 Sep 2014 12:13:44 +0000 Subject: [PATCH] SSDM-831 : CKAN - publishing with containers - pass request handler related properties to a jython script. The ckan script has to read 'published-spaces' and 'server-url' properties. SVN: 32446 --- .../server/oaipmh/JythonBasedRequestHandler.java | 13 +++++++++++-- .../jython/IRequestHandlerPluginScriptRunner.java | 2 ++ .../plugins/jython/PluginScriptRunnerFactory.java | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/oaipmh/JythonBasedRequestHandler.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/oaipmh/JythonBasedRequestHandler.java index 693cfe9f7a6..3acdc7bb0c8 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/oaipmh/JythonBasedRequestHandler.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/oaipmh/JythonBasedRequestHandler.java @@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.IPluginScriptRunnerFactory; +import ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.IRequestHandlerPluginScriptRunner; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.PluginScriptRunnerFactory; import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext; import ch.systemsx.cisd.openbis.dss.generic.shared.IDataStoreServiceInternal; @@ -36,6 +37,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; * OAI-PMH response handler that delegates a response generation to a Jython script. The script can be configured via "script-path" property. The * script should define a function with a following signature: * </p> + * * <pre> * def handle(request, response) * </pre> @@ -58,16 +60,22 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; * @author pkupczyk */ +@SuppressWarnings("hiding") public class JythonBasedRequestHandler implements IRequestHandler { private static final String SCRIPT_PATH_PARAMETER_NAME = "script-path"; + private static final String PROPERTIES_VARIABLE_NAME = "properties"; + + private Properties properties; + private String scriptPath; @Override public void init(Properties properties) { + this.properties = properties; this.scriptPath = initScriptPath(properties); } @@ -113,14 +121,15 @@ public class JythonBasedRequestHandler implements IRequestHandler service.getSessionWorkspaceProvider(session.getSessionToken()), new HashMap<String, String>(), service.createEMailClient(), session.getUserName(), session.getUserEmail(), session.getSessionToken()); - factory.createRequestHandlerPluginRunner(context).handle(req, resp); + IRequestHandlerPluginScriptRunner runner = factory.createRequestHandlerPluginRunner(context); + runner.setVariable(PROPERTIES_VARIABLE_NAME, properties); + runner.handle(req, resp); } finally { manager.releaseLocks(); } } - @SuppressWarnings("hiding") protected IPluginScriptRunnerFactory getScriptRunnerFactory(String scriptPath) { return new PluginScriptRunnerFactory(scriptPath); diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/IRequestHandlerPluginScriptRunner.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/IRequestHandlerPluginScriptRunner.java index 347236cbd29..24f0484b565 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/IRequestHandlerPluginScriptRunner.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/IRequestHandlerPluginScriptRunner.java @@ -25,6 +25,8 @@ import javax.servlet.http.HttpServletResponse; public interface IRequestHandlerPluginScriptRunner { + void setVariable(String name, Object value); + void handle(HttpServletRequest req, HttpServletResponse resp); void releaseResources(); diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/PluginScriptRunnerFactory.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/PluginScriptRunnerFactory.java index ee72a9cc7bb..68aeea12d46 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/PluginScriptRunnerFactory.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/PluginScriptRunnerFactory.java @@ -448,6 +448,12 @@ public class PluginScriptRunnerFactory implements IPluginScriptRunnerFactory } } + @Override + public void setVariable(String name, Object value) + { + evaluator.set(name, value); + } + @Override public void handle(HttpServletRequest request, HttpServletResponse response) { -- GitLab