Commit 583c1e241aac07b4530666e9e2028cd72a59a588
1 parent
8cb9af878e
Exists in
master
create server dan on report
Showing 2 changed files with 46 additions and 1 deletions Side-by-side Diff
package.json
... | ... | @@ -27,6 +27,7 @@ |
27 | 27 | "sate24": "git+http://git@gitlab.kodesumber.com/reload97/node-sate24.git", |
28 | 28 | "sate24-expresso": "git+http://gitlab.kodesumber.com/reload97/sate24-expresso.git", |
29 | 29 | "xmlrpc": "~1.3.1", |
30 | - "winston": "~2.1.1" | |
30 | + "winston": "~2.1.1", | |
31 | + "xml2js": "~0.4.15" | |
31 | 32 | } |
32 | 33 | } |
vre.js
1 | 1 | var xmlrpc = require('xmlrpc'); |
2 | +var xmlParser = require("xml2js").parseString; | |
2 | 3 | |
3 | 4 | var config; |
4 | 5 | var callbackReport; |
... | ... | @@ -26,4 +27,47 @@ function start(_config, _callbackReport, options) { |
26 | 27 | createServer(); |
27 | 28 | } |
28 | 29 | |
30 | +function createServer() { | |
31 | + var httpServer = http.createServer(onReverseReport).listen(config.h2h_out.listen_port, function() { | |
32 | + logger.info('HTTP Reverse/Report server listen on port ' + config.h2h_out.listen_port); | |
33 | + }); | |
34 | +} | |
35 | + | |
36 | +function onReverseReport(http_request, http_response) { | |
37 | + xmlParser(http_request, function(err, data) { | |
38 | + | |
39 | + if (err) { | |
40 | + logger.warn('Can not parse XML request', {http_request: http_request}); | |
41 | + http_response('Something wrong'); | |
42 | + return; | |
43 | + } | |
44 | + | |
45 | + var message; | |
46 | + var trx_id; | |
47 | + | |
48 | + try { | |
49 | + message = data.reporth2h.msg.join().trim(); | |
50 | + trx_id = data.reporth2h.msg.join().trim(); | |
51 | + } | |
52 | + catch(missingFieldError) { | |
53 | + logger.warn('Missing field on xml report', {http_request: http_request, error: missingFieldError}); | |
54 | + http_response('Something wrong'); | |
55 | + return; | |
56 | + } | |
57 | + | |
58 | + var trx_status = '68'; | |
59 | + | |
60 | + if (message.indexOf('Sukses') >= 0) { | |
61 | + trx_status = '00'; | |
62 | + } | |
63 | + else if (message.indexOf('Gagal') >= 0) { | |
64 | + trx_status = '40'; | |
65 | + } | |
66 | + | |
67 | + callbackReport(trx_id, trx_status, message); | |
68 | + }); | |
69 | +} | |
70 | + | |
71 | + | |
72 | + | |
29 | 73 | exports.start = start; |