Skip to content

Instantly share code, notes, and snippets.

@cleuton
Last active August 29, 2015 13:57
Show Gist options
  • Save cleuton/9670636 to your computer and use it in GitHub Desktop.
Save cleuton/9670636 to your computer and use it in GitHub Desktop.
A sails.js controller invoking a java class' method
/**
* TokenController
*
* @module :: Controller
* @description :: A set of functions called `actions`.
*
* Actions contain code telling Sails how to respond to a certain type of request.
* (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
*
* You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
* and/or override them with custom routes (`config/routes.js`)
*
* NOTE: The code you write here supports both HTTP and Socket.io automatically.
*
* @docs :: http://sailsjs.org/#!documentation/controllers
*/
module.exports = {
/**
* Action blueprints:
* `/gettoken/get`
*/
get: function (req, res) {
// Send a JSON response
var java = require('java')
java.classpath.push("C:/Users/cleuton/proj/sails.js/testProject/api/controllers/jsondao.jar")
var javaObject = java.newInstanceSync("com.obomprogramador.sails.test.SampleJava")
return res.json({
hello: javaObject.getTokenSync()
});
},
/**
* Overrides for the settings in `config/controllers.js`
* (specific to GetTokenController)
*/
_config: {}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment