EzDevInfo.com

ringojs

RingoJS is a JavaScript platform built on the JVM and optimized for server-side applications. RingoJS - Multi-threaded JavaScript on the JVM

Simulate browser using RingoJs

I create a server that accessing a site as if the site is accessed by a browser. Some sites that my server need to access is required the execution of javascript, my question regarding RingoJs is: can I use RingoJs runtime to execute downloaded js from the accessed site?


Source: (StackOverflow)

ringojs fileupload example

Does anyone have an example of uploading a file to the server using ringojs?


Source: (StackOverflow)

Advertisements

How do I get the real filesystem path from within RingoJS webapp?

If I manage to get ServletContext object from java's HttpRequest, I'd manage to accomplish this, but I couldn't find out how to access these objects from Ringo wrappers.

This is needed to create a file inside the webapp with some saved information. The relative paths correspond to different absolute paths in different enviroment, so we need to find the webapp absolute filesystem path.


Source: (StackOverflow)

RingoJS javascript - get user input on console

When using Rhino or RingoJS, one can use print on the console REPL to print output (alert is not available).

What can be used to read user input on the console, instead of prompt?

Is there somewhere I can find information on these conventions, what APIs are available in Rhino and/or RingoJS, or is there a CommonJS guide they are adhering to?


Source: (StackOverflow)

Which platform are GMail server side JavaScript running on? [closed]

According to this question and this article, GMail server side is written in JavaScript. I'm wondering which platform is GMail server side JavaScript running on. Node.js? RingoJS?


Source: (StackOverflow)

Is using Node.js or Ringojs safe for live websites?

As stated in the title, I would like to know if it's safe to develop a website using one of the actuals "omg" platforms that are Node.js and Ringo.js at their actual version.

Also, I would like to know if they support cookies/sessions and how do they deals with multi-fields post (fieldname[] in PHP).

Thank you

--Edit--

Thanks for all the links guys.

What can you tell me about Ringojs ?

Since I haven't figured which platform to start playing with. I must admit that the fact it can use Java seamlessly really impress me. The only available XSLT 2.0 library is in Java. I could use it as a templating system.

Is there anyone who had the chance to play with Ringojs?


Source: (StackOverflow)

How to read an entire text stream in node.js?

In RingoJS there's a function called read which allows you to read an entire stream until the end is reached. This is useful when you're making a command line application. For example you may write a tac program as follows:

#!/usr/bin/env ringo

var string = system.stdin.read(); // read the entire input stream
var lines = string.split("\n");   // split the lines

lines.reverse();                  // reverse the lines

var reversed = lines.join("\n");  // join the reversed lines
system.stdout.write(reversed);    // write the reversed lines

This allows you to fire up a shell and run the tac command. Then you type in as many lines as you wish to and after you're done you can press Ctrl+D (or Ctrl+Z on Windows) to signal the end of transmission.

I want to do the same thing in node.js but I can't find any function which would do so. I thought of using the readSync function from the fs library to simulate as follows, but to no avail:

fs.readSync(0, buffer, 0, buffer.length, null);

The file descriptor for stdin (the first argument) is 0. So it should read the data from the keyboard. Instead it gives me the following error:

Error: ESPIPE, invalid seek
    at Object.fs.readSync (fs.js:381:19)
    at repl:1:4
    at REPLServer.self.eval (repl.js:109:21)
    at rli.on.self.bufferedCmd (repl.js:258:20)
    at REPLServer.self.eval (repl.js:116:5)
    at Interface.<anonymous> (repl.js:248:12)
    at Interface.EventEmitter.emit (events.js:96:17)
    at Interface._onLine (readline.js:200:10)
    at Interface._line (readline.js:518:8)
    at Interface._ttyWrite (readline.js:736:14)

How would you synchronously collect all the data in an input text stream and return it as a string in node.js? A code example would be very helpful.


Source: (StackOverflow)

How are daemon processes created in RingoJS?

