
{
"options": {
"management": true,
"messagingrest": true
},
"emname": "mesh"
}
# Generated manifest.yml based on template version 0.1.0
# appName = hanapi
# language=nodejs
# multitenancy=false
---
applications:
# -----------------------------------------------------------------------------------
# Backend Service
# -----------------------------------------------------------------------------------
- name: hanapi-srv
random-route: true # for development only
path: app
buildpack: nodejs_buildpack
command: node server.js
const exp = require('express');
const xenv = require('@sap/xsenv');
const hdbext = require('@sap/hdbext');
const axios = require('axios');
const app = exp();
//get data from EMSEND
app.get('/emsend', (req, res) => {
req.db.exec('SELECT * FROM "DBADMIN"."EMRECEIVE"', (err, rows) => {
if (err) {
res.type('text/plain').status(500).send(err);
};
res.status(200).json(rows);
});
});
//function for message push
let eventpush = async (baseuri, accesstok, body) => {
await axios.post(baseuri, body, {
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${accesstok}`,
'x-qos': 1
}
}).then(response => {
console.log('Queue API success');
console.log(response);
}).catch(err => {
console.log('err in Queue API');
console.log(err);
});
};
//function for token'
let eventmeshfun = async (token, tokenurl, baseuri, body) => {
await axios.post(tokenurl, {}, {
headers: {
'Authorization': `Basic ${token}`
}
}).then(response => {
console.log('response trigger');
console.log(response);//here we will get access token"
//post message to Queue API
eventpush(baseuri, response.data.access_token, body)
}).catch(err => {
console.log('err');
});
};
//push messages to Queue
app.post('/push', (req, res) => {
let lmessages = msgsrv['enterprise-messaging'].messaging;
let lhttp = lmessages.filter(lmessage => lmessage.protocol[0] == 'httprest');
let tokenurl = lhttp[0].oa2.tokenendpoint + '?grant_type=client_credentials&response_type=token';
let baseuri = lhttp[0].uri + '/messagingrest/v1/queues/HANAQUEUE/messages';
const username = lhttp[0].oa2.clientid;
const password = lhttp[0].oa2.clientsecret;
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64');
eventmeshfun(token, tokenurl, baseuri, req.body);
res.send('Data Push Done');
});
////Webhook subscription from QUEUE
app.post('/pull', (req, res) => {
let element = req.body;
req.db.exec('INSERT INTO "DBADMIN"."EMRECEIVE" VALUES(?,?,?)', [element.ID, element.DATA, element.Comments],
(err) => {
if (err) {
console.log(err);
}
});
{
"source": "^/emsend",
"target": "/emsend",
"destination": "geteventmesh"
},
{
"source": "^/push",
"target": "/push",
"destination": "geteventmesh"
}
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
],
/**
* @param {typeof sap.ui.core.mvc.Controller} Controller
*/
function (Controller,JSONModel) {
"use strict";
return Controller.extend("ui5app.controller.V1", {
onInit: function () {
//get data from HANA Service destination service
let oModel = new JSONModel();
let uri = '/emsend';
let that = this;
jQuery
.ajax({
url: uri,
type: "GET",
dataType: "json",
success: function (response) {
let data = { hana : ''};
data.hana = response;
oModel.setData(data);
console.log(oModel);
that.getView().setModel(oModel,"HANAMODEL");
},
error: function (err) {
console.log(err);
}
});
},
onPush: function (evt) {
let uri = '/push';
let that = this;
let data = { "ID":'',"DATA":'',"Comments":''};
data.ID = this.getView().byId("ID").getValue();
data.DATA = this.getView().byId("DATA").getValue();
data.Comments = this.getView().byId("Comments").getValue();
jQuery
.ajax({
url: uri,
type: "POST",
dataType: "json",
data: data,
success: function (response) {
console.log(response);
},
error: function (err) {
console.log(err);
}
});
},
onPress: function (evt) {
let uri = '/emsend';
let that = this;
jQuery
.ajax({
url: uri,
type: "GET",
dataType: "json",
success: function (response) {
let oModel = that.getView().getModel("HANAMODEL");
let data = { hana : ''};
data.hana = response;
oModel.setData(data);
console.log(oModel);
// that.getView().setModel(oModel,"HANAMODEL");
},
error: function (err) {
console.log(err);
}
});
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |