Author: hannes
Date: 2009-04-09 10:01:52 +0200 (Thu, 09 Apr 2009)
New Revision: 9595
Modified:
helma-ng/trunk/src/org/helma/web/HelmaServlet.java
Log:
Simplify HelmaServlet code and rename init parameters to match those in JackServlet:
moduleName -> module
functionName -> function
helmaHome -> home
Details at http://dev.helma.org/trac/helma/changeset/9595
Modified: helma-ng/trunk/src/org/helma/web/HelmaServlet.java
===================================================================
--- helma-ng/trunk/src/org/helma/web/HelmaServlet.java 2009-04-09 08:01:50 UTC (rev 9594)
+++ helma-ng/trunk/src/org/helma/web/HelmaServlet.java 2009-04-09 08:01:52 UTC (rev 9595)
@@ -33,11 +33,8 @@
public class HelmaServlet extends HttpServlet {
protected RhinoEngine engine;
+ private String module, function;
- private int requestTimeout = 30;
-
- private String moduleName, functionName;
-
static protected Class[] defaultHostClasses =
new Class[] {
Request.class,
@@ -62,22 +59,13 @@
this.engine = engine;
}
- public void init(ServletConfig servletConfig) throws ServletException {
- moduleName = servletConfig.getInitParameter("moduleName");
- if (moduleName == null) {
- throw new ServletException("moduleName servlet parameter not defined");
- }
- functionName = servletConfig.getInitParameter("functionName");
- if (functionName == null) {
- throw new ServletException("functionName servlet parameter not defined");
- }
- String timeout = servletConfig.getInitParameter("requestTimeout");
- if (timeout != null) {
- requestTimeout = Integer.parseInt(timeout);
- }
+ public void init(ServletConfig config) throws ServletException {
+ module = getInitParam(config, "module", "app");
+ function = getInitParam(config, "function", "handler");
+
if (engine == null) {
try {
- String classNames = servletConfig.getInitParameter("hostClasses");
+ String classNames = config.getInitParameter("hostClasses");
Class[] classes = defaultHostClasses;
if (classNames != null) {
Class[] custom = StringUtils.toClassArray(classNames, ", ");
@@ -86,16 +74,16 @@
System.arraycopy(custom, 0, copy, classes.length, custom.length);
classes = copy;
}
- String helmaHome = servletConfig.getInitParameter("helmaHome");
- String modulePath = servletConfig.getInitParameter("modulePath");
- Repository home = new WebappRepository(servletConfig.getServletContext(), helmaHome);
+ String helmaHome = getInitParam(config, "home", "WEB-INF");
+ String modulePath = getInitParam(config, "modulePath", "modules");
+ Repository home = new WebappRepository(config.getServletContext(), helmaHome);
if (!home.exists()) {
home = new FileRepository(helmaHome);
}
- HelmaConfiguration config =
+ HelmaConfiguration helmaConfig =
new HelmaConfiguration(home, modulePath, "modules");
- config.setHostClasses(classes);
- engine = new RhinoEngine(config, null);
+ helmaConfig.setHostClasses(classes);
+ engine = new RhinoEngine(helmaConfig, null);
} catch (ClassNotFoundException x) {
throw new ServletException(x);
} catch (FileNotFoundException x) {
@@ -108,7 +96,7 @@
final HttpServletResponse res)
throws ServletException, IOException {
try {
- engine.invoke(moduleName, functionName, new Request(req), new Response(res));
+ engine.invoke(module, function, new Request(req), new Response(res));
} catch (RedirectException redir) {
res.sendRedirect(redir.getMessage());
} catch (NoSuchMethodException x) {
@@ -116,17 +104,9 @@
}
}
- public int getRequestTimeout() {
- return requestTimeout;
+ private String getInitParam(ServletConfig config, String name, String defaultValue) {
+ String value = config.getInitParameter(name);
+ return value == null ? defaultValue : value;
}
-
- public void setRequestTimeout(int requestTimeout) {
- this.requestTimeout = requestTimeout;
- }
-
- class Status {
- volatile Throwable exception;
- volatile String redirect;
- }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.