users@jersey.java.net

Re: [Jersey] Using "*" as a wildcard when searching for the Provider using the javax.ws.rs.ext.Providers interface

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 10 Jul 2009 11:00:04 +0200

On Jul 10, 2009, at 8:14 AM, Michael Elman wrote:

> Hi,
>
> I'm somewhat confused how "*" in the Media Type value should be
> treated, when using the javax.ws.rs.ext.Providers interface to get
> the providers (MessageBodyReaders/Writers and ContextResolvers)
> I mean should it be treated as a wildcard or as string?
>

A wildcard.


> For example if I have the following providers:
>
> @Produces("text/plain")
> class ProviderA implements MessageBodyWriter
>
> @Produces("text/*")
> class ProviderB implements MessageBodyWriter
>
> @Produces("text/xml")
> class ProviderC implements MessageBodyWriter
>
> If "*" is treated as a string, only ProviderB is matching.
> If "*" is treated as a wildcard, all three providers are matching.
>
> So what is correct?
>

If the media type to be written is "text/plain" then ProviderA and
ProviderB will be selected. The order in which the isWriteable methods
will be called is in the order of ProviderA and ProviderB (then those
supplied by Jersey).

If the media type to be written is "text/xml" then ProviderB and
ProviderC wll be selected. The order in which the isWriteable methods
will be called is in the order of ProviderC and ProviderB (then those
supplied by Jersey).

If the media type to be written is "text/html" then ProviderB will be
selected. The order in which the isWriteable methods will be called
is in the order of ProviderB (then those supplied by Jersey).

The media type to be written *has* to be a concrete media type (i.e.
not one that contains wild cards).

Hope that helps,
Paul.