实施 Thrift API 时出错
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在
TSocket
实例上调用open()
方法,以便它连接并获取所需的输入/输出流。来源:TSocket.java
You need to call the
open()
method on yourTSocket
instance in order for it to connect and obtain the input/output streams it needs.Source: TSocket.java