实施 Thrift API 时出错

发布于 2024-10-03 08:22:04 字数 1419 浏览 7 评论 0原文

我正在用 Java 实现 Thrift 远程过程调用框架。我设置了 thrift 并生成了我的框架代码,没有出现很多问题,但现在我实际上正在使用 API 方法,我遇到了奇怪的错误。

以下是我得到的错误:

Exception in thread "main" org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:163)
at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:91)
at SimonSays$Client.send_registerClient(SimonSays.java:102)
at SimonSays$Client.registerClient(SimonSays.java:96)
at simon.main(testClass.java:16)

我不认为我没有犯任何错误,但只是为了确保,这里是导致错误的代码:

TProtocol prot = new TBinaryProtocol(new TSocket("http://thriftpuzzle.facebook.com",9030));
    SimonSays.Client client = new SimonSays.Client(prot);

    client.registerClient("[email protected]");

据说该错误是从 client.registerClient 生成的() 调用,但那是对 Thrift 生成的代码的调用,这让我感觉我在设置连接本身时做错了什么。

关于制作 TProtocol 实例的部分我自己也包含在内,很可能这就是问题所在。

我希望有人能比我更了解我到底出了什么问题。

如果需要更多信息或澄清,请告诉我。

编辑:我从 Cassandra Wiki 找到了 TProtocol 实例化语句

I'm implementing the Thrift Remote Procedure call framework in Java. I set up thrift and generated my skeleton code without a lot of issues, but now that I'm actually using the API methods, I get strange errors.

Here are the errors I get:

Exception in thread "main" org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:163)
at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:91)
at SimonSays$Client.send_registerClient(SimonSays.java:102)
at SimonSays$Client.registerClient(SimonSays.java:96)
at simon.main(testClass.java:16)

I don't think I'm not making any mistakes, but just to make sure, here's the code that's leading to the errors:

TProtocol prot = new TBinaryProtocol(new TSocket("http://thriftpuzzle.facebook.com",9030));
    SimonSays.Client client = new SimonSays.Client(prot);

    client.registerClient("[email protected]");

The error is said to be generated from the client.registerClient() call, but that is a call to the code generated by Thrift, which makes me feel that I'm doing something wrong in setting up the connection itself.

The part about making a TProtocol instance I included myself, and it's likely that that's where the problem lies.

I was hoping that someone would have more of an idea about what's going wrong that I do.

Please let me know if more information or clarification is needed.

Edit: I found the TProtocol instantiation statement from the Cassandra Wiki

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2024-10-10 08:22:04

您需要在 TSocket 实例上调用 open() 方法,以便它连接并获取所需的输入/输出流。

来源:TSocket.java

You need to call the open() method on your TSocket instance in order for it to connect and obtain the input/output streams it needs.

Source: TSocket.java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文