About Question enthuware.ocejws.v6.2.189 :

Moderators: Site Manager, fjwalraven

Post Reply
rkbansal83
Posts: 33
Joined: Sat Nov 24, 2012 8:52 am
Contact:

About Question enthuware.ocejws.v6.2.189 :

Post by rkbansal83 »

The question says
The HTTP request from the client has an Accept header of "image/jpeg;q=0.9,image/gif;q=0.8,application/xml"
It does not mention */* in the accept header of HTTP request

Why it should find a matching method whose media type (by default) is */* ?
does this mean */* is also a default media type of HTTP request even if not explicitly mentioned in HTTP accept header ?

Code: Select all

@GET
public String getText(@QueryParam("me") double meters,           @QueryParam("km") double kmPerHour)
 {    double seconds = convert(kmPerHour, meters);    return "" + seconds; }

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.ocejws.v6.2.189 :

Post by fjwalraven »

Hi,
does this mean */* is also a default media type of HTTP request even if not explicitly mentioned in HTTP accept header ?
No, request matching follows a certain algorithm. First it will look at the methods that have a @Produces annotation that matches the Accept header values.
An implementation MUST NOT invoke a method whose effective value of @Produces does not match the request Accept header.
When there is no matching method it will look for a method that has an @Produces("*/*") annotation because it produces all media types, including the ones that are in the Accept header.

The 4th option has no @Produces annotation, so it will have the default which is @Produces("*/*") and therefore this method is chosen.

Regards,
Frits

victor2016
Posts: 18
Joined: Wed Jan 20, 2016 7:16 pm
Contact:

Re: About Question enthuware.ocejws.v6.2.189 :

Post by victor2016 »

Hi,

But had there been an option with @Produces("application/xml") then that would have been the best answer?

Thanks.

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.ocejws.v6.2.189 :

Post by fjwalraven »

But had there been an option with @Produces("application/xml") then that would have been the best answer?
Yes!

Regards,
Frits

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests