0

When I create a new ClientResource, I usually do the following

ClientResource cr = new ClientResource("URI string");

Is there a way to recover the URI string later in time from cr?

tigerjack
  • 1,158
  • 3
  • 21
  • 39

2 Answers2

1

Here are some additional hints about this issue:

ClientResource cr = new ClientResource("http://www.google.fr:8182/test");

String hostDomain = cr.getReference().getHostDomain();
String hostIdentifier = cr.getReference().getHostIdentifier();
int hostPort = cr.getReference().getHostPort();
String path = cr.getReference().getPath();
String scheme = cr.getReference().getScheme();

System.out.println("hostIdentifier = "+hostIdentifier);
System.out.println("hostDomain = "+hostDomain);
System.out.println("scheme = "+scheme);
System.out.println("hostPort = "+hostPort);
System.out.println("path = "+path);

This will give you the following:

hostIdentifier = http://www.google.fr:8182
hostDomain = www.google.fr
scheme = http
hostPort = 8182
path = /test

You can notice that, if the port isn't explicitely specified in the URL, the value of hostDomain is -1.

Hope it helps, Thierry

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
0

Found the solution testing some get method. You can use CLientResource#getReference, inherited from the abstract class Resource. It returns a Reference object that is a

Reference to a Uniform Resource Identifier (URI). Contrary to the java.net.URI class, this interface represents mutable references. It strictly conforms to the RFC 3986 specifying URIs and follow its naming conventions. [...]

The fundamental point to underline is the difference between an URI "reference" and an URI. Contrary to an URI (the target identifier of a REST resource), an URI reference can be relative (with or without query and fragment part). This relative URI reference can then be resolved against a base reference via the getTargetRef() method which will return a new resolved Reference instance, an absolute URI reference with no base reference and with no dot-segments (the path segments "." and "..").

See here and here for more infos.

tigerjack
  • 1,158
  • 3
  • 21
  • 39