java.net.URI.relativize(java.net.URI) not really working

Discussion in 'Java' started by Stanimir Stamenkov, Aug 12, 2005.

  1. The java.net.URI.relativize(java.net.URI) method does its job exactly
    as described in the method documentation, but seems it has really no
    usage that way.

    I want to relativize:

    http://www.example.com/path/to/linked_resource

    against:

    http://www.example.com/path/to/resource

    The result from the URI.relativize() method is an absolute URI. It
    works as expected only when the path component of the base URI is
    prefix of the path of the URI to relativize, i.e. the above base needs
    to be:

    http://www.example.com/path/to/

    Doing this test I've noticed another thing which should be considered
    erroneous behavior according to the algorithm to resolve relative URIs.
    If the base is:

    http://www.example.com/path/to

    and the URI to relativize:

    http://www.example.com/path/to/linked_resource

    the result is still:

    linked_resource

    while I expect it to be:

    to/linked_resource

    The documentation for the URI class also describes
    <http://java.sun.com/j2se/1.4.2/docs/api/java/net/URI.html>:

    > Relativization, finally, is the inverse of resolution: For any two
    > normalized URIs u and v,
    >
    > u.relativize(u.resolve(v)).equals(v) and
    > u.resolve(u.relativize(v)).equals(v) .


    While I couldn't figure exactly what's the meaning of the above tests
    they both fail using:

    u = http://www.example.com/path/to
    v = http://www.example.com/path/to/linked_resource

    and the first fails when:

    u = http://www.example.com/path/to/
    v = http://www.example.com/path/to/linked_resource

    I've made my tests using the Sun's Java 1.4 on Windows.

    --
    Stanimir
     
    Stanimir Stamenkov, Aug 12, 2005
    #1
    1. Advertising

  2. /Stanimir Stamenkov/:

    > I want to relativize:
    >
    > http://www.example.com/path/to /linked_resource
    >
    > against:
    >
    > http://www.example.com/path/to /resource


    Here's a related issue at the Sun's Bug Database:

    "Bug ID: 6226081 URI should be able to relativize paths with partial
    roots" <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6226081>

    --
    Stanimir
     
    Stanimir Stamenkov, Aug 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Harris
    Replies:
    0
    Views:
    6,470
    Simon Harris
    May 10, 2005
  2. Pavel
    Replies:
    2
    Views:
    1,702
    Peter Flynn
    Aug 4, 2004
  3. etheriau
    Replies:
    1
    Views:
    688
    Pavel
    Aug 23, 2004
  4. Joe Curry

    Invalid URI: The format of the URI could not be determined.

    Joe Curry, Oct 8, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    372
    Joe Curry
    Oct 8, 2003
  5. Jay 99
    Replies:
    2
    Views:
    211
    Jay 99
    Apr 4, 2009
Loading...

Share This Page