users@jersey.java.net

[Jersey] Re: Using relative urls

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Mon, 6 Mar 2017 08:11:27 +0100

Hi Ravthiru,

WebTarget#path appends the argument to the existing path, see the javadoc:

/** * Create a new {_at_code WebTarget} instance by appending path to the
URI of * the current target instance.

...

You can always use URI/URL from java and its #resolve(...) method.
(target has #getUri() method).

Jersey client is usually the expensive part, WebTarget instances are
"for free", especially when you are changing only the URI. So the best
practice here is to keep the Client instance stored somewhere, reuse it
and create as many WebTarget instances as you want. (don't forget to
call Client#close() when you are done with that instance).

Regards,
Pavel


On 06/03/2017 02:15, ravthiru wrote:
> I am not able to fetch the resource using relative URL .
>
>
> Page URL is http://localhost:8080/page/123
> Image url is http://localhost:8080/image/1001
>
> While retrieving Page i send relative urls of the images,
> later i want to retrieve images using the base url
>
> I used below code to get the images, but it end up with resource not found
> (404)
>
> String base = "http://localhost:8080/page";
> String path = "../image/1001";
> WebTarget target = ClientBuilder.newClient().target(base);
> target=target.path(path);
> response = target.request().get();
>
> Is this correct way to use relative URl
>
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Using-relative-urls-tp7583941.html
> Sent from the Jersey mailing list archive at Nabble.com.