Skip to content

Instantly share code, notes, and snippets.

@vietj
Created January 25, 2016 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vietj/51ff223bfb7cfcbc97ce to your computer and use it in GitHub Desktop.
Save vietj/51ff223bfb7cfcbc97ce to your computer and use it in GitHub Desktop.
var ShellService = require("vertx-shell-js/shell_service");
var CommandBuilder = require("vertx-shell-js/command_builder");
var CommandRegistry = require("vertx-shell-js/command_registry");
var service = ShellService.create(vertx, {
"telnetOptions" : {
"host" : "localhost",
"port" : 5000
}
});
service.start();
var client = vertx.createHttpClient();
var builder = CommandBuilder.command("http-client");
builder.processHandler(function (process) {
// Check the url argument
if (process.args().length < 1) {
process.write("Missing URL\n").end();
return;
}
var url = process.args()[0];
// Create the client request
var request = client.getAbs(url, function(response) {
// Print the response in the shell console
response.handler(function(buffer) {
process.write(buffer.toString("UTF-8"));
});
// End the command when the response ends
response.endHandler(function() {
process.end();
});
});
// Set a request handler to end the command with error
request.exceptionHandler(function(err) {
process.write("Error: " + err.getMessage());
process.end();
});
// End the http request
request.end();
});
// Register the command
var registry = CommandRegistry.getShared(vertx);
registry.registerCommand(builder.build(vertx));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment