users@jersey.java.net

Re: namespace prefix mapping

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 09 Oct 2007 13:17:19 -0400

On Oct 9, 2007, at 12:16 PM, A S Manzoor wrote:
>
> So thats how Atom entries magically get morphed in and out :-) So
> technically, all the supported representations are in
> com.sun.ws.rest.impl.provider.entity.

Yes and each is listed in the file "javax.ws.rs.ext.EntityProvider"
in the META-INF.services directory so Jersey can find them.

> I will get to looking at the implementation to see how how I could
> create an XML representation of my objects. I have not looked at
> the annotations but What exactly does @ProduceMime and_at_ConsumeMime
> actually do? Do they do anything in terms of negotiating the
> representations? Again, thanks Marc,
>
They perform two functions:

(i) They serve to identify the method that Jersey will call. E.g. if
a class has two methods that will serve a GET request and one is
annotated @ProduceMime("application/xml") while the other is
annotated @ProduceMime("text/plain") the the former will be used if
the request has an Accept: application/xml header and the latter will
be called for a request that has an Accept: text/plain.

(ii) They serve to provide the default media type. e.g. a method that
returns String could support a number of different media types and
Jersey will default to application/octet-stream without any
additional information. If the method is annotated with @ProduceMime
("text/plain") then Jersey will use that media type for the response.
Note that you can be explicit about the media type by returning an
instance of Response from your method and setting the type in that.

Marc.

>
> On Oct 9, 2007, at 4:10 PM, Marc Hadley wrote:
>
>> On Oct 7, 2007, at 7:48 AM, A S Manzoor wrote:
>>>
>>> Is there anyway I can set the properties on the jaxb marshaller?
>>> I am using Jaxb to in and out XML representations and it would be
>>> nice to have readable namespace prefixes instead of ns1 and so
>>> on. Jersey is so good, I have no clue how its converting to and
>>> from XML (and i mean that as a compliment). It would be nice to
>>> get my hand on the marshaller to set the namespace prefix mapper.
>>> Thanks for your help.
>>>
>> There's currently no simple way to accomplish what you want. We
>> have discussed a few ideas related to application supplied JAXB
>> contexts but haven't decided on an approach yet.
>>
>> For now you could create your own custom JAXB entity provider and
>> bundle that with your application. Paul's blog entry[1] provides
>> lots of detail on how to do that and you could base your new
>> entity provider on the existing JAXB one:
>> com.sun.ws.rest.impl.provider.entity.JAXBElementProvider.
>>
>> Hope that helps.
>> Marc.
>>
>> [1] http://blogs.sun.com/sandoz/entry/plugable_types_with_jax_rs
>>
>>> Cheers
>>> su./hail
>>>
>>> --------------------------------------------------------------------
>>> -
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>> ---
>> 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
>>
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.