users@jersey.java.net

[Jersey] calling other web resources from a server web resource

From: Guarded Identity <tfh7hi102_at_sneakemail.com>
Date: Wed, 22 Aug 2012 21:40:06 -0500

Hi,

We'd like to implement a "batch" API using multipart/mixed media types similar
to something Google's doing with their Cloud Storage API [1].

[1] https://developers.google.com/storage/docs/json_api/v1/how-tos/batch#example

We'll have something like a "/batch" URL receiving a multipart/mixed request of
HTTP requests, which we'll then perform in pieces. Right now, we're
envisioning having something like a whole bunch of Futures composing the
execution a whole bunch of embedded Jersey clients running on some reasonable
executor service.

Essentially, the REST service will be calling itself several times. I know we
can @Context inject UriInfo to get our service's URI. However, we'd like to
avoid actually making a call out onto the TCP stack unnecessarily if we can.
We'll be handling these requests with the exact same JVM sending the requests,
so it seems wasteful. It doesn't seem like we can call the web resources
directly because we'd loose all the benefits of the Jersey lifecycle and
respect for the annotations we've applied. It would just be nice if there was
a way to inject a WebResource for our root.

Also, we haven't tried this out, but we're curious if it's possible to use a
relative URL:

    WebResource r = client.resource("/path/to/our/resource");

We suspect this might do one of a few things:

    1) exactly what we want

    2) work, but still send a request out on the local machine's TCP stack

    3) not work at all because we didn't provide a full URI.

Thanks for your recommendations and help.

-Sukant