Jersey
是否可以使用相同的正则表达式但不同类型定义 2 个方法?( GET
, PUT
..):
@GET
@Path("{key: .+}")
@Produces(MediaType.TEXT_PLAIN)
public Response root(String key) {
}
@PUT
@Path("{key: .+}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public Response publish(String key, FormDataMultiPart data) {
}
第一种方法应该只回复密钥(带或不带斜杠)
curl -X GET "http://localhost/key
Jersey respond with 200 OK since it went to the GET method
curl -X GET "http://localhost/key/
Jersey respond with 200 OK since it went to the GET method
curl -X PUT -T file.txt "http://localhost/key
Jersey respond with 200 OK since it went to the PUT method
curl -X PUT -T file.txt "http://localhost/key/
Jersey respond with 200 OK since it went to the PUT method
curl -X PUT -T file.txt "http://localhost/key/folder/folder
Jersey respond with 405 Method Not Found since it went to the GET method
instead of the PUT (the get only respond to 1 folder level which is the 'key'
but i expected that jersey will go directly to the PUT since it suppose to check for the method type before the regex matching
为什么最后一个不起作用?似乎泽西岛首先寻找正则表达式,即使它是一个PUT
请求。