dongtu7567 2015-08-21 15:23
浏览 152

golang jsonrpc调用java json rpc

I was trying to connect golang programs with java programs by json rpc, but ran into some trouble. I use the "net/rpc/jsonrpc" package from golang native packages, and "jsonrpc4j" for java. I use stream mode to create a server in java, because golang's jsonrpc just supports tcp invoke. But it still gets the error response in golang client:

err: invalid error map[code:-32602 message:Invalid method parameters]

Meanwhile the java server is also encountering error:

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@385b5b5c; line: 1, column: 1] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3747) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3687) at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2202) at com.googlecode.jsonrpc4j.JsonRpcServer.handle(JsonRpcServer.java:224) at com.googlecode.jsonrpc4j.StreamServer$Server.run(StreamServer.java:214) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:744)

I don't understand why it does not work, is there any discipline that exists in the jsonrpc protocol that golang can't invoke java or do I just not do it right?

  • 写回答

1条回答 默认 最新

  • doubi1931 2015-08-24 00:10
    关注

    I wish I had a better answer. This is something that I was trying to make work earlier and couldn't get to happen. I've read that only Go clients can rpc to Go servers.

    There are two means which I resorted to after trying to make json/rpc work between Java and Go, maybe you can tailor something similar to your needs.

    In one case I used the net/http package and did a basic web server in Go and then used HandlerFunc to call functions/methods based on url requests. The requests were based on simple http form actions. I then redirected back to the main page as I wanted the "app" to stay in front of the user as I just needed the "/submit" url to trigger a method with the values passed in from the form.

    Not all that elegant but it worked in a pinch to rapidly set up a way to gather information and it could be instantly "deployed" by letting my colleagues know what port I was listening on.

    In the second case, since a friend of mine was programming the Java side I set up a socket a listed for a pattern of bytes that we had agreed on which would call a particular function.

    Not so adaptable but if you what what you're getting from the client it works out fine.

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题