I would like to use the ringo/daemon module to create daemon processes in RingoJS. However there doesn't seem to be sufficient documentation on how to do so, and I'm really confused. Any help would be greatly appreciated. Perhaps someone could link me to a page which explains how to get it done.


Source: (StackOverflow)

Running node.js module (more specifically YUIDoc) in a JVM

I want to run the node.js module YUIDoc in a JVM. The reason for this is that YUIDoc is my JavaScript documentation generator of choice, and that I want to be able to run it from a maven-plugin without having to install node.js, npm and such up front.

I have looked at SprintStack but it seems a bit immature so far.
Is there another way to do this?


Source: (StackOverflow)

How are native functions created in Rhino?

I've been looking at the Rhino documentation and source code for a clue as to how to implement my own global native function. This task is however more complicated than I expected it to be.

After reading the code of the implementation of the require function in RingoJS I believe I need to do something along the following lines:

import org.mozilla.javascript.BaseFunction;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Context;

public class MyGlobalNativeFunction extends BaseFunction {
    public MyGlobalNativeFunction() {}

    public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
        // implementation of my function
    }

    public int getArity() {
        return 1;
    }
}

Am I on the correct track? A step by step walkthrough on how to achieve this would be great.

Also it would be great if I could use Rhino's defineClass function to create my global native function. I'm not too keen on rolling out my own modified version of Rhino just because I want to implement one native function.


Source: (StackOverflow)

Reading and writing data using RingoJS on App Engine

Okay, I'm creating a RingoJS project and hosting it on Google App Engine. Now App Engine allows you to use java.io.FileInputStream to read data from the filesystem, but it doesn't allow you to use java.io.FileOutputStream to write data to the filesystem.

The data I would like to store is simple markdown for blog posts. Now I'm trying to learn how to store data using the High Replication Datastore API provided by App Engine, but I'm still confused as to how to do so.

If I'm not wrong, I need to do something along the following lines (in JavaScript):

// Get the High Replication Datastore API
importPackage(com.google.appengine.api.datastore);

// Create a new datastore
var datastore = DatastoreServiceFactory.getDatastoreService();

// Save the blog post
var blogPost = new Entity("BlogPost", uid, author.getKey());
blogPost.setProperty("markdown", markdown);
datastore.put(blogPost);

// Create the key for the blog post
var key = KeyFactory.createKey("BlogPost", uid, author.getKey());

// Getting the entity
var blogPost = datastore.get(key);

// Reading the properties
var markdown = blogPost.getProperty("markdown");

Is what I'm doing correct? Is there any other way to store persistent data easily? I only need to read and write data. I don't need queries.


Source: (StackOverflow)

How to access custom Java classes from RingoJS?

I have created a few classes in Java and have combined them into a single package in the 'org' namespace. How do I access them from RingoJS?

Must I copy the package into the 'src/org' directory in Ringo or do I have to modify the classpath dynamically from the script?


Source: (StackOverflow)

How are precompiled JavaScript modules loaded in RingoJS?

Okay, so I created a JavaScript file called test.js which contains the following code:

print("It works!");

I compiled it using the Rhino JavaScript Compiler without any errors. Then I created a new file called foo.js which contains this code:

var test = require("./test.class");

Now when I run foo.js in Ringo in throws the following exception and stack trace:

Uncaught exception:
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.ringojs.tools.launcher.Main.run(Main.java:66)
    at org.ringojs.tools.launcher.Main.main(Main.java:45)
