users@jersey.java.net

Re: [Jersey] UriInfo additions?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 30 Apr 2009 13:50:17 +0200

Hi Casper,

Are you using a Web container?

Jersey does the following for servlet support:

         /**
          * The HttpServletRequest.getRequestURL() contains the
complete URI
          * minus the query and fragment components.
          */
         UriBuilder absoluteUriBuilder = UriBuilder.fromUri(
                 request.getRequestURL().toString());

         ...

         final String encodedBasePath = ...

         ...

         final URI baseUri =
absoluteUriBuilder.replacePath(encodedBasePath).
                 build();

         String queryParameters = request.getQueryString();
         if (queryParameters == null) {
             queryParameters = "";
         }

         final URI requestUri =
absoluteUriBuilder.replacePath(request.getRequestURI()).
                 replaceQuery(queryParameters).
                 build();


Apart from having to jump through hoops to get URIs nice and clean
using servlet!!! information such as protocol, authority, port etc.
are derived from the HttpServletRequest.getRequestURL().

Paul.


On Apr 30, 2009, at 1:43 PM, Casper Bang wrote:

> I really like the UriInfo and how it makes it easier to build
> references to resources, however I am missing a few things. Stuff
> like protocol, authority, port and anchor.
>
> For instance, when modeling resources that uses basic http
> authorization, UriInfo.getBaseUri() won't contain the authority part
> (user:pass@ of a URL) so browsers that do not cache this won't be
> able to follow the linked resources. I have of course written my own
> UrlUtils but it's much less elegant than if Jersey provided access
> to a few more "literals" of the URI spec (RFC 3986).
>
>
> Am I missing something, or is it simply the case that Jersey was
> optimized for the common scenario of dealing with just path segments
> and query parms?
>
> Regards,
> Casper
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>