Reputation: 3938
I am trying to use node.js thrift client. I am getting error on server side
TSimpleServer exception: N6apache6thrift8protocol18TProtocolExceptionE: TProtocolException: Invalid data
How to fix this issue?
My sample .thrift file is:
struct Person{
1: required string name_;
2: required map<i64,string> attribute1_;
3: required map<i64,i64> attribute2_;
4: required map<i64,string> attribute3_;
}
service ProcessPerson {
void DoPerson(
1: required list<Person> person_array
)
}
node.js client code is:
var thrift = require('thrift');
var ttransport = require('./node_modules/thrift/lib/thrift/transport.js');
var tprotocol = require('./node_modules/thrift/lib/thrift/protocol.js');
var b_conn = thrift.createConnection('localhost', 9090, {transport: ttransport.TBufferedTransport ,protocol: tprotocol.TBinaryProtocol});
var ServicePerson = require('./person_js/ProcessPerson.js');
var type = require('./person_js/person_types');
b_conn.on('error', function(err) {
console.error("error");
console.error(err);
});
b_conn.on('connect', function(data) {
console.log('on conect');
var client = thrift.createClient(ServicePerson, b_conn);
var person_list = new Array();
var person_obj = new type.Person({name_:"aa", attribute1_:"",attribute2_:"",attribute3_: "" });
console.log(person_obj);
person_list.push(person_obj);
client.DoPerson(person_list, function() {
console.log("Hi");
});
});
I am using skeleton file at server side.
Upvotes: 0
Views: 1997
Reputation: 11
I have seen this problem before. The cause is that the struct message that received is not valid because it doesn't set the field which is "required" in thrift!
Please be sure that the client set all the required fields.
PS: I don't know how to check the node js code. I write code in C++ which I can check with __isset mechanism
Upvotes: 1