调试不使用休息方法PUT使用postman rest客户端

时间:2018-01-12 08:05:53

标签: java rest spring-mvc debugging postman

我有两个Uri's

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

我正在尝试调试方法,我在启动时为两个方法添加了断点,    以调试模式启动服务器。使用时发送json请求    POST方法光标的邮递员休息客户端在断点处阻止你    POST方法。但同样的PUT方法请求不起作用    光标不会阻止你在断点处直接给出响应    回到客户端。

@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);
    }

仅供参考:我正在测试两种方法的负面情况,例如: id的长度是4,如果我为id传递5长度,那么它必须返回异常

问候,

2 个答案:

答案 0 :(得分:0)

通常在PUT请求更新时,应该知道特定的资源URI。所以说客户提出要求:

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

我们的服务会查找已传递的ID。如果找不到,我们会返回404状态代码,因为资源不存在。如果它确实存在,那么我们更新请求中提供的应用程序ID的联系人。如果您想创建一个未知URI的联系人,那么POST将是正确的,并且您将应用程序ID表示发送到:

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

所以基本上如果资源可用并且我们正在进行put操作,它将直接在服务器上更新,并且它也是幂等的,所以evrytime你发出PUT请求它不会做任何其他更改,因为POST每次都会创建新资源因此它会一直通过代码。

答案 1 :(得分:0)

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

_method:put
相关问题