cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: MediaType matching question
Date Fri, 09 Dec 2016 16:14:32 GMT
Hey Mark,

have a look
to org.apache.cxf.jaxrs.provider.ProviderFactory.MessageBodyWriterComparator
(and the reader companion) maybe. Got aligned in cxf "jaxrs 2" for spec
alignment


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-12-09 17:10 GMT+01:00 Mark Struberg <struberg@yahoo.de.invalid>:

> good evening!
>
> My first post to CXF, so I excuse if I ask something obvious ;)
>
> We have the following code over in Apache OpenWebBeans / Meecrowave:
>
> @Produces({
>         "application/json", "*/json",
>         "*/*+json", "*/x-json",
>         "*/javascript", "*/x-javascript"
> })
> @Consumes({
>         "application/json", "*/json",
>         "*/*+json", "*/x-json",
>         "*/javascript", "*/x-javascript"
> })
> public static class ConfiguredJsonbJaxrsProvider<T> extends
> JsonbJaxrsProvider<T> {
>
> I tried to use the CXF WebClient to send a multipart form with a file
> attachment. MediaType is application/octet-stream.
> Sadly I always triggered our Johnzon JSONB provider (johnzon.apache.org).
>
> The reason is that */json seems to match ANY other MediaType, regardless
> of the subtype. Is this intended?
> The code I found during debugging is the following in geronimo-jaxrs_2.0
> MediaType:
>
> public boolean isCompatible(MediaType other) {
>     return other != null && (type.equals(MEDIA_TYPE_WILDCARD) ||
> other.type.equals(MEDIA_TYPE_WILDCARD) ||
>         (type.equalsIgnoreCase(other.type) && (subtype.equals(MEDIA_TYPE_WILDCARD)
> || other.subtype.equals(MEDIA_TYPE_WILDCARD))) ||
>         (type.equalsIgnoreCase(other.type) &&
> this.subtype.equalsIgnoreCase(other.subtype)));
> }
>
>
> I'm geronimo PMC myself so I can even fix it. But would need some feedback
> how it should behave.
> https://svn.apache.org/repos/asf/geronimo/specs/trunk/
> geronimo-jaxrs_2.0_spec/
>
> I did a quick look at the RI and now I'm even more confused:
>
>     public boolean isCompatible(MediaType other) {
>         return other != null && // return false if other is null, else
>                 (type.equals(MEDIA_TYPE_WILDCARD) ||
> other.type.equals(MEDIA_TYPE_WILDCARD) || // both are wildcard types, or
>                         (type.equalsIgnoreCase(other.type) &&
> (subtype.equals(MEDIA_TYPE_WILDCARD)
>                                 || other.subtype.equals(MEDIA_TYPE_WILDCARD)))
> || // same types, wildcard sub-types, or
>                         (type.equalsIgnoreCase(other.type) &&
> this.subtype.equalsIgnoreCase(other.subtype))); // same types & sub-types
>     }
>
> It says "both are wildcard types" but the code is actually ONE of them is
> a wildcard type, isn't?
>  (type.equals(MEDIA_TYPE_WILDCARD) || other.type.equals(MEDIA_TYPE_WILDCARD)
> || // both are wildcard types, or
>
>
> Any hints are highly welcome, my head is already hurting...
>
> What are the actual rules for matching MediaTypes? What does the spec
> define?
>
> txs and LieGrue,
> strub
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message