Spring: Returning empty HTTP Responses with ResponseEntity doesn't work

前端 未结 6 1041
梦如初夏
梦如初夏 2020-12-05 09:47

We are implementing a REST API with Spring (4.1.1.). For certain HTTP requests, we would like to return a head with no body as a response. However, using ResponseEntit

6条回答
  •  春和景丽
    2020-12-05 10:10

    Personally, to deal with empty responses, I use in my Integration Tests the MockMvcResponse object like this :

    MockMvcResponse response = RestAssuredMockMvc.given()
                    .webAppContextSetup(webApplicationContext)
                    .when()
                    .get("/v1/ticket");
    
        assertThat(response.mockHttpServletResponse().getStatus()).isEqualTo(HttpStatus.NO_CONTENT.value());
    

    and in my controller I return empty response in a specific case like this :

    return ResponseEntity.noContent().build();
    

提交回复
热议问题