Coder Social home page Coder Social logo

jsonrpc2-elixir's People

Contributors

dkataskin avatar ericentin avatar fredericandre avatar gabrielgiordan avatar naps62 avatar nkmanolovsumup avatar ryanleecode avatar sashman avatar whitered avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonrpc2-elixir's Issues

TCP doesn't works for large messages

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.

Plug doesn't work with Content-Type: application/json

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?

Application level error handling

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.

Debugging a HTTP call

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 (

{:ok, 200, _headers, body_ref} <- response,
)

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.

Problems with Content-Type: application/json in 1.1.0

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}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.