java - How are Jersey @Consumes endpoints matched? -
i designing restful endpoint receive files. accept posting both plain file/stream , multipart. there rule how endpoints matched servlet container? code below work reliably, or implementation specific? can away wildcard, or have limit application_octet_stream?
@path("foo") public class foo { @post @path("{filename}") @consumes(mediatype.wildcard) public response uploadfiledirect( @pathparam("filename") string filename, inputstream is) { // process input stream response.ok().build(); } @post @path("{filename}") @consumes(mediatype.multipart_form_data) public response uploadfilemultipart( @pathparam("filename") string filename, @formdataparam("file") inputstream is) { // process input stream response.ok().build(); } }
this specified in jax-rs spec 3.7.2 request matching
[...]
resource class/object found , resource , sub resource methods put set
m[...]
- identify method handle request:
a. filtermremoving members not meet following criteria:
[...]
b. sortmin descending order follows:
* primary key media type of input data. methods@consumesvalue best match media type of request sorted first.
* secondary key@producesvalue. methods value of@producesbest matches value of request accept header sorted first.determining best matching media types follows general rule:
n/m>n/*>*/*, i.e. method explicitly consumes request media type or produces 1 of requested media types sorted before method consumes or produces*/*.
if @ last paragraph (that determines best matching), says */* (mediatype.wildcard) given least priority. more specific media types win.
Comments
Post a Comment