cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: MediaType matching question
Date Fri, 09 Dec 2016 19:55:53 GMT
Hi Mark, oops,
sorry for the doubt earlier, but it looks like an obvious bug which CXF 
has not have :-), hence my doubt.
I've reproduced it, and indeed I agree it is not a CXF but the actual 
API bug, I've reproduced it:

type.equals(MEDIA_TYPE_WILDCARD) || other.type.equals(MEDIA_TYPE_WILDCARD

This statement makes sense for many cases but I agree it will confuse 
anyone who will see 'application/octet-stream' matching with '*/*+json'.

The problem is, it may be tricky convince the group it is a bug.
Lets give it a try:

https://java.net/jira/browse/JAX_RS_SPEC-538
(please vote and/or comment)


It does make sense to have


(type.equals(MEDIA_TYPE_WILDCARD) || 
other.type.equals(MEDIA_TYPE_WILDCARD) &&


(subtype.equals(MEDIA_TYPE_WILDCARD) || 
other.subtype.equals(MEDIA_TYPE_WILDCARD)

At the moment consider having something like "application/*+json" 
instead of "*/*+json"


Thanks, Sergey

On 09/12/16 18:47, Mark Struberg wrote:
> Yes it does, but it doesn't seem to be a CXF bug. The bug is in the RI API (and in geronimo
we ported the logic 1:1).
> I'm also not sure if this is a 'bug' in the API or in the spec.
>
> From a user pov it seems counter intuitive at least.
>
> LieGrue,
> strub
>
>> Am 09.12.2016 um 18:22 schrieb Sergey Beryozkin <sberyozkin@gmail.com>:
>>
>> Hmm,
>> are you saying CXF will match "*/*+json" against application/octet-stream ? I have
to sign off right now, but I honestly doubt it, I'll check later on.
>>
>>
>> Thanks, Sergey
>>
>>
>>
>> On 09/12/16 17:11, Mark Struberg wrote:
>>>> Do you expect a "*/*+json" match the application/octet-stream ?
>>>
>>>
>>> No, I did not expect that. But that's exactly how the code of MediaType#isCompatible
behaves currently :(
>>>
>>>
>>>
>>> LieGrue,
>>> strub
>>>
>>>
>>>
>>>
>>>> On Friday, 9 December 2016, 17:24, Sergey Beryozkin <sberyozkin@gmail.com>
wrote:
>>>>> Hi Mark, welcome,
>>>>
>>>> Do you expect a "*/*+json" match the application/octet-stream ?
>>>> And how is the method parameter accepting a multipart payload is typed,
>>>> as InputStream ?
>>>>
>>>> As a side note with WebClient you can use a more dedicated Attachment
>>>> code but on the server side, if you need to stay 100% compliant, then
>>>> yes, you;d need to read from InputStream and parse the payload manually
>>>> - CXF MultipartProvider will not touch it unless it is annotated with a
>>>> CXF specific annotation
>>>>
>>>> Cheers, Sergey
>>>>
>>>>
>>>> On 09/12/16 16:17, Mark Struberg wrote:
>>>>> While debugging through this didn't get used as far as I remember.
>>>>>
>>>>> Maybe MultipartProvider uses an alternative path to detect the handlers?
>>>>>
>>>>> LieGrue,
>>>>> strub
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> On Friday, 9 December 2016, 17:15, Romain Manni-Bucau
>>>> <rmannibucau@gmail.com> wrote:
>>>>>>> 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
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>>>>
>>>> --
>>>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Mime
View raw message