Jersey switch on Content Type dynamically

两盒软妹~` 提交于 2019-12-11 09:52:55

问题


A similar question is here: Supporting both Multipart and Application Url Encoded parameters in Jersey

I have an API endpoint (in Jersey) that can accepts POST request. The content types are either: form-urlencoded, or multipart. The two types of request arrive at the same path. How do I switch on that?

For the urlencoded request, I want to get argument:

@FormParam("recipient") String recipient

For multipart request, I want to get:

@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail

Thanks!


回答1:


I think that Jersey only allows a single method for each unique @Path & @VERB pair, meaning that you'll either need to have one of those things use a different verb (POST and PUT) or you need two different paths. Before you just go and make one POST and the other PUT, make sure you understand how to properly use verbs in REST.



来源:https://stackoverflow.com/questions/19104413/jersey-switch-on-content-type-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!