简体   繁体   中英

RESTEasy giving null value as form params in a @DELETE method

I am working on designing restful web service API using REASTEasy. I have a workflow where I have to delete multiple items in a resource. The web service signature looks something like this

@DELETE
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
@Path("/directories/{directoryname}/documents")
public Response deleteDocuments(@FormParam("documentnames")final String documents, @PathParam("directoryname")final String directoryName)

I am making following request

DELETE /directories/1234/documents HTTP/1.1
Host: localhost:8080
Cache-Control: no-cache
Postman-Token: 45c0094f-1853-5710-2201-a1102a6acef0
Content-Type: application/x-www-form-urlencoded

documentnames=test

But when the method is invoked the form parameter "documentnames" is having the value as null even when I am passing its value as test as shown in the request.

Review your annotations again:

@Path("/directories/{directoryname}/documents")
public Response deleteDocuments(@FormParam("documentnames")final String documents, @PathParam("directoryname")final String directoryName)

@PathParam("directoryname") refers to {directoryname} in @Path definition while @FormParam("documentnames") should get data from form request. However your perform HTTP DELETE without form parameters. At least I do not see them in capture that your have sent.

Did you probably want to send directories as a path parameter too?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM