listener.on("binary", function(bytes, offset, length) {
     event.source.postMessage(bytes);
     semaphore.signal();
     server.stop();
     server.destroy();
     server = null;
 });
Beispiel #2
0
exports.setUp = function() {
    var handleRequest = function(env) {
        include('ringo/webapp/request');
        include('ringo/webapp/response');
        var req = new Request(env);
        req.charset = config.charset || 'utf8';
        req.pathInfo = decodeURI(req.pathInfo);
        var res = getResponse(req, env);
        if (res instanceof Response) {
           return res.close();
        }
        return res;
    };
   
    var config = {
       host: host,
       port: port
    };

    server = new Server(config);
    server.getDefaultContext().serveApplication(handleRequest);
    server.start();
    // FIXME without this the test may hang in some configurations
    java.lang.Thread.currentThread().sleep(1000);
};
 listener.on("text", function(message) {
     event.source.postMessage(message);
     semaphore.signal();
     server.stop();
     server.destroy();
     server = null;
 });
exports.testExceptions = function() {
   server = new Server(objects.merge({
      appName: 'jsgiAppExceptions'
   }, config));
   server.start();
   var exchange = httpclient.request({
      url: baseUrl,
      headers: acceptHeader
   });
};
Beispiel #5
0
  var httpServer = module.singleton('httpServer', function() {
      var httpServer = new Server({
       appModule: module.id,
       appName: 'rootApp',
       port: config.get('server').port
     });

      var staticContext = httpServer.getContext(config.get('server').staticMountpoint);
      staticContext.serveStatic(config.get('server').staticDir);
      return httpServer;
  });
