Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug(notifications): Improve debug logging for notification callbacks #1225

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import org.springframework.http.RequestEntity
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Component
import retrofit.Endpoint
import retrofit.RetrofitError

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
import static retrofit.RetrofitError.Kind.HTTP

@CompileStatic
@Component
Expand Down Expand Up @@ -75,23 +79,33 @@ class NotificationService {
// the original body unmodified along to echo.
Endpoint echoEndpoint = serviceConfiguration.getServiceEndpoint("echo")

log.debug("Building echo request with URL ${echoEndpoint.url + request.url.path}, Content-Type: $contentType")
Request.Builder builder = new Request.Builder()
.url(echoEndpoint.url + request.url.path)
.post(RequestBody.create(mediaType, request.body))

request.getHeaders().each { String name, List values ->
values.each { value ->
log.debug("Relaying request header $name: $value")
builder.addHeader(name, value.toString())
}
}

Request echoRequest = builder.build();
Response response = okHttpClient.newCall(echoRequest).execute()

// convert retrofit response to Spring format
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()))
try {
Response response = okHttpClient.newCall(echoRequest).execute()
// convert retrofit response to Spring format
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()))
} catch (RetrofitError error) {
log.error("Error proxying notification callback to echo: $error")
if (error.getKind() == HTTP) {
throw error
} else {
return new ResponseEntity(INTERNAL_SERVER_ERROR)
}
}
}
}