豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.35 KB

File metadata and controls

53 lines (41 loc) · 1.35 KB

This repository provides a small working example showing the use of Spring Boot and JSON-RPC. As JSON-RPC implementation jsonrpc4j is used.

The code is based on the post Is Java Remote Procedure Call Dead in the REST Age? written by Lieven Doclo.

build

mvn clean package

run the server

java -jar target/JsonRPC-0.0.1-SNAPSHOT.jar

send a JSON RPC request

Linux/OSX

curl -v -H "Content-Type: application/json" \
    -d '{"id":0, "method":"sayHelloWorld", "params":["John Doe"]}' \
    http://localhost:8080/rpc/myservice

Windows

curl -v -H "Content-Type: application/json"  ^
    -d "{\"id\":0, \"method\":\"sayHelloWorld\", \"params\":[\"John Doe\"]}" ^
    http://localhost:8080/rpc/myservice

output

> POST /rpc/myservice HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.45.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 57
> 
* upload completely sent off: 57 out of 57 bytes
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: application/json-rpc;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Wed, 16 Dec 2015 00:12:59 GMT
< 
{"jsonrpc":"2.0","id":0,"result":"Hello world, John Doe"}