In a recent project our team was building a data visualization tool using a world map. The front-end was created using SAPUI5 and the backed runs on HANA using XSJS Services to deliver the data to the front-end.
To display a map on which we can visualize our data, the application needs to fetch map tiles from a separate server on the same network as our HANA machine. However, the HANA XS Server can only be accessed using HTTPS, while the map server only supportes HTTP. Using both in conjunction on one web application leads to a Mixed-Content error in the web browser blocks its execution. In order to circumvent this Mixed-Content error, we require some kind of proxy to map the tile server's HTTP resource to HTTPS. Since I did not have access to the server infrastructure, I was limited to using HANA native technolgy to solve this issue.
For this, I implemented a simple proxy using XS HTTP destinations. This approach is flexible and very easy to implement. I hope it will help some of you in case you have similar troubles or if you simply want to reroute a remote resource to your HANA server.
The proxy consists of 3 HANA development artifacts:
description = "Map Tile Server";
host = "<URL of the server>";
port = 80;
useProxy = false;
useSSL = false;
authType = none;
timeout = -1;
{
"exposed" : true,
"authentication" : {
"method": "Basic"
},
"rewrite_rules": [{
"source": "renderMap",
"target": "proxy.xsjs"
}],
"cache-control": "no-cache no-store"
}
function proxy() {
var destPackage = "path.to.your.destination";
var destName = "server";
// setup the HTTP connection
var dest = $.net.http.readDestination(destPackage, destName);
var client = new $.net.http.Client();
// send a POST request to the resource on the server we want to reroute
var req = new $.web.WebRequest($.net.http.POST, "/path/to/resource");
// set the content of the original request as request body
req.setBody($.request.body.asString());
// send the request and fetch the response
client.request(req, dest);
var response = client.getResponse();
$.response.status = $.net.http.OK;
// return the response
$.response.contentType = "application/json";
$.response.setBody(response.body.asString());
}
try {
proxy();
} catch (e) {
// return the error as JSON for debugging
var errorResponse = {"error": e.toString()};
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
$.response.contentType = "application/json";
$.response.setBody(JSON.stringify(errorResponse));
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
36 | |
25 | |
17 | |
13 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 |