Hi experts,
We are trying to achieve Message Forwarding (HTTP) to handle messages send by IOT device. We wanted to process the incoming messages, convert into a specific format and needs to be stored in HCP table. To process the incoming messages from IOT device we have created a .xsjs service. Please find the attached word document to know the steps we have followed to achieve the same.
The issue is after sending the messages, it is not hitting the actual end point which in our case is xsjs service. But still we are getting response that 1 message received from device. We are not able to see any payload received from IOTMMS.
Steps followed :
Please see below detail level information :
Step1. Service Configuration:
{
"deviceType":"0525eff757bdfd608ac4",
"messageType":"3d79fcdb8226ce348fd3",
"processingServices":[
{
"name":"http",
"properties":{
"mms.processing.http.url":"https://jofa9908cdf9.hana.ondemand.com/IBAS/GENERAL/XSJS/Test_Message.xsjs",
"mms.processing.http.send_mode":"messages",
"mms.processing.http.auth_mode":"basicauth",
"mms.processing.http.basicauth.username":"xxxxxxx",
"mms.processing.http.basicauth.password":”xxxxxxx",
"mms.processing.http.proxy_enabled":"true",
"mms.processing.http.proxy_host":"proxy",
"mms.processing.http.proxy_port":"8080"
}
}
]
}
Step2. .XSJS file
(function() {
var messageDef = $.import("../../GENERAL/UTIL/MESSAGE.xsjslib");
var httpStatus;
var dbconn = $.db.getConnection();
var hdbconn = $.hdb.getConnection();
var failedResponse = function(message) {
var result = JSON.parse(messageDef.message); //message format
result.Message = message;
result.MessageType = messageDef.types.Error;
return result;
};
var successResponse = function(message) {
var result = JSON.parse(messageDef.message); //message format
result.Message = message;
result.MessageType = messageDef.types.Success;
return result;
};
var message = function() {
var input = getInput();
var device = input.device ;
var messageType = input.messageType;
var messages = input.messages;
var sql = 'INSERT INTO "SCHEMA"."TABLE" (DEVICE,MESSAGETYPE,MESSAGES) VALUES('+ "'" +input.device +"'"+ ',' +"'" + input.messageType +"'"+ ',' + "'"+input.messages+"'" + ')' ;
var res = hdbconn.executeUpdate(sql);
hdbconn.commit();
};
var getInput = function() {
if ($.request.body) {
var content = $.request.body.asString();
return JSON.parse(content);
} else {
var obj = {};
return obj;
}
};
var main = function() {
try {
var result = message();
if (result) {
$.response.setBody(JSON.stringify(result));
}
} catch (e) {
if (!httpStatus) {
httpStatus = $.net.http.BAD_REQUEST;
}
$.response.contentType = "application/json";
$.response.setBody(messageDef.failedResponse(e.message).body);
} finally {
dbconn.close();
hdbconn.close();
$.response.contentType = "application/json";
$.response.status = $.net.http.OK; //|| $.net.http.BAD_REQUEST;
}
};
main();
}(this));
Step3. Response for Service Configuration
{
"msg": "Processing service mapping with device type [0525eff757bdfd608ac4] and message type [3d79fcdb8226ce348fd3] has been registered"
}
Step4. Messaging through HTTP from MMS Cockpit
Refer step4.jpg
Step5. Response from HTTP API Server
Refer step5.jpg
Response from HTTP API server says success but still it seems end point is not hit because we are not able to see any payload received from IOTMMS.
Appreciate your help to resolve this issue.
Thanks,
Ankita