diff --git a/bin/json_request.js b/bin/json_request.js new file mode 100755 index 000000000..0b9c08666 --- /dev/null +++ b/bin/json_request.js @@ -0,0 +1,42 @@ +#!/usr/bin/node +// +// This is a tool to issue JSON-RPC requests from the command line. +// +// This can be used to test a JSON-RPC server. +// +// Requires: npm simple-jsonrpc +// + +var jsonrpc = require('simple-jsonrpc'); + +var program = process.argv[1]; + +if (5 !== process.argv.length) { + console.log("Usage: %s ", program); +} +else { + var url = process.argv[2]; + var method = process.argv[3]; + var json_raw = process.argv[4]; + var json; + + try { + json = JSON.parse(json_raw); + } + catch (e) { + console.log("JSON parse error: %s", e.message); + throw e; + } + + var client = jsonrpc.client(url); + + client.call(method, json, + function (result) { + console.log(JSON.stringify(result, undefined, 2)); + }, + function (error) { + console.log(JSON.stringify(error, undefined, 2)); + }); +} + +// vim:sw=2:sts=2:ts=8:et diff --git a/bin/json_server.js b/bin/json_server.js new file mode 100755 index 000000000..4cd3ffb95 --- /dev/null +++ b/bin/json_server.js @@ -0,0 +1,68 @@ +#!/usr/bin/node +// +// This is a tool to listen for JSON-RPC requests at an IP and port. +// +// This will report the request to console and echo back the request as the response. +// + +var http = require("http"); + +var program = process.argv[1]; + +if (4 !== process.argv.length) { + console.log("Usage: %s ", program); +} +else { + var ip = process.argv[2]; + var port = process.argv[3]; + + var server = http.createServer(function (req, res) { + console.log("CONNECT"); + var input = ""; + + req.setEncoding(); + + req.on('data', function (buffer) { + // console.log("DATA: %s", buffer); + input = input + buffer; + }); + + req.on('end', function () { + // console.log("END"); + + var json_req; + + console.log("URL: %s", req.url); + console.log("HEADERS: %s", JSON.stringify(req.headers, undefined, 2)); + + try { + json_req = JSON.parse(input); + + console.log("REQ: %s", JSON.stringify(json_req, undefined, 2)); + } + catch (e) { + console.log("BAD JSON: %s", e.message); + + json_req = { error : e.message } + } + + res.statusCode = 200; + res.end(JSON.stringify({ + jsonrpc: "2.0", + result: { request : json_req }, + id: req.id + })); + }); + + req.on('close', function () { + console.log("CLOSE"); + }); + }); + + server.listen(port, ip, undefined, + function () { + console.log("Listening at: %s:%s", ip, port); + }); +} + +// vim:sw=2:sts=2:ts=8:et diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 97b3f1b34..215d239ce 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2499,6 +2499,8 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest) if (!mInfoSub && !jvRequest.isMember("url")) { // Must be a JSON-RPC call. + cLog(lsINFO) << boost::str(boost::format("doSubscribe: RPC subscribe requires a url")); + return rpcError(rpcINVALID_PARAMS); } @@ -2535,7 +2537,17 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest) ispSub = mInfoSub; } - if (jvRequest.isMember("streams")) + if (!jvRequest.isMember("streams")) + { + nothing(); + } + else if (!jvRequest["streams"].isArray()) + { + cLog(lsINFO) << boost::str(boost::format("doSubscribe: streams requires an array.")); + + return rpcError(rpcINVALID_PARAMS); + } + else { for (Json::Value::iterator it = jvRequest["streams"].begin(); it != jvRequest["streams"].end(); it++) { @@ -2550,12 +2562,10 @@ Json::Value RPCHandler::doSubscribe(Json::Value jvRequest) else if (streamName=="ledger") { mNetOps->subLedger(ispSub, jvResult); - } else if (streamName=="transactions") { mNetOps->subTransactions(ispSub); - } else if (streamName=="rt_transactions") {