Sending a POST

45 views
Skip to first unread message

Dean

unread,
Apr 27, 2011, 8:14:46 PM4/27/11
to jpoxy
Thanks for this utility. It has a lot of promise. However, I'm
having trouble making it respond to an invocation.

What I *can* do:
- GET using positional query params. For example:
http://172.18.1.115:8080/jsonrpc/jsonrpc?method=createUser&params=[%22Dean%22]
produces
{"result":"Dean","jsonrpc":"2.0"}

What I *can't* do:
- POST using a JSON file. For example, the file test.json contains:
{"jsonrpc": "2.0","method": "createUser","params":["Dean"]}
I use the following cURL:
curl -v http://localhost:8080/jsonrpc/jsonrpc -d @test.json -H
"Content-Type: application/json"

With expose_methods= true, I get:
{"result":{"method":
[{"static":false,"name":"createUser","class":"com.telespree.mbod.jsonrpc.Meter","params":
["java.lang.String"],"returns":"java.lang.String"},
{"static":false,"name":"listrpcmethods","class":"org.jpoxy.RPC","params":
[],"returns":"org.json.JSONObject"}]},"jsonrpc":"2.0"}

Which appears to be a failure condition.

I tried different things, like changing test.json, removing the curl -
H flag (default is www-url-encoded), etc. The only way it appears to
work is from a browser using a query string.

Any advice is appreciated.

Thanks.

-Dean

Wes Widner

unread,
Apr 30, 2011, 12:57:06 PM4/30/11
to jp...@googlegroups.com
Hey Dean, 

Thanks for the great idea! I've added the ability to process a json file upload as a command in the 1.0.19 release I uploaded a minute ago. 

I had to add two more dependencies, both from apache commons:
Right now it checks for file uploads in POST requests which have a Content-Type of multipart (the unit test I wrote uses multipart/form-data). If at least 1 upload is found it attempts to parse the contests of the file as a string.

Let me know if this isn't what you had in mind.

Thanks,
-Wes

Dean

unread,
May 5, 2011, 1:18:46 PM5/5/11
to jpoxy
Thanks Wes. It was truly amazing that I didn't need to change even
one line of code for this to happen. My development test seemed to
work. When I'm ready to send an RPC call from a remote process, I
will let you know if that worked as well.

I added the two new dependencies and used the command:

curl -v http://172.18.1.115:8080/jsonrpc/jsonrpc -F
"file=@test.json;type=application/json"

and received this response:

* Trying 172.18.1.115... connected
* Connected to 172.18.1.115 (172.18.1.115) port 8080 (#0)
> POST /jsonrpc/jsonrpc HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: 172.18.1.115:8080
> Accept: */*
> Content-Length: 236
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------6e3d3a92d585
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/plain
< Content-Length: 35
< Date: Thu, 05 May 2011 17:12:46 GMT
<
{"result":"Dean","jsonrpc":"2.0"}
* Connection #0 to host 172.18.1.115 left intact
* Closing connection #0

-Dean

===

On Apr 30, 9:57 am, Wes Widner <kai5263...@gmail.com> wrote:
> Hey Dean,
>
> Thanks for the great idea! I've added the ability to process a json file
> upload as a command in the 1.0.19 release I uploaded a minute ago.
>
> I had to add two more dependencies, both from apache commons:
>
>    - commons-fileupload <http://commons.apache.org/fileupload/>
>    - commons-io <http://commons.apache.org/io/>
>
> Right now it checks for file uploads in POST requests which have a
> Content-Type of multipart (the unit test I wrote uses multipart/form-data).
> If at least 1 upload is found it attempts to parse the contests of the file
> as a string.
>
> Let me know if this isn't what you had in mind.
>
> Thanks,
> -Wes
>
>
>
> On Wed, Apr 27, 2011 at 8:14 PM, Dean <dean.eb...@gmail.com> wrote:
> > Thanks for this utility.  It has a lot of promise.  However, I'm
> > having trouble making it respond to an invocation.
>
> > What I *can* do:
> > - GET using positional query params.  For example:
>
> >http://172.18.1.115:8080/jsonrpc/jsonrpc?method=createUser&params=[%22Dean%22]
> >  produces
> >      {"result":"Dean","jsonrpc":"2.0"}
>
> > What I *can't* do:
> > - POST using a JSON file.  For example, the file test.json contains:
> >      {"jsonrpc": "2.0","method": "createUser","params":["Dean"]}
> >  I use the following cURL:
> >      curl -vhttp://localhost:8080/jsonrpc/jsonrpc-d @test.json -H
> > "Content-Type: application/json"
>
> > With expose_methods= true, I get:
> > {"result":{"method":
>
> > [{"static":false,"name":"createUser","class":"com.telespree.mbod.jsonrpc.Me ter","params":
Reply all
Reply to author
Forward
0 new messages