Skip to content
Snippets Groups Projects
Commit dce3a0c3 authored by cramakri's avatar cramakri
Browse files

SE-186 Refactoring to support initialization parameters for servlets in DSS.

SVN: 14648
parent 1c5b33a5
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ import java.io.File; ...@@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -101,6 +102,7 @@ abstract public class AbstractDatasetDownloadServlet extends HttpServlet ...@@ -101,6 +102,7 @@ abstract public class AbstractDatasetDownloadServlet extends HttpServlet
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }
@SuppressWarnings("unchecked")
@Override @Override
public final void init(final ServletConfig servletConfig) throws ServletException public final void init(final ServletConfig servletConfig) throws ServletException
{ {
...@@ -111,6 +113,12 @@ abstract public class AbstractDatasetDownloadServlet extends HttpServlet ...@@ -111,6 +113,12 @@ abstract public class AbstractDatasetDownloadServlet extends HttpServlet
applicationContext = applicationContext =
(ApplicationContext) context (ApplicationContext) context
.getAttribute(DataStoreServer.APPLICATION_CONTEXT_KEY); .getAttribute(DataStoreServer.APPLICATION_CONTEXT_KEY);
// Look for the additional configuration parameters and initialize the servlet using
// them
Enumeration<String> e = servletConfig.getInitParameterNames();
if (e.hasMoreElements())
doSpecificInitialization(e, servletConfig);
} catch (Exception ex) } catch (Exception ex)
{ {
notificationLog.fatal("Failure during '" + servletConfig.getServletName() notificationLog.fatal("Failure during '" + servletConfig.getServletName()
...@@ -119,6 +127,16 @@ abstract public class AbstractDatasetDownloadServlet extends HttpServlet ...@@ -119,6 +127,16 @@ abstract public class AbstractDatasetDownloadServlet extends HttpServlet
} }
} }
/**
* Do any additional initialization using information from the properties passed in. Subclasses
* may override.
*/
protected synchronized void doSpecificInitialization(Enumeration<String> parameterNames,
ServletConfig servletConfig)
{
return;
}
protected final HttpSession tryGetOrCreateSession(final HttpServletRequest request, protected final HttpSession tryGetOrCreateSession(final HttpServletRequest request,
String sessionIdOrNull) String sessionIdOrNull)
{ {
......
...@@ -91,10 +91,13 @@ final class ConfigParameters ...@@ -91,10 +91,13 @@ final class ConfigParameters
private final String servletPath; private final String servletPath;
public PluginServlet(String servletClass, String servletPath) private final Properties servletProperties;
public PluginServlet(String servletClass, String servletPath, Properties servletProperties)
{ {
this.servletClass = servletClass; this.servletClass = servletClass;
this.servletPath = servletPath; this.servletPath = servletPath;
this.servletProperties = servletProperties;
} }
public String getServletClass() public String getServletClass()
...@@ -108,6 +111,12 @@ final class ConfigParameters ...@@ -108,6 +111,12 @@ final class ConfigParameters
return servletPath; return servletPath;
} }
/** Any additional properties specified in the properties file */
public Properties getServletProperties()
{
return servletProperties;
}
@Override @Override
public String toString() public String toString()
{ {
...@@ -155,7 +164,7 @@ final class ConfigParameters ...@@ -155,7 +164,7 @@ final class ConfigParameters
PropertyUtils.getMandatoryProperty(servletProps, PLUGIN_SERVICE_CLASS_KEY); PropertyUtils.getMandatoryProperty(servletProps, PLUGIN_SERVICE_CLASS_KEY);
String servletPath = String servletPath =
PropertyUtils.getMandatoryProperty(servletProps, PLUGIN_SERVICE_PATH_KEY); PropertyUtils.getMandatoryProperty(servletProps, PLUGIN_SERVICE_PATH_KEY);
servlets.add(new PluginServlet(servletClass, servletPath)); servlets.add(new PluginServlet(servletClass, servletPath, servletProps));
} }
return servlets; return servlets;
} }
......
...@@ -175,19 +175,22 @@ public class DataStoreServer ...@@ -175,19 +175,22 @@ public class DataStoreServer
private static void registerPluginServlets(Context context, List<PluginServlet> pluginServlets) private static void registerPluginServlets(Context context, List<PluginServlet> pluginServlets)
{ {
for (PluginServlet servlet : pluginServlets) for (PluginServlet pluginServlet : pluginServlets)
{ {
Class<?> classInstance; Class<?> classInstance;
try try
{ {
classInstance = Class.forName(servlet.getServletClass()); classInstance = Class.forName(pluginServlet.getServletClass());
} catch (ClassNotFoundException ex) } catch (ClassNotFoundException ex)
{ {
throw EnvironmentFailureException.fromTemplate( throw EnvironmentFailureException.fromTemplate(
"Error while loading servlet plugin class '%s': %s", servlet.getClass(), ex "Error while loading servlet plugin class '%s': %s", pluginServlet
.getMessage()); .getClass(), ex.getMessage());
} }
context.addServlet(classInstance, servlet.getServletPath()); ServletHolder holder =
context.addServlet(classInstance, pluginServlet.getServletPath());
// Add any additional parameters to the init parameters
holder.setInitParameters(pluginServlet.getServletProperties());
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment