Request compression

53 views
Skip to first unread message

mic...@yahoo.it

unread,
Sep 6, 2012, 10:38:00 AM9/6/12
to json...@googlegroups.com
Hi all,
I'm new of this group. Few days ago I began to use the jsonrpc4j library and I'd like to know how it is possible to compress the json request. I tried to use the invoke method with the Base64.OutputStream, but it seems not working.

Thanks a lot

Michele

Brian C. Dilley

unread,
Sep 6, 2012, 10:39:35 AM9/6/12
to json...@googlegroups.com
Base64 isn't compression, in fact it doubles the size.

You should be able to use GZip*Stream classes
> --
> You received this message because you are subscribed to the Google
> Groups "jsonrpc4j" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/jsonrpc4j/-/WETVASe5jpEJ.
> To post to this group, send email to json...@googlegroups.com.
> To unsubscribe from this group, send email to
> jsonrpc4j+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jsonrpc4j?hl=en.

micder

unread,
Sep 6, 2012, 10:52:18 AM9/6/12
to json...@googlegroups.com
Hi Brian,
thanks a lot for your reply. Could you please post a simple example about the compression?

Thanks a lot

Michele

Brian C. Dilley

unread,
Sep 6, 2012, 11:04:59 AM9/6/12
to json...@googlegroups.com
http://stackoverflow.com/questions/3477962/when-do-we-need-decorator-pattern

It really isn't specific to jsonrpc4j at all - it's just the decorator pattern.  All of java's streams inherit from InputStream or OutputStream and usually have a constructor that takes an implementation of the other.  ie:

OutputStream out = new FileOutputStream("file.txt.gz");
out.write("not compressed'.getBytes());

out = new GZIPOutputStream(out);
out.write("compressed'.getBytes());


Here's an example with the client:

// setup client
JsonRpcClient client = ...;

// setup stream
OutputStream out = ...;
GZIPOutputStream compressedOut = new GZIPOutputStream(out);

// invoke
client.invoke("someMethod", arg, compressedOut);
--
You received this message because you are subscribed to the Google Groups "jsonrpc4j" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jsonrpc4j/-/xn7rr6523xQJ.

micder

unread,
Sep 6, 2012, 11:14:24 AM9/6/12
to json...@googlegroups.com
Hi Brian,
I know the java streams, but the following code seems not working:

             JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(url));
             ByteArrayOutputStream os = new ByteArrayOutputStream();
             GZIPOutputStream zos = new GZIPOutputStream(os);
             client.invoke(method, params,zos,"0");  

I'm trying to send the request to an apache http server using a php json rpc. Using a protocol sniffer, I see no packets.

Bye

Michele

Brian C. Dilley

unread,
Sep 6, 2012, 11:18:04 AM9/6/12
to json...@googlegroups.com
inspect your ByteArrayOutputStream - you're writing to it, not the server.

Also, the client isn't going to send the proper headers to the server that way if you're expecting the server to identify the GZIP request.
To view this discussion on the web visit https://groups.google.com/d/msg/jsonrpc4j/-/Llq8e8rwZBYJ.

micder

unread,
Sep 6, 2012, 11:38:46 AM9/6/12
to json...@googlegroups.com
I saw that the ByteArrayOutputStream content is very strange: only the first three bytes are valorized before and after the invoke method call. Regarding the server, it is able to receive compressed requests.
Reply all
Reply to author
Forward
0 new messages