Skip to Content
0

Issue with HCP IOT - Message Forwarding (HTTP) - XSJS service is not calling

May 22, 2017 at 11:36 AM

106

avatar image
Former Member

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 :

  1. Created Message Type, Device Type and Device
  2. Created a xsjs service contains logic to process the messages coming from IOT device
  3. Configured HTTP Processing Service by submitting an HTTP PUT request
  4. Send Messages through MMS Cockpit

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

step4.jpg (46.9 kB)
step4.jpg (46.9 kB)
step5.jpg (27.0 kB)
10 |10000 characters needed characters left characters exceeded

Hi,

I am facing same problem. Did you fix it?

Could you tell me please how you did it.

Regards,

0
* Please Login or Register to Answer, Follow or Comment.

0 Answers