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
リクエストであっても、ジャージーは最初に正規表現を探すようです。