Apache Thrift Java-Javascript communication

て烟熏妆下的殇ゞ 提交于 2019-12-12 08:38:49

问题


I'm writing a Java server based on Apache Thrift, that will receive data from a Javascript client. I have completed the Java server, but the problem is that I can get a working example for the Javascript client (I was unable to find a good example for it). the examples in the build documentation aren't very helpful. My current Javascript client is below:

function testServer() {
    try {
        var transport = new Thrift.Transport("http://127.0.0.1:9090");
        var protocol  = new Thrift.Protocol(transport);
        var client = new JavaEventClient(protocol);

        var alive = client.isServerAlive();
    } catch(e) {
    }
}

testServer();  

But the code isn't working - as the Java server throws an "Out Of Memory" Error. I don't know if the error is due to my client code or Apache Thrift.

What am I doing wrong?


回答1:


Looks like problem problem in communications. Maybe you use different protocol or transport on server and client. or bug in implementations of that protocols. // as example I found bug with utf8 characters in thrift-javascript serialization.

Please looks on https://github.com/imysak/using-thrift (My friend and I wrote this simple example of communication Java-Node.js via thrift).

I hope you can use something from our JS implementation.




回答2:


The Out Of Memory error occurs when your server is using TBinaryProtocol but you try to access it in another way, e.g. using a browser (which speaks HTTP). IMO that is a bug. There should be some nice error message instead.

The files how to make a Thrift Java server work with an Thrift Javascript client are scattered throughout the source. I puzzled them together here: https://github.com/LukeOwncloud/ThriftJavaJavascriptDemo



来源:https://stackoverflow.com/questions/11820379/apache-thrift-java-javascript-communication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!