users@jersey.java.net

Re: [Jersey] Connectedness, Jaxb and link paths

From: tarjei <tarjei_at_nu.no>
Date: Wed, 24 Sep 2008 15:55:52 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marc Hadley wrote:
> On Sep 24, 2008, at 7:10 AM, tarjei wrote:
>>
>> I got two usecases:
>>
>> 1. A field with a link to a testservice for that url:
>>
>> <url href="/myservice/test/http://test.com">http://test.com</url>
>>
>> 2. Representing a mapping (*:* or 1:*) in the representation without
>> showing the complete object:
>> <subscribers>
>> <subscriber href="/subscribers/jonas_at_sm.com" id="1"
>> email="jonas_at_sm.com"/>
>> <subscriber href="/subscribers/jonas_at_sm.com" id="1"
>> email="jonas_at_sm.com"/>
>> </subscribers>
>>
>> I have already implemented an adapter to that works fairly well, however
>> it is not general, so if anyone has some tips on how I can create a
>> general linkadapter that will work without me defining the link every
>> time, that would be great. I'm planning to build a rest interface
>> against a DB with 50+ tables soon and I'll be needing it then.
>>
>> With regard to the first one, I want to keep the links inside the
>> resource somehow but with jax not knowing about them. Should I just use
>> some separate namespace for the links, like xlink?
>>
> I don't know how you'd define a general type adaptor, I think you'd
> either have to use the @XmlJavaTypeAdapter on each field that you want
> to make into a link or put it on the class assuming you always want
> links to instances of those types.
Hmm, ok. I'll keep searching.
>
>> Also, the last part of this question is, is there a general way to
>> generate absolute links?
>>
>> For example, if the service is running bellow the url /services/ on a
>> host named myservice running on port 8080, I want the links to be to
>> http://myservice:8080/services/...
>>
> Use
>
> @Context UriInfo u;
>
> to have Jersey inject the UriInfo into a field of your resource class.
> Then get a base URI builder from the instance when you want to build the
> absolute URI.
>
> URI link = u.getBaseUriBuilder().path(somePath).build();
Thanks, do you know a way to get this into a Jaxb XMLAdapter subclass? I
tried adding "@Context UriInfo u;" to the class but this didn't work
(nor did I expect it to). Any tips on how to provide context information
to jaxb?
>
> Note that you can pass a resource class to the path method and the
> UriBuilder will extract the @Path template to save you having to
> duplicate string constants.
Cool.

Kind regards,
Tarjei
>
> Marc.
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFI2kboYVRKCnSvzfIRAvB0AJjENGw7B+2XNFmdh4CJtcoJQ0j2AKCwiPCK
JZV9LiAvuhRvPJjI3VzYug==
=BPb6
-----END PGP SIGNATURE-----