Caused by: java.lang.NoClassDefFoundError: /home/aaditmshah/test (wrong name: test)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at org.mozilla.javascript.DefiningClassLoader.defineClass(DefiningClassLoader.java:62)
    at org.ringojs.engine.ClassModuleLoader.load(ModuleLoader.java:126)
    at org.ringojs.engine.ReloadableScript.compileScript(ReloadableScript.java:153)
    at org.ringojs.engine.ReloadableScript.getScript(ReloadableScript.java:118)
    at org.ringojs.engine.ReloadableScript.exec(ReloadableScript.java:227)
    at org.ringojs.engine.ReloadableScript.load(ReloadableScript.java:215)
    at org.ringojs.engine.RingoWorker.loadModuleInternal(RingoWorker.java:283)
    at org.ringojs.engine.Require.call(Require.java:81)
    at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
    at org.mozilla.javascript.gen._home_aaditmshah_foo_js_3._c_script_0(/home/aaditmshah/foo.js:1)
    at org.mozilla.javascript.gen._home_aaditmshah_foo_js_3.call(/home/aaditmshah/foo.js)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3178)
    at org.mozilla.javascript.gen._home_aaditmshah_foo_js_3.call(/home/aaditmshah/foo.js)
    at org.mozilla.javascript.gen._home_aaditmshah_foo_js_3.exec(/home/aaditmshah/foo.js)
    at org.ringojs.engine.ReloadableScript.evaluate(ReloadableScript.java:186)
    at org.ringojs.engine.RingoWorker.evaluateScript(RingoWorker.java:315)
    at org.ringojs.engine.RhinoEngine.runScript(RhinoEngine.java:186)
    at org.ringojs.tools.RingoRunner.run(RingoRunner.java:152)
    ... 6 more
enter code here

I don't know where am I going wrong. I have the latest versions of Ringo and Rhino 1.7R3. I added the current directory to my classpath by prepending the following line to foo.js:

addToClasspath(module.resolve("."));

However, it still generates the same error. I have no idea how to make this work. Any help will be greatly appreciated.


Source: (StackOverflow)

Using RingoJS EventEmitter... or how to use coffeescript compiler with RingoJS

I am trying to get the coffeescript compiler working with RingoJS (we're a Java shop...)

I have had some success - https://github.com/jashkenas/coffee-script/wiki/Using-CS-with-Java-Rhino

Now I am trying to get the coffee-script/command stuff ( https://github.com/jashkenas/coffee-script/blob/master/lib/coffee-script/command.js ) to work rather than re-doing it, but its failing on these lines:

CoffeeScript = require('./coffee-script');

_ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec;

EventEmitter = require('events').EventEmitter;

helpers.extend(CoffeeScript, new EventEmitter);

// fails here - EventEmitter is undefined and so the extend fails.

I have tried writing an adapter "events.js" to turn the ringojs/events into what its expecting, but my JS skills or lack of them are failing me.

This is what I have:

(function() {
    require("ringo/events");
    var events = { };
    events['EventEmitter'] = EventEmitter;
    return events;
}).call(this);

But EventEmitter is still undefined here - I'd expect it to be available due to the exports.EventEmitter line in ringojs/events, but obviously not...

Any thoughts/tips on where I am going wrong.

Thanks in advance, Chris


Source: (StackOverflow)

How can I set and read session data in RingoJS?

Good day,

I have recently started playing with RingoJS along with Stick middleware and I am now stuck with sessions. I can't make it work.

main.js

var {Application} = require( "./_lib_/stick" ),
    app = exports.app = Application();

app.configure( "mount" );
app.mount( "/", require( "./actions" ) );

if ( require.main === module ) {
    require( "ringo/httpserver" ).main( module.directory );
}

actions.js

var {Application, helpers} = require( "./_lib_/stick" ),
    Response = require( "ringo/jsgi/response" );

export( "app" );

var app = Application();

app.configure( "route", "render", "session" );
app.render.base = module.resolve( "templates" );
app.render.master = "page.html";

app.get("/session.htm", function( request ) {
    //request.session.data.foo = "bar";
    request.session.data.put("foo", "bar");

    return Response.redirect( "session2.htm" );
});

app.get("/session2.htm", function( request ) {
    var value = request.session;

    return Response.html( "Session: " + value );
});

I've tested many combinaison but none of them worked as espected.

Most errors I get is about reading the data from the session. For example:

TypeError: Cannot read property "data" from undefined

Any tips?


Source: (StackOverflow)