onButtonPress: function(oEvent) {
var this_ = this;
var partnernumber = oView.byId("input").getValue();
console.log(partnernumber);
this_.wasteTime();
var CLIENT_ID_str = 'REPLACE_WITH_CLIENT_ID';
var CLIENT_SECRET_str = 'REPLACE_WITH_CLIENT_SECRET';
$.ajax({
type: 'POST',
url: "https://REPLACE_WITH_TOKEN_URL/uaa-security/oauth/token",
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
crossDomain: true,
cache: true,
dataType: 'json',
data: {
client_id: CLIENT_ID_str,
client_secret: CLIENT_SECRET_str,
grant_type: 'client_credentials',
},
success: function(data) {
console.log(data);
var access_token = data.access_token;
$.ajax({
url: restAPIURL,
type: 'POST',
headers: {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/x-www-form-urlencoded"
},
data: $.param({
"partnernumber": partnernumber
}),
async: true,
timeout: 0,
contentType: 'application/x-www-form-urlencoded',
success: function(data) {
this_.runNext();
console.log(data);
_score = data;
that._firePropertiesChanged();
this.settings = {};
this.settings.score = "";
that.dispatchEvent(new CustomEvent("onStart", {
detail: {
settings: this.settings
}
}));
},
error: function(e) {
this_.runNext();
console.log("error: " + e);
console.log(e);
}
});
},
error: function(e) {
this_.runNext();
console.log(e.responseText);
}
});
},
/*eslint no-console: 0, no-unused-vars: 0, no-undef:0, no-process-exit:0*/
/*eslint-env node, es6 */
"use strict";
const port = process.env.PORT || 3000;
const server = require("http").createServer();
//Initialize Express App for XSA UAA and HDBEXT Middleware
const xsenv = require("@sap/xsenv");
const passport = require("passport");
const xssec = require("@sap/xssec");
const express = require("express");
global.__base = __dirname + "/";
const https = require('https');
const http = require('http');
const cors = require('cors');
const querystring = require('querystring');
//logging
var logging = require("@sap/logging");
var appContext = logging.createAppContext()
//Initialize Express App for XS UAA and HDBEXT Middleware
var app = express();
app.use(cors());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from
res.header('Access-Control-Allow-Methods: OPTIONS,GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({
extended: true
})); // support encoded bodies
//Compression
app.use(require("compression")({
threshold: "1b"
}));
//Helmet for Security Policy Headers
const helmet = require("helmet");
// ...
app.use(helmet());
app.use(helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'", "sapui5.hana.ondemand.com"],
scriptSrc: ["'self'", "sapui5.hana.ondemand.com"]
}
}));
// Sets "Referrer-Policy: no-referrer".
app.use(helmet.referrerPolicy({ policy: "no-referrer" }));
passport.use("JWT", new xssec.JWTStrategy(xsenv.getServices({
uaa: {
tag: "xsuaa"
}
}).uaa));
app.use(logging.middleware({
appContext: appContext,
logNetwork: true
}));
app.use(passport.initialize());
app.use(
passport.authenticate("JWT", {
session: false
})
//xsHDBConn.middleware(hanaOptions.hana)
);
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200
}
// Redirect any to service root
app.get("/node", (req, res) => {
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.write('OK');
res.end();
});
app.post('/score', function(req, res) {
req.setTimeout(0);
console.log(req.body.partnernumber);
async function getPartnerNumber() {
let response = await doRequest(req.body.partnernumber);
console.log(response);
res.status(200).send(response)
}
getPartnerNumber();
})
function doRequest(partnernumber) {
console.log();
return new Promise((resolve, reject) => {
var post_data = querystring.stringify({
'partnernumber': partnernumber
});
// An object of options to indicate where to post to
var post_options = {
host: 'R_PLUMBER_SERVER',
port: 'R_PLUMBER_PORT',
path: '/score',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(post_data)
}
};
var body = '';
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
console.log('Response: ' + chunk);
body += chunk;
});
res.on('end', function() {
resolve(body);
});
});
post_req.write(post_data)
post_req.end();
});
}
//Start the Server
server.on("request", app);
//Start the Server
server.listen(port, function () {
console.info(`HTTP Server: ${server.address().port}`);
});
var CLIENT_ID_str = 'REPLACE_WITH_CLIENT_ID';
var CLIENT_SECRET_str = 'REPLACE_WITH_CLIENT_SECRET';
url: "https://REPLACE_WITH_TOKEN_URL/uaa-security/oauth/token"
var score = restAPI_1.getScore();
console.log("score: " + score);
TextArea_1.setValue(score);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
15 | |
9 | |
9 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |