-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
83 lines (70 loc) · 2.63 KB
/
Copy pathserver.js
File metadata and controls
83 lines (70 loc) · 2.63 KB
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
const soap = require('soap');
const express = require('express');
const bodyParser = require('body-parser');
// Create an Express app
const app = express();
app.use(bodyParser.raw({ type: function() { return true; }, limit: '5mb' }));
app.use(express.json());
// Add middleware to log SOAP-specific information
app.use((req, res, next) => {
const timestamp = new Date().toISOString();
if (req.url.includes('?wsdl')) {
console.log(`[${timestamp}] Client requesting WSDL definition`);
} else if (req.method === 'POST') {
console.log(`[${timestamp}] SOAP request received from ${req.ip}`);
}
next();
});
// Define the service
const service = {
CalculatorService: {
CalculatorPort: {
add: function(args) {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}] SOAP operation: add`);
console.log(`SOAP request parameters: a=${args.a}, b=${args.b}`);
const n1 = parseInt(args.a);
const n2 = parseInt(args.b);
const result = n1 + n2;
console.log(`SOAP response: result=${result}`);
return { result: result };
},
subtract: function(args) {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}] SOAP operation: subtract`);
console.log(`SOAP request parameters: a=${args.a}, b=${args.b}`);
const n1 = parseInt(args.a);
const n2 = parseInt(args.b);
const result = n1 - n2;
console.log(`SOAP response: result=${result}`);
return { result: result };
}
}
}
};
// Read the WSDL file
const xml = require('fs').readFileSync('calculator.wsdl', 'utf8');
// Create the server
const server = app.listen(8000, '0.0.0.0', function() {
console.log('SOAP Server running at http://0.0.0.0:8000');
console.log('WSDL available at: http://0.0.0.0:8000/calculator?wsdl');
console.log('Waiting for SOAP clients to connect...');
});
// Create the SOAP server
soap.listen(app, '/calculator', service, xml);
// Handle graceful shutdown
process.on('SIGTERM', () => {
console.log('SIGTERM signal received: closing HTTP server');
server.close(() => {
console.log('HTTP server closed');
process.exit(0);
});
});
process.on('SIGINT', () => {
console.log('SIGINT signal received: closing HTTP server');
server.close(() => {
console.log('HTTP server closed');
process.exit(0);
});
});
// Handle