Skip to content

Commit

Permalink
Merge pull request #17 from hmrc/APID-65
Browse files Browse the repository at this point in the history
APID-65: add extra logging
  • Loading branch information
lburgos authored Jan 26, 2021
2 parents 24e81d3 + c0ab29b commit b1e0249
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class OutboundConnector @Inject()(appConfig: AppConfig, httpClient: HttpClient)(implicit ec: ExecutionContext) {
class OutboundConnector @Inject()(appConfig: AppConfig, httpClient: HttpClient)
(implicit ec: ExecutionContext) extends HttpErrorFunctions {

val logger: LoggerLike = Logger

def postMessage(message: String): Future[Int] = {
implicit val hc: HeaderCarrier = HeaderCarrier().withExtraHeaders(CONTENT_TYPE -> "application/soap+xml")

httpClient.POSTString[HttpResponse](appConfig.ccn2Url, message) map { response =>
if (response.status >= 400) {
if (!is2xx(response.status)) {
logger.warn(s"Attempted request to ${appConfig.ccn2Url} responded with HTTP response code ${response.status}")
}
response.status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ class OutboundService @Inject()(outboundConnector: OutboundConnector,
def sendMessage(message: MessageRequest): Future[OutboundSoapMessage] = {
val envelope = buildEnvelope(message)
outboundConnector.postMessage(envelope) flatMap { result =>
val globalId: UUID = randomUUID
val messageId = message.addressing.flatMap(_.messageId)
val outboundSoapMessage = if (is2xx(result)) {
SentOutboundSoapMessage(randomUUID, messageId, envelope, now)
logger.info(s"Message with global ID $globalId and message ID $messageId successfully sent")
SentOutboundSoapMessage(globalId, messageId, envelope, now)
} else {
RetryingOutboundSoapMessage(randomUUID, messageId, envelope, now, now.plus(appConfig.retryInterval.toMillis))
logger.info(s"Message with global ID $globalId and message ID $messageId failed on first attempt")
RetryingOutboundSoapMessage(globalId, messageId, envelope, now, now.plus(appConfig.retryInterval.toMillis))
}
outboundMessageRepository.persist(outboundSoapMessage).map(_ => outboundSoapMessage)
}
Expand All @@ -78,17 +81,20 @@ class OutboundService @Inject()(outboundConnector: OutboundConnector,
val nextRetryDateTime: DateTime = now.plus(appConfig.retryInterval.toMillis)
outboundConnector.postMessage(message.soapMessage) flatMap { result =>
if (is2xx(result)) {
logger.info(s"Retrying message with global ID ${message.globalId} and message ID ${message.messageId} succeeded")
outboundMessageRepository.updateStatus(message.globalId, SendingStatus.SENT) map { updatedMessage =>
updatedMessage.map(notificationCallbackConnector.sendNotification)
()
}
} else {
if (message.createDateTime.plus(appConfig.retryDuration.toMillis).isBefore(now.getMillis)){
logger.info(s"Retrying message with global ID ${message.globalId} and message ID ${message.messageId} failed on last attempt")
outboundMessageRepository.updateStatus(message.globalId, SendingStatus.FAILED).map { updatedMessage =>
updatedMessage.map(notificationCallbackConnector.sendNotification)
()
}
} else{
logger.info(s"Retrying message with global ID ${message.globalId} and message ID ${message.messageId} failed")
outboundMessageRepository.updateNextRetryTime(message.globalId, nextRetryDateTime).map(_ => ())
}
}
Expand Down

0 comments on commit b1e0249

Please sign in to comment.