-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
111 lines (106 loc) · 3.85 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const express = require('express')
const app = express()
const { JavaCaller } = require("java-caller");
const bodyParser = require('body-parser')
const Ftp = require( 'ftp' );
app.use(bodyParser.json())
app.get("/test", (req, res) => {
res.send("running")
})
app.get("/test1", (req, res) => {
//res.send("running")
const exec = require('child_process').exec;
const childPorcess = exec('java -jar NodeAppProject.jar "Jar is invoked by Node js"', function(err, stdout, stderr) {
if (err) {
//console.log(err)
res.send(err)
}
//console.log(stdout)
res.send(stdout)
})
})
// Run asynchronously to use the returned status for process.exit
app.get("/", (req, res) => {
(async () => {
try {
//await runExample();
const java = new JavaCaller({
classPath: 'NodeAppProject.jar', // CLASSPATH referencing the package embedded jar files
mainClass: 'nodeappproject.NodeAppProject',// Main class to call, must be available from CLASSPATH,
rootPath: __dirname,
});
const { status, stdout, stderr } = await java.run();
//console.log(stdout);
res.send(stdout);
} catch (err) {
console.error("Unexpected error: " + err.message + "\n" + err.stack);
process.exitCode = 1;
}
})();
})
app.get("/big", (req, res) => {
(async () => {
try {
//await runExample();
const java = new JavaCaller({
classPath: 'WordFileMgtNodeJS.jar', // CLASSPATH referencing the package embedded jar files
mainClass: 'wordfilemgtnodejs.WordFileMgtNodeJS',// Main class to call, must be available from CLASSPATH,
rootPath: __dirname,
});
const { status, stdout, stderr } = await java.run();
console.log(stdout);
res.send(stdout);
} catch (err) {
console.error("Unexpected error: " + err.message + "\n" + err.stack);
process.exitCode = 1;
}
})();
})
// Example function
async function runExample() {
const java = new JavaCaller({
classPath: 'NodeAppProject.jar', // CLASSPATH referencing the package embedded jar files
mainClass: 'nodeappproject.NodeAppProject',// Main class to call, must be available from CLASSPATH,
rootPath: __dirname,
});
const { status, stdout, stderr } = await java.run();
console.log(stdout);
}
app.post("/11", (req, res) => {
const fs = require('fs');
(async () => {
try {
//await runExample();
const java = new JavaCaller({
classPath: 'AuditSoftMCQFillProject.jar', // CLASSPATH referencing the package embedded jar files
mainClass: 'auditsoftmcqfillproject.AuditSoftMCQFillProject',// Main class to call, must be available from CLASSPATH,
rootPath: __dirname,
});
const { status, stdout, stderr } = await java.run(['abc', req.body['args']]);
//console.log(stdout);
//res.send(stdout);
fs.readFile('application_doc.pdf', function(err, buffer){
const ftpClient = new Ftp();
//console.log(req.file);
ftpClient.on( 'ready', function() {
ftpClient.put( buffer, '/public_html/temp_files/app_doc.pdf', function( err, list ) {
if ( err ) throw err;
ftpClient.end();
res.send('done');
});
});
ftpClient.connect( {
'host': 'ftp.cwac.in',
'user': 'cwacin',
'password': '$Rv01111996'
} );
})
} catch (err) {
console.error("Unexpected error: " + err.message + "\n" + err.stack);
process.exitCode = 1;
}
})();
})
app.listen(process.env.PORT || 5000, () => {
console.log("listening")
})