简体   繁体   中英

debug not working for rest method PUT using postman rest client

I have two Uri's

POST : http://localhost:8080/applications/2851/involved-parties/1/contacts
PUT : http://localhost:8080/applications/2851/involved-parties/1/contacts

I am trying to debug methods,I have added breakpoint for both methods at starting, started server in debug mode. while sending json request using postman rest client for POST method cursor stop you at break point at POST method. but same request for PUT method does not work your cursor does not stop you at break point its directly giving response back to client.

@RequestMapping(value = "/applications/{applicationReferenceNumber}/involved-parties/{id}/contacts", method = RequestMethod.PUT)
@ResponseBody
public PutApplicationsResponse putContacts(@Valid @RequestBody final PutApplicationsRequest req,
        final BindingResult bind, @PathVariable(value = "applicationReferenceNumber") final Long arn,
        @PathVariable(value = "id") final Integer id, @RequestHeader final HttpHeaders httpHeaders,
        final HttpServletRequest reqHTTP) throws ContactsException, SQLException, MethodArgumentNotValidException,
                HttpMessageNotReadableException {

    reqHTTP.setAttribute(ExceptionConstants.ARN, arn);
    reqHTTP.setAttribute(ExceptionConstants.id, id);
    objMp = new ObjectMapper();

    if (bind.hasErrors()) {
        throw new MethodArgumentNotValidException(null, bind);
    }

FYI : I am testing negative scenario for both method eg length for id is 4 if I pass the 5 length for id then it has to return exception

Regards,

Normally with a PUT request to update, the particular resource URI should be known. So say the client makes a request to:

http://blah.com/applications/{applicationReferenceNumber}/involved-parties/{id}/contacts

Our service will look up the the id passsed. If it can't be found, we return a 404 status code, as the resource doesn't exist. If it does exist, then we update the contacts for the application id provided in the request. If you wanted to create a contacts, where the URI is not known, then POST would be correct, and you'd send a application id representation to:

http://blah.com/applications/{applicationReferenceNumber}/involved-parties/{id}/contacts

So basically if resource is available and we are doing put operation it will update directly on the server and also it is idempotent so evrytime you fire PUT request it will not do any other changes where as POST will create new resource every time and hence it will go through the code all the time.

在Postman中,您可能需要通过POST发送数据,然后将_method字段添加为请求的一部分。

_method:put

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