vert-x / mod-lang-rhino Goto Github PK
View Code? Open in Web Editor NEWVert.x 2.x is deprecated - use instead
Home Page: https://github.com/vert-x3/vertx-lang-js
License: Other
Vert.x 2.x is deprecated - use instead
Home Page: https://github.com/vert-x3/vertx-lang-js
License: Other
Currently it is not possible to pass an augmented request through the RouteMatcher
to the individual route handlers:
httpServer.requestHandler(function (req1) {
req1.stuff = "my precious augmentation";
routeMatcher.call(req1);
});
routeMatcher.get('/somepath', function (req2) {
// req2.stuff is undefined because req1 !== req2
});
It is possible to mitigate this limitation by doing some bookkeeping:
var jreq_to_req = new java.util.HashMap();
httpServer.requestHandler(function (req1) {
req1.stuff = "my precious augmentation";
jreq_to_req.put(req._to_java_request(), req1);
routeMatcher.call(req1);
});
routeMatcher.get('/somepath', function (req2) {
var req1 = jreq_to_req.remove(req2._to_java_request());
// do stuff with req1.stuff
});
This example works as inside Java the same request gets passed around. But now we have the problem that each route handler has to do the necessary bookkeeping and there is a memory leak if we don't provide a custom noMatchHandler
.
This bookkeeping could be made more robust by pushing it down into the RouteMatcher
and offer the user an interface where req1 === req2
.
Gist here: https://gist.github.com/borego/6003136
Google groups thread here: https://groups.google.com/d/msg/vertx/Apw4xSv7jyA/mzPApknf5z8J
If a server has multiple requestHandler() functions tacked onto it (e.g. one as a RouteMatcher, one to catch all requests before the routes hit), if there's an outgoing request in the catch-all (e.g. to authenticate the user), the subsequent bodyHandler will not fire.
If you don't send a request in the first requestHandler (comment out lines 14, 16, 17 in the gist), everything seems to work fine, but otherwise the bodyHandler is never called and the request hangs.
There is a small glitch in the docs for "Flow Control - Streams and Pumps". The last example before introducing the Pump has to be modified to avoid data loss. In it's current form the data packet received by the handler, when the write queue is full will be discarded.
sock.dataHandler(function(buffer) {
if (!sock.writeQueueFull()) {
sock.write(buffer);
} else {
sock.pause();
sock.write(buffer); // <-- ADD THIS, OR DATA WILL BE LOST
sock.drainHandler(function() {
sock.resume();
});
}
});
Even if it is only an example, which is to be circumvented by using pump, people might still try it out and wonder. I guess it would then have to be adjusted in the manuals for the other languages, too.
(I know, a pull request would be nice, but I'm still a very old fashioned SVN guy - vertx might make me want to learn git at some point...)
See also:
eclipse-vertx/vert.x@633ccaa
Trying to chain commands after .timeout() gives an undefined error. I've fixed this in my local edition by adding "return that;" to the .timeout() function (line 1261 of https://github.com/vert-x/mod-lang-rhino/blob/master/src/main/api_shim/vertx/http.js)
In a previous release, the class RhinoVerticleFactory was including a piece of code that enable Eclipse debugging. In version 2.1.1 that piece of code seems missing. Could you consider to re-integrate it, in order to enable Javascript debugging within Eclipse ?
Below a possible patch applied to version 2.1.1 of the above class.
Thanks
Maurizio
In JavaScript readDirSync does currently not list the contents of a directory, when not filter is given.
The reason is that the filter is set to false as a default. It has to be set to null instead (File: file_system.js, line 506).
AsyncFile.write always write always writes to the beginning of a file, ignoring the position argument.
Also, the given handler is not called after a successful write, i.e. the handler argument is ignored, too.
Also, can we extend this to include event bus send reply failures?
I'm getting the error
TypeError: Cannot call property config in object org.vertx.java.platform.impl.DefaultContainer@3e481e39. It is not a function, it is "object".
at container.js:119 (anonymous)
at container.js:20
at vertx.js:18 (anonymous)
at vertx.js:17
at file:/Users/tyates/Code/Vert.x/mod-jdbc-persistor/src/test/resources/integration_tests/javascript/test_client.js:17
When running my tests against 2.0.0-SNAPSHOT
I am using the distro for vert.x-2.1M5, which includes
io.vertxlang-rhino2.0.0-final
At any rate any app I write dies with this error:
Failed in deploying verticle
org.mozilla.javascript.EvaluatorException: missing name after . operator (file:/usr/local/vert.x-2.1M5/sys-mods/io.vertxlang-rhino2.0.0-final/vertx/http.js#1029)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:96)
at org.mozilla.javascript.Parser.addError(Parser.java:146)
at org.mozilla.javascript.Parser.reportError(Parser.java:160)
at org.mozilla.javascript.Parser.memberExprTail(Parser.java:2015)
at org.mozilla.javascript.Parser.memberExpr(Parser.java:1953)
at org.mozilla.javascript.Parser.unaryExpr(Parser.java:1808)
at org.mozilla.javascript.Parser.mulExpr(Parser.java:1737)
at org.mozilla.javascript.Parser.addExpr(Parser.java:1718)
at org.mozilla.javascript.Parser.shiftExpr(Parser.java:1698)
at org.mozilla.javascript.Parser.relExpr(Parser.java:1672)
at org.mozilla.javascript.Parser.eqExpr(Parser.java:1628)
at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:1617)
at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:1606)
at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:1595)
at org.mozilla.javascript.Parser.andExpr(Parser.java:1583)
at org.mozilla.javascript.Parser.orExpr(Parser.java:1571)
at org.mozilla.javascript.Parser.condExpr(Parser.java:1554)
at org.mozilla.javascript.Parser.assignExpr(Parser.java:1539)
at org.mozilla.javascript.Parser.expr(Parser.java:1518)
at org.mozilla.javascript.Parser.statementHelper(Parser.java:1245)
at org.mozilla.javascript.Parser.statement(Parser.java:708)
at org.mozilla.javascript.Parser.parseFunctionBody(Parser.java:463)
at org.mozilla.javascript.Parser.function(Parser.java:592)
at org.mozilla.javascript.Parser.primaryExpr(Parser.java:2231)
at org.mozilla.javascript.Parser.memberExpr(Parser.java:1950)
at org.mozilla.javascript.Parser.unaryExpr(Parser.java:1808)
at org.mozilla.javascript.Parser.mulExpr(Parser.java:1737)
at org.mozilla.javascript.Parser.addExpr(Parser.java:1718)
at org.mozilla.javascript.Parser.shiftExpr(Parser.java:1698)
at org.mozilla.javascript.Parser.relExpr(Parser.java:1672)
at org.mozilla.javascript.Parser.eqExpr(Parser.java:1628)
at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:1617)
at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:1606)
at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:1595)
at org.mozilla.javascript.Parser.andExpr(Parser.java:1583)
at org.mozilla.javascript.Parser.orExpr(Parser.java:1571)
at org.mozilla.javascript.Parser.condExpr(Parser.java:1554)
at org.mozilla.javascript.Parser.assignExpr(Parser.java:1539)
at org.mozilla.javascript.Parser.assignExpr(Parser.java:1545)
at org.mozilla.javascript.Parser.expr(Parser.java:1518)
at org.mozilla.javascript.Parser.statementHelper(Parser.java:1201)
at org.mozilla.javascript.Parser.statement(Parser.java:708)
at org.mozilla.javascript.Parser.parse(Parser.java:401)
at org.mozilla.javascript.Parser.parse(Parser.java:359)
at org.mozilla.javascript.Context.compileImpl(Context.java:2254)
at org.mozilla.javascript.Context.compileReader(Context.java:1202)
at org.mozilla.javascript.commonjs.module.provider.CachingModuleScriptProviderBase.getModuleScript(CachingModuleScriptProviderBase.java:89)
at org.mozilla.javascript.commonjs.module.provider.SoftCachingModuleScriptProvider.getModuleScript(SoftCachingModuleScriptProvider.java:67)
at org.vertx.java.platform.impl.RhinoVerticleFactory$1.getModuleScript(RhinoVerticleFactory.java:153)
at org.mozilla.javascript.commonjs.module.Require.getModule(Require.java:363)
at org.mozilla.javascript.commonjs.module.Require.getExportedModuleInterface(Require.java:264)
at org.mozilla.javascript.commonjs.module.Require.call(Require.java:218)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
at org.mozilla.javascript.gen.c2._c0(file:/usr/local/vert.x-2.1M5/sys-mods/io.vertxlang-rhino2.0.0-final/vertx.js:67)
at org.mozilla.javascript.gen.c2.call(file:/usr/local/vert.x-2.1M5/sys-mods/io.vertxlang-rhino2.0.0-final/vertx.js)
at org.mozilla.javascript.gen.c2.exec(file:/usr/local/vert.x-2.1M5/sys-mods/io.vertxlang-rhino2.0.0-final/vertx.js)
at org.mozilla.javascript.commonjs.module.Require.executeModuleScript(Require.java:340)
at org.mozilla.javascript.commonjs.module.Require.getExportedModuleInterface(Require.java:288)
at org.mozilla.javascript.commonjs.module.Require.call(Require.java:218)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
at org.mozilla.javascript.gen.c1._c0(file:/Users/sowens/Documents/workspace/SessionService/app.js:1)
at org.mozilla.javascript.gen.c1.call(file:/Users/sowens/Documents/workspace/SessionService/app.js)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
at org.mozilla.javascript.gen.c1.call(file:/Users/sowens/Documents/workspace/SessionService/app.js)
at org.mozilla.javascript.gen.c1.exec(file:/Users/sowens/Documents/workspace/SessionService/app.js)
at org.mozilla.javascript.commonjs.module.Require.executeModuleScript(Require.java:340)
at org.mozilla.javascript.commonjs.module.Require.getExportedModuleInterface(Require.java:288)
at org.mozilla.javascript.commonjs.module.Require.requireMain(Require.java:137)
at org.vertx.java.platform.impl.RhinoVerticleFactory$RhinoVerticle.start(RhinoVerticleFactory.java:229)
at org.vertx.java.platform.Verticle.start(Verticle.java:82)
at org.vertx.java.platform.impl.DefaultPlatformManager$21.run(DefaultPlatformManager.java:1708)
at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:176)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:744)
I initially posted this in the eclipse bugzilla but maybe this is a better place for it.
In order to access a non-core Java class from rhino you need to use 'new Packages.mypackage.myclass()', but this discussion seems to state that the 'Packages' prefix should not be necessary:
https://groups.google.com/forum/#!topic/vertx/f2Jbl6-EyQE
I think perhaps only the core classes are available without using the 'Packages' prefix because they are explicitly added by the RhinoVerticleFactory? I don't really mind having to use the packages prefix, but if this is the correct behavior it should probably be documented in the JavaScript manual.
I have posted a sample module showing the issue here
https://dl.dropboxusercontent.com/u/52601024/frank~start-js-contained~1.0.zip
it can be run using
vertx runmod frank
start-js-contained1.0
Can you please confirm what is the correct behavior here?
thanks
Google Groups topic here
The ability to catch all incoming requests before they hit individual route matches would be excellent for code DRYness, as it would allow common functionality like authentication to occur inside this handler as opposed to inside each route handler.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.