fanduel / jsonrpc2-elixir Goto Github PK
View Code? Open in Web Editor NEWJSON-RPC 2.0 for Elixir
License: Other
JSON-RPC 2.0 for Elixir
License: Other
Hello!
I'm trying to do connect between two Elixir's apps (tcp client -> tcp server)
Basically all works fine (!!!)
But when I try to send a large message (more than one tcp packet limit), I got multiple error:
[error] JSONRPC2.Clients.TCP.Protocol received response with null ID: {:error, {-32700, "Parse error", nil}}
(multiple times, on client side)
Looks like the client try to split a message and to send it in multiple requests.
It looks as:
# full message (cropped, it means a large image in the base64 parameter)
%{"base64" => "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4REERXhpZgAATU0AKgAAAAgABAE7AAIAAAAcAAAISodpAAQAAAABAAAIZpydAAEAAAAeAAAQ3uocAAcAAAgMAAAAPgAAAAAc6gAA" <> ..., "caption" => ""}
# server receive splitted message as multiple messages and can't decode on each of them, so it do a response with error `Parse error` for each of them
# message 1
"{"params":[{"caption":"","base64":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4REERXhpZgAATU0AKgAAAAgABAE7AAAAA <> ..."
# message 2
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA <> ..."
# message 3
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA <> ..."
# last message:
"... <> ElFFFAgooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z"},{"id":"1"}],"method":"create_image","jsonrpc":"2.0","id":0}"
Any ideas what I can do with it?
Here is deps for both apps:
{:jsonrpc2, "~> 1.0"},
{:shackle, "~> 0.5"},
{:ranch, "~> 1.3.2"},
On application start on client app:
Client.TCP.start("localhost", 8001)
On application start on server app:
JSONRPC2.Servers.TCP.start_listener(Server.TCP, 8001)
All works fine for small messages.
When trying to access documentation from Hex.pm (https://hexdocs.pm/jsonrpc2), page is not found and a message is shown telling you to report such issue.
When using:
forward "/jsonrpc", JSONRPC2.Servers.HTTP.Plug, YourJSONRPC2HandlerModule
and sending via curl, a parse error occurs:
$ curl "localhost:4000/jsonrpc" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "method": "hello", "id": 1}'
{"jsonrpc":"2.0","id":null,"error":{"message":"Parse error","code":-32700}}%
Digging deeper, in JSONRPC2.Servers.HTTP.Plug, {:ok, req_body, conn} = Plug.Conn.read_body(conn)
sets req_body
to empty string. When inspecting the conn
, the incoming body is definitely there and has already been parsed in the params
field:
%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
...
params: %{"id" => 1, "jsonrpc" => "2.0", "method" => "hello"},
...
So when forcing Content-Type to plain text, the plug works as expected:
$ curl "localhost:4000/jsonrpc" -H "Content-Type: plain/text" -d '{"jsonrpc":"2.0", "method": "hello", "id": 1}'
{"result":"Hello!","jsonrpc":"2.0","id":1}%
Is this intended and I might have something misconfigured?
I have a Phoenix application using the JSONRPC2.Server.Handler
and we use Sentry for error collection. I'd like to be able to integrate Sentry error reporting.
The library currently has nice detailed error logging but I'd like to implement an handle_error
callback or similar to have JSONRPC2 handle the calls and response but allow the Rollbar, Sentry, other tool of choice be hooked in by the library user.
Thoughts on how this should look or if it's even in scope for the library, maybe this is doable now? I couldn't see an easy way without code change.
Hi all,
I'm getting the correct content, but receiving:
{:error,
{:invalid_response,
%{
"error" => nil,
"id" => "0",
"result" => [
which means the response code wasn't 200 (
)Can you advise how to switch on debug to see the response? This client uses hackney, so I presume it's a hackney_opts
Thanks.
When making a call via the http client no custom request id can be specified. The id is hardcoded to 0.
https://github.com/fanduel/jsonrpc2-elixir/blob/master/lib/jsonrpc2/clients/http.ex#L20
Hi, I think I am getting a similar problem to #8?
I am not sure but I think this still doesn't work if I run JSONRPC2 in a Supervisor. Here's the way to reproduce:
mix.exs:
defmodule JsonTest.MixProject do
use Mix.Project
def project do
[
app: :json_test,
version: "0.1.0",
elixir: "~> 1.6",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
extra_applications: [:logger],
mod: {JsonTest.Application, []}
]
end
defp deps do
[
{:jsonrpc2, "~> 1.1"}, {:poison, "~> 3.1"}, {:plug, "~> 1.3"}, {:cowboy, "~> 1.1"}
]
end
end
application.ex:
defmodule JsonTest.Application do
use Application
def start(_type, _args) do
children = [
JSONRPC2.Servers.HTTP.child_spec(:http, JsonTest)
]
opts = [strategy: :one_for_one, name: JsonTest.Supervisor]
Supervisor.start_link(children, opts)
end
end
json_test.ex:
defmodule JsonTest do
use JSONRPC2.Server.Handler
def handle_request(method, params) do
:ok
end
end
Then with JSONRPC2 1.1.0 as above I'm getting:
$ curl "localhost:4000/jsonrpc" -H "Content-Type: plain/text" -d '{"jsonrpc":"2.0", "method": "hello", "id": 1}'
{"result":"ok","jsonrpc":"2.0","id":1}
$ curl "localhost:4000/jsonrpc" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "method": "hello", "id": 1}'
{"jsonrpc":"2.0","id":null,"error":{"message":"Invalid Request","code":-32600}}
If I downgrade to 1.0.3 then all is good:
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
cowboy 1.1.2
cowlib 1.0.2
mime 1.3.0
plug 1.6.1
poison 3.1.0
ranch 1.3.2
Downgraded:
jsonrpc2 1.1.0 => 1.0.3
* Updating jsonrpc2 (Hex package)
$ curl "localhost:4000/jsonrpc" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "method": "hello", "id": 1}'
{"result":"ok","jsonrpc":"2.0","id":1}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.