reTHINK-project / dev-service-framework

DEPRECATED! Service framework libs have been moved to dev-runtime-core repo
Apache License 2.0
1 stars 2 forks source link

Parameters in messages are not consistent in the message factory and causing trouble when stringifying them #25

Closed jhamfler closed 8 years ago

jhamfler commented 8 years ago

Used branch: develop with npm install github:reTHINK-project/dev-service-framework#develop --save

I tried to use the message factory to send a message from a client to a messaging node. The response message had undefined for id, to and from while doing it the same way like you in your test cases. I think the error lies in the Message.js's constructor where the parameters are used differently than in MessageFactory.js's createMessageResponse.

The following test illustrates this. Simply save it as test.js and run it with node test.js while having the required packages available.

var ServiceFramework = require('service-framework');
var MessageFactory = ServiceFramework.MessageFactory;

var x, addresses=1;
console.log('ServiceFramework', ServiceFramework);
console.log('MessageFactory: ', MessageFactory);
console.log('new MessageFactory: ',mf = new MessageFactory(false,{}));

var message = mf.createCreateMessageRequest("hyperty-runtime-esn://domain.com/12345",
                ["hyperty-runtime-imei://domain.com/12345", "hyperty-runtime-imei://domain.com/678910"],
                "{audio: 'PCMU-Codec'}", "policyURL");
console.log('Message: ', message);

console.log("-------------------------------------------this works and this is how you use it in the message factory");
console.log(".id: ", message.id);
console.log("._id: ", message._id);

var stringimsg = JSON.stringify(message);
console.log("stringimsg: ", stringimsg);

var parsemsg = JSON.parse(stringimsg)
console.log("parsemsg: ", parsemsg);

console.log("-------------------------------------------this happens after stringifying it for the websocket");
console.log(".id: ", parsemsg.id);
console.log("._id: ", parsemsg._id);

var addr = {allocated: addresses};
var response = mf.createMessageResponse(JSON.parse(stringimsg),'200', addr);
console.log("Response: ",response);

I suggest we should use the same parameters in all cases like here, so without the underscores "_".

pchainho commented 8 years ago

A small note: you should only use hyperty-runtime scheme to address components in the Hyperty Runtime.

jhamfler commented 8 years ago

Thank you for the hint. You mean hyperty-runtime-esn:// and hyperty-runtime-ime:// should really be hyperty-runtime://, right? I just copied this from the test specs as it doesn't make a difference for that particular test.

acheambe commented 8 years ago

Message class object has been updated. Please test and let me know if you still encounter the problem

jhamfler commented 8 years ago

I downloaded the repo via npm again and the src/ directory seems good except the dist/ directory wasn't built. After I built it locally and replaced the old serviceframework.js it seemed to work fine.

I think the next step would be to make a dist, push it and close the issue. It would be great if you could do that as I don't want to tamper with this repo. Thank you for your help.

acheambe commented 8 years ago

Done