Respose URI in a MessageBodyReader on a Client

Martynas
 

Hi,

suppose I am writing a MessageBodyReader (on Jersey 1.19) and I add register it in ClientConfig for use in the Client.

Is there any way to inject or otherwise supply the URI of the response being read? It is required in some cases to properly read the entity, for example baseUri in Jsoup.parse​(InputStream in, String charsetName, String baseUri):

MessageBodyReader.readFrom() supplies media type, HTTP headers and entity stream. As far as I know, no response header provides the response URI, other than Location in case of redirect, so no luck there.

On the server side this is not a problem as one can inject UriInfo, but I'm interested in the use with Client.

I could pass the baseUri into the MessageBodyReader implementation constructor, but I don't want to be creating a provider with each read, and anyway I don't see to a way to register it on a WebResource rather than Client/ClientConfig.

Is there a way to solve this in 1.x or 2.x or is my thinking flawed?

Thanks

Martynas

Join jersey@javaee.groups.io to automatically receive all group messages.