diff --git a/src/Center/Center.ts b/src/Center/Center.ts index 1b2ff11..73c2444 100644 --- a/src/Center/Center.ts +++ b/src/Center/Center.ts @@ -36,8 +36,8 @@ export class Center extends SmppSession { this.password = password; this.port = port; - this.setDefaultSingleJob(Job.createEmptySingle()); - this.setDefaultMultipleJob(Job.createEmptyMultiple()); + this.defaultSingleJob = Job.createEmptySingle(); + this.defaultMultipleJob = Job.createEmptyMultiple(); this.logger = new Logger(`Center-${id}`); diff --git a/src/HttpServer/CenterRequestHandler.ts b/src/HttpServer/CenterRequestHandler.ts index 2f0b8ac..47f2108 100644 --- a/src/HttpServer/CenterRequestHandler.ts +++ b/src/HttpServer/CenterRequestHandler.ts @@ -45,11 +45,11 @@ export class CenterRequestHandler extends RequestHandler { } doPost(req: any, res: any): void { - this.logger.log1("Creating client session"); + this.logger.log1("Creating center session"); this.sessionManager.createSession(req.body.port, req.body.username, req.body.password).then((session: SmppSession) => { res.send(session.serialize()); }, (err: any) => { - this.logger.log1(`Failed to create client session: ${err}`); + this.logger.log1(`Failed to create center session: ${err}`); res.status(500).send(); }); } diff --git a/src/HttpServer/HttpServer.ts b/src/HttpServer/HttpServer.ts index c77a1b0..1c1e589 100644 --- a/src/HttpServer/HttpServer.ts +++ b/src/HttpServer/HttpServer.ts @@ -24,39 +24,42 @@ export class HttpServer { this.app = express(); this.app.use(bodyParser.json()); - this.app.get('/api/client', this.clientRequestHandler.doGet.bind(this.clientRequestHandler)); - this.app.post('/api/client', this.clientRequestHandler.doPost.bind(this.clientRequestHandler)); - this.app.get('/api/client/:id', this.clientRequestHandler.doGetById.bind(this.clientRequestHandler)); - this.app.patch('/api/client/:id', this.clientRequestHandler.doPatch.bind(this.clientRequestHandler)); - this.app.put('/api/client/:id/send', this.clientRequestHandler.doConfigureSingleJob.bind(this.clientRequestHandler)); - this.app.post('/api/client/:id/send/default', this.clientRequestHandler.doSendSingleJob.bind(this.clientRequestHandler)); - this.app.post('/api/client/:id/send', this.clientRequestHandler.doSend.bind(this.clientRequestHandler)); - this.app.put('/api/client/:id/sendMany', this.clientRequestHandler.doConfigureManyJob.bind(this.clientRequestHandler)); - this.app.post('/api/client/:id/sendMany/default', this.clientRequestHandler.doSendManyJob.bind(this.clientRequestHandler)); - this.app.post('/api/client/:id/sendMany', this.clientRequestHandler.doSendMany.bind(this.clientRequestHandler)); - this.app.delete('/api/client/:id/sendMany', this.clientRequestHandler.doCancelSendMany.bind(this.clientRequestHandler)); - this.app.post('/api/client/:id/bind', this.clientRequestHandler.doBind.bind(this.clientRequestHandler)); - this.app.post('/api/client/:id/connect', this.clientRequestHandler.doConnect.bind(this.clientRequestHandler)); - this.app.delete('/api/client/:id/connect', this.clientRequestHandler.doDisconnect.bind(this.clientRequestHandler)); - this.app.delete('/api/client/:id', this.clientRequestHandler.doDelete.bind(this.clientRequestHandler)); + let clientApiPath = 'ClientEntity'; + let centerApiPath = 'CenterEntity'; - this.app.get('/api/center', this.centerRequestHandler.doGet.bind(this.centerRequestHandler)); - this.app.post('/api/center', this.centerRequestHandler.doPost.bind(this.centerRequestHandler)); - this.app.get('/api/center/:id', this.centerRequestHandler.doGetById.bind(this.centerRequestHandler)); - this.app.patch('/api/center/:id', this.centerRequestHandler.doPatch.bind(this.centerRequestHandler)); - this.app.put('/api/center/:id/send', this.centerRequestHandler.doConfigureSingleJob.bind(this.centerRequestHandler)); - this.app.post('/api/center/:id/send/default', this.centerRequestHandler.doSendSingleJob.bind(this.centerRequestHandler)); - this.app.post('/api/center/:id/send', this.centerRequestHandler.doSend.bind(this.centerRequestHandler)); - this.app.put('/api/center/:id/sendMany', this.centerRequestHandler.doConfigureManyJob.bind(this.centerRequestHandler)); - this.app.post('/api/center/:id/sendMany/default', this.centerRequestHandler.doSendManyJob.bind(this.centerRequestHandler)); - this.app.post('/api/center/:id/sendMany', this.centerRequestHandler.doSendMany.bind(this.centerRequestHandler)); - this.app.delete('/api/center/:id/sendMany', this.centerRequestHandler.doCancelSendMany.bind(this.centerRequestHandler)); - this.app.delete('/api/center/:id/connect', this.centerRequestHandler.doDisconnect.bind(this.centerRequestHandler)); - this.app.delete('/api/center/:id', this.centerRequestHandler.doDelete.bind(this.centerRequestHandler)); - this.app.get('/api/center/processors', this.centerRequestHandler.doGetAppliedProcessors.bind(this.centerRequestHandler)); - this.app.get('/api/center/processors/all', this.centerRequestHandler.doGetAvailableProcessors.bind(this.centerRequestHandler)); - this.app.post('/api/center/processors', this.centerRequestHandler.doAddProcessor.bind(this.centerRequestHandler)); - this.app.delete('/api/center/processors', this.centerRequestHandler.doRemoveProcessor.bind(this.centerRequestHandler)); + this.app.get(`/api/${clientApiPath}`, this.clientRequestHandler.doGet.bind(this.clientRequestHandler)); + this.app.post(`/api/${clientApiPath}`, this.clientRequestHandler.doPost.bind(this.clientRequestHandler)); + this.app.get(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doGetById.bind(this.clientRequestHandler)); + this.app.patch(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doPatch.bind(this.clientRequestHandler)); + this.app.put(`/api/${clientApiPath}/:id/send`, this.clientRequestHandler.doConfigureSingleJob.bind(this.clientRequestHandler)); + this.app.post(`/api/${clientApiPath}/:id/send/default`, this.clientRequestHandler.doSendSingleJob.bind(this.clientRequestHandler)); + this.app.post(`/api/${clientApiPath}/:id/send`, this.clientRequestHandler.doSend.bind(this.clientRequestHandler)); + this.app.put(`/api/${clientApiPath}/:id/sendMany`, this.clientRequestHandler.doConfigureManyJob.bind(this.clientRequestHandler)); + this.app.post(`/api/${clientApiPath}/:id/sendMany/default`, this.clientRequestHandler.doSendManyJob.bind(this.clientRequestHandler)); + this.app.post(`/api/${clientApiPath}/:id/sendMany`, this.clientRequestHandler.doSendMany.bind(this.clientRequestHandler)); + this.app.delete(`/api/${clientApiPath}/:id/sendMany`, this.clientRequestHandler.doCancelSendMany.bind(this.clientRequestHandler)); + this.app.post(`/api/${clientApiPath}/:id/bind`, this.clientRequestHandler.doBind.bind(this.clientRequestHandler)); + this.app.post(`/api/${clientApiPath}/:id/connect`, this.clientRequestHandler.doConnect.bind(this.clientRequestHandler)); + this.app.delete(`/api/${clientApiPath}/:id/connect`, this.clientRequestHandler.doDisconnect.bind(this.clientRequestHandler)); + this.app.delete(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doDelete.bind(this.clientRequestHandler)); + + this.app.get(`/api/${centerApiPath}`, this.centerRequestHandler.doGet.bind(this.centerRequestHandler)); + this.app.post(`/api/${centerApiPath}`, this.centerRequestHandler.doPost.bind(this.centerRequestHandler)); + this.app.get(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doGetById.bind(this.centerRequestHandler)); + this.app.patch(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doPatch.bind(this.centerRequestHandler)); + this.app.put(`/api/${centerApiPath}/:id/send`, this.centerRequestHandler.doConfigureSingleJob.bind(this.centerRequestHandler)); + this.app.post(`/api/${centerApiPath}/:id/send/default`, this.centerRequestHandler.doSendSingleJob.bind(this.centerRequestHandler)); + this.app.post(`/api/${centerApiPath}/:id/send`, this.centerRequestHandler.doSend.bind(this.centerRequestHandler)); + this.app.put(`/api/${centerApiPath}/:id/sendMany`, this.centerRequestHandler.doConfigureManyJob.bind(this.centerRequestHandler)); + this.app.post(`/api/${centerApiPath}/:id/sendMany/default`, this.centerRequestHandler.doSendManyJob.bind(this.centerRequestHandler)); + this.app.post(`/api/${centerApiPath}/:id/sendMany`, this.centerRequestHandler.doSendMany.bind(this.centerRequestHandler)); + this.app.delete(`/api/${centerApiPath}/:id/sendMany`, this.centerRequestHandler.doCancelSendMany.bind(this.centerRequestHandler)); + this.app.delete(`/api/${centerApiPath}/:id/connect`, this.centerRequestHandler.doDisconnect.bind(this.centerRequestHandler)); + this.app.delete(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doDelete.bind(this.centerRequestHandler)); + this.app.get(`/api/${centerApiPath}/processors`, this.centerRequestHandler.doGetAppliedProcessors.bind(this.centerRequestHandler)); + this.app.get(`/api/${centerApiPath}/processors/all`, this.centerRequestHandler.doGetAvailableProcessors.bind(this.centerRequestHandler)); + this.app.post(`/api/${centerApiPath}/processors`, this.centerRequestHandler.doAddProcessor.bind(this.centerRequestHandler)); + this.app.delete(`/api/${centerApiPath}/processors`, this.centerRequestHandler.doRemoveProcessor.bind(this.centerRequestHandler)); this.app.get('/api/ping', function (req: any, res: any) { res.send('pong'); diff --git a/src/HttpServer/RequestHandler.ts b/src/HttpServer/RequestHandler.ts index 04b296e..1a2d708 100644 --- a/src/HttpServer/RequestHandler.ts +++ b/src/HttpServer/RequestHandler.ts @@ -8,13 +8,13 @@ export abstract class RequestHandler { logger: Logger = new Logger(this.constructor.name); doGet(req: any, res: any): void { - this.logger.log1("Getting client sessions"); + this.logger.log1(`Getting sessions`); res.send(this.sessionManager.serialize()); } doGetById(req: any, res: any): void { this.sessionManager.getSession(req.params.id).then((session: SmppSession) => { - this.logger.log1(`Client session found with ID ${req.params.id}`) + this.logger.log1(`Session found with ID ${req.params.id}`) res.send(session.serialize()); }, this.handleSessionNotFound.bind(this, req, res)); } @@ -33,18 +33,19 @@ export abstract class RequestHandler { } doConfigureSingleJob(req: any, res: any): void { - this.sessionManager.getSession(req.params.id).then((session: SmppSession) => { + this.sessionManager.getSession(Number(req.params.id)).then((session: SmppSession) => { let job: Job = session.getDefaultSingleJob(); - if (job.pdu.source_addr && job.pdu.source_addr !== req.body.source) { + if (job.pdu.source_addr !== req.body.source) { job.pdu.source_addr = req.body.source; } - if (job.pdu.destination_addr && job.pdu.destination_addr !== req.body.destination) { + if (job.pdu.destination_addr !== req.body.destination) { job.pdu.destination_addr = req.body.destination; } - if (job.pdu.short_message && job.pdu.short_message !== req.body.message) { + if (job.pdu.short_message !== req.body.message) { job.pdu.short_message = req.body.message; } - this.logger.log1(`Updating default job on session with ID ${req.params.id}`) + this.logger.log1(`Updating default job on session with ID ${req.params.id}`); + res.send(session.serialize()); }, this.handleSessionNotFound.bind(this, req, res)); } diff --git a/src/SessionManager.ts b/src/SessionManager.ts index 845a29f..e9a76d4 100644 --- a/src/SessionManager.ts +++ b/src/SessionManager.ts @@ -46,7 +46,7 @@ export abstract class SessionManager { getSession(id: number): Promise { return new Promise((resolve, reject) => { this.logger.log1(`Looking for session with id ${id}...`); - let session: SmppSession | undefined = this.sessions.find(s => s.getId() === id); + let session: SmppSession | undefined = this.sessions.find(s => s.getId() == id); if (session) { this.logger.log1(`Found session with id ${id}`); resolve(session);