Author: hannes
Date: 2009-04-11 16:18:06 +0200 (Sat, 11 Apr 2009)
New Revision: 9604
Modified:
helma-ng/trunk/modules/helma/jack.js
helma-ng/trunk/src/org/helma/jack/JackEnv.java
Log:
Add some more missing features to jack servlet.
- Implement "jack.*" properties, except input and error return raw java streams
- convert return values to string in helma/jack.applyResponse()
Details at http://dev.helma.org/trac/helma/changeset/9604
Modified: helma-ng/trunk/modules/helma/jack.js
===================================================================
--- helma-ng/trunk/modules/helma/jack.js 2009-04-10 12:29:12 UTC (rev 9603)
+++ helma-ng/trunk/modules/helma/jack.js 2009-04-11 14:18:06 UTC (rev 9604)
@@ -7,7 +7,7 @@
* you won't need this unless you're implementing your own servlet
* based jack connector.
*
- * @param response an instance of javax.servlet.http.HttpServletResponse
+ * @param response an instanceof javax.servlet.http.HttpServletResponse
* @param result the object returned by a jack application
*/
function applyResponse(response, result) {
@@ -19,11 +19,11 @@
var writer = response.writer;
if (body && typeof body.forEach == "function") {
body.forEach(function(chunk) {
- writer.write(chunk);
+ writer.write(String(chunk));
writer.flush();
})
} else {
- writer.write(body);
+ writer.write(String(body));
writer.flush();
}
}
Modified: helma-ng/trunk/src/org/helma/jack/JackEnv.java
===================================================================
--- helma-ng/trunk/src/org/helma/jack/JackEnv.java 2009-04-10 12:29:12 UTC (rev 9603)
+++ helma-ng/trunk/src/org/helma/jack/JackEnv.java 2009-04-11 14:18:06 UTC (rev 9604)
@@ -16,10 +16,11 @@
package org.helma.jack;
-import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
+import java.io.IOException;
public class JackEnv extends ScriptableObject {
@@ -75,9 +76,35 @@
return req.getRemoteHost();
}
+ public static void finishInit(Scriptable scope, FunctionObject constructor, Scriptable prototype) {
+ int flags = DONTENUM | READONLY | PERMANENT;
+ Context cx = Context.getCurrentContext();
+ Scriptable version = cx.newArray(scope, new Object[] {new Integer(0), new Integer(1)});
+ ScriptableObject.defineProperty(prototype, "jack.version", version, flags);
+ ScriptableObject.defineProperty(prototype, "jack.multithread", Boolean.TRUE, flags);
+ ScriptableObject.defineProperty(prototype, "jack.multiprocess", Boolean.TRUE, flags);
+ ScriptableObject.defineProperty(prototype, "jack.run_once", Boolean.FALSE, flags);
+ }
+
+ @Override
+ public Object get(String name, Scriptable start) {
+ // FIXME: implement IO wrappers
+ if ("jack.input".equals(name)) {
+ try {
+ return Context.toObject(req.getInputStream(), this);
+ } catch (IOException iox) {
+ return Undefined.instance;
+ }
+ } else if ("jack.error".equals(name)) {
+ return Context.toObject(System.err, this);
+ }
+ return super.get(name, start);
+ }
+
/**
* Return the name of the class.
*/
+ @Override
public String getClassName() {
return "JackEnv";
}
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.