Beispiel #6
0
exports.setUp = function() {
    var config = {
        host: host,
        port: port
    };

    server = new Server(config);
    server.getDefaultContext().serveApplication(function(req) {
        // this performs the actual test
        checkRequest(req);
        return response.html("");
    });
    server.start();
};
exports.testEvents = function() {
   server = new Server(objects.merge({
      appName: 'jsgiAppEvents'
   }, config));
   server.start();

   var exchange = httpclient.request({
      url: baseUrl,
      headers: acceptHeader
   });

   assert.equal(exchange.status, 200);
   assert.deepEqual(exchange.headers['X-Additional-Header'], ['ValueFoo']);
   assert.equal(exchange.content, 'data: \"testing foo bar\"\r\n\r\nevent: foo\r\ndata: zar\r\n\r\n: invisible\r\n\r\n');

};
var onmessage = function(event) {
    var {message, semaphore, isAsync} = event.data;
    var isBinary = (typeof message === "string");
    var server = new Server(config);
    server.start();
    server.getDefaultContext().addWebSocket(path, function(socket, session) {
        socket.on("text", function(message) {
            socket[isAsync ? "sendString" : "sendStringAsync"](message);
        });
        socket.on("binary", function(bytes, offset, length) {
            socket[isAsync ? "sendBinary" : "sendBinaryAsync"](bytes, offset, length);
        });
    });

    var client = new WebSocketClient();
    client.start();

    var socketUri = new URI(uri);
    var request = new ClientUpgradeRequest();

    var listener = new Listener();
    listener.on("connect", function(session) {
        var remote = session.getRemote();
        if (isBinary) {
            remote.sendString(message);
        } else {
            remote.sendBytes(ByteBuffer.wrap(message));
        }
    });
    listener.on("text", function(message) {
        event.source.postMessage(message);
        semaphore.signal();
        server.stop();
        server.destroy();
        server = null;
    });
    listener.on("binary", function(bytes, offset, length) {
        event.source.postMessage(bytes);
        semaphore.signal();
        server.stop();
        server.destroy();
        server = null;
    });
    client.connect(listener.impl, socketUri, request);
};
Beispiel #9
0
exports.setUp = function() {
    var handleRequest = function(req) {
        req.charset = 'utf8';
        req.pathInfo = decodeURI(req.pathInfo);
        return getResponse(req);
    };

    var config = {
        host: host,
        port: port
    };

    server = new Server(config);
    server.getDefaultContext().serveApplication(handleRequest);
    server.start();
    // test used to hang without this, but seems no longer the case
    // java.lang.Thread.currentThread().sleep(1000);
};
Beispiel #10
0
exports.serve = function(args) {
   // init instance config
   var config = require('../config');
   var path = args[0];
   config.init(path);

   // startup server & aggregator worker
   var aggregator = new Worker(module.resolve('../workers/aggregator'));
   // start workers
   aggregator.postMessage();
   config.data.hitQueue.postMessage();
   var server = new Server({
      host: config.data.http.host, 
      port: config.data.http.port, 
      appModule: module.resolve('../actions'),
      appName: 'app'
   });
   server.start();
}
Beispiel #11
0
exports.testOptions = function() {
    server.stop();
    var config = {
        host: host,
        port: port,
        sessions: false,
        security: false
    };
    server = new Server(config);
    server.start();
    var cx = server.getDefaultContext();
    assert.isNull(cx.getHandler().getSessionHandler());
    assert.isNull(cx.getHandler().getSecurityHandler());
    server.stop();
    // enable sessions
    config.sessions = true;
    config.security = true;
    server = new Server(config);
    server.start();
    cx = server.getDefaultContext();
    assert.isNotNull(cx.getHandler().getSecurityHandler());
    var sessionHandler = cx.getHandler().getSessionHandler();
    assert.isNotNull(sessionHandler);
    var sessionManager = sessionHandler.getSessionManager();
    assert.strictEqual(sessionManager.getSessionCookie(), "JSESSIONID");
    assert.strictEqual(sessionManager.getSessionDomain(), null);
    assert.strictEqual(sessionManager.getSessionPath(), null);
    assert.isFalse(sessionManager.getHttpOnly());
    assert.isFalse(sessionManager.getSecureCookies());
    server.stop();
    // configure session cookies
    config.cookieName = "ringosession";
    config.cookieDomain = ".example.com";
    config.cookiePath = "/test";
    config.httpOnlyCookies = true;
    config.secureCookies = true;
    server = new Server(config);
    server.start();
    cx = server.getDefaultContext();
    sessionManager = cx.getHandler().getSessionHandler().getSessionManager();
    assert.strictEqual(sessionManager.getSessionCookie(), config.cookieName);
    assert.strictEqual(sessionManager.getSessionDomain(), config.cookieDomain);
    assert.strictEqual(sessionManager.getSessionPath(), config.cookiePath);
    assert.isTrue(sessionManager.getHttpOnly());
    assert.isTrue(sessionManager.getSecureCookies());
};
Beispiel #12
0
	go.register('search', 'do', golr_callback_action);
	go.update('search');

	return response.promise;
    };
}

// Dynamic GOlr output.
app.get('/term/:query',
	create_request_function('ontology', 'ontology_class',
				'annotation_class', 'annotation_class_label',
				'term'));
app.get('/gene_product/:query',
	create_request_function('bioentity', 'bioentity',
				'bioentity', 'bioentity_label',
				'gene_product'));

///
/// Runner.
///

// Module juggle.
if (require.main == module) {
    //require('ringo/httpserver').main(module.id);
    //var {Server} = require('ringo/httpserver');
    var Server = require('ringo/httpserver').Server;
    //var server = new Server({app: app, port: port});  
    var server = new Server({app: app, host: host, port: port});  
    server.start();  
}
Beispiel #13
0
if (!fs.exists(configFile)) {
   configFile = module.resolve("./config.json");
}
if (!fs.exists(configFile)) {
   console.log('Missing config file', configFile);
   system.exit(1);
}
try {
   exports.config = JSON.parse(fs.read(configFile));
   exports.config.root = fs.join(homeDir, 'content');
   if (opts.contentdir) {
    exports.config.root = opts.contentdir;
   }
} catch (e) {
   console.log('Error parsing config file "', configFile ,'": ', e);
   system.exit(1);
}

exports.app = require("./actions").index;

// main script to start application
if (require.main == module) {
    var {Server} = require("ringo/httpserver");
    var httpServer = new Server({
        "appName": "app",
        "appModule": module.resolve('./main'),
        "port": exports.config.port || 8080
    });
    httpServer.start();
}