Fix header conversion when converting from Spring ResponseEntity to JAX-RS Response

This commit is contained in:
Georgios Andrianakis
2019-11-27 13:39:21 +02:00
committed by Guillaume Smet
parent 224bf0e024
commit 4fbbeba236
3 changed files with 4 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ public class ResponseEntityConverter {
private static Headers<Object> toHeaders(HttpHeaders springHeaders) {
Headers<Object> jaxRsHeaders = new Headers<>();
for (Map.Entry<String, List<String>> entry : springHeaders.entrySet()) {
jaxRsHeaders.addAll(entry.getKey(), entry.getValue());
jaxRsHeaders.addAll(entry.getKey(), entry.getValue().toArray(new Object[0]));
}
return jaxRsHeaders;
}

View File

@@ -26,7 +26,7 @@ public class CustomAdvice {
@ExceptionHandler(IllegalStateException.class)
public ResponseEntity<Error> handleIllegalStateException(IllegalStateException e,
HttpServletRequest request, HttpServletResponse response) {
return ResponseEntity.status(HttpStatus.PAYMENT_REQUIRED)
return ResponseEntity.status(HttpStatus.PAYMENT_REQUIRED).header("custom-header", "custom-value")
.body(new Error(request.getRequestURI() + ":" + e.getMessage()));
}

View File

@@ -82,7 +82,8 @@ public class SpringControllerTest {
RestAssured.when().get("/exception/responseEntity").then()
.contentType("application/json")
.body(containsString("bad state"), containsString("responseEntity"))
.statusCode(402);
.statusCode(402)
.header("custom-header", "custom-value");
}
@Test