Skip to content

Commit

Permalink
fix(notifications): Ensure empty body on callback when appropriate (#…
Browse files Browse the repository at this point in the history
…1060)

* fix(notifications): Ensure empty body on callback when appropriate

* fix(notifications): Fix body conversion to string
  • Loading branch information
luispollo authored Feb 14, 2020
1 parent c825fc8 commit 9846de9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class NotificationService {
Response response = okHttpClient.newCall(echoRequest).execute()

// convert retrofit response to Spring format
String body = response.body().string()
String body = response.body().contentLength() > 0 ? response.body().string() : null
HttpHeaders headers = new HttpHeaders()
headers.putAll(response.headers().toMultimap())
return new ResponseEntity(body, headers, HttpStatus.valueOf(response.code()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class NotificationServiceSpec extends Specification {
.addHeader("multi-value-header", "value2")
.build()

Response expectedEchoResponse = mockEchoResponse(expectedEchoRequest)

when: "a request is received for processing"
ResponseEntity<String> response = notificationService.processNotificationCallback("someSource", incomingRequest)

Expand All @@ -85,7 +87,7 @@ class NotificationServiceSpec extends Specification {
echoRequest.headers() == expectedEchoRequest.headers()
echoCall
}
1 * echoCall.execute() >> mockEchoResponse(expectedEchoRequest)
1 * echoCall.execute() >> expectedEchoResponse

and: "returns the response from echo converted as appropriate"
response == new ResponseEntity<String>('{ "status": "ok" }', null, HttpStatus.OK)
Expand Down

0 comments on commit 9846de9

Please sign in to comment.