Skip to content

@RequestMapping get '406 Not Acceptable' when change 'produces' order [SPR-16205] #20753

Closed
@spring-projects-issues

Description

@spring-projects-issues

Loi Huu Mai opened SPR-16205 and commented

I have a Rest API for download Media Resource. Inside this API, an exception would be thrown if some conditions are satisfied, no physical file found for example. I have a @ControllerAdvice class which will catch that exception and returns a JSON Object.

The problem is when an exception is thrown and caught in ControllerAdvice, if I had the produces with MediaType.APPLICATION_JSON_VALUE stand first, it will work fine, a JSON Object will be returned.

@RequestMapping(value = "/download", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE})
{
    "id": 2,
    "message": "Test message"
}

However, MediaType.APPLICATION_OCTET_STREAM_VALUE stand first, 406 Not Acceptable status will be returned

@RequestMapping(value = "/download", method = RequestMethod.GET, produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE, MediaType.APPLICATION_JSON_VALUE}

I did some debug into the framework and found this:
!Debug.png|thumbnail!

The result should be the same regardless the order of produces.


Affects: 4.3.12

Reference URL: https://github.com/maihuuloi123/accept_mapping_bug.git

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions