Re: Respose URI in a MessageBodyReader on a Client

Jan Supol
 

Hi,

does ClientRequestContext#getUri help you?

Thanks,

Jan

On 25.06.2018 22:53, Martynas wrote:
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):
https://jsoup.org/apidocs/org/jsoup/Jsoup.html#parse-java.io.InputStream-java.lang.String-java.lang.String-

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
atomgraph.com <http://atomgraph.com>

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