diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/OutboundConnector.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/OutboundConnector.scala index cfd6159..7347db2 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/OutboundConnector.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/OutboundConnector.scala @@ -26,7 +26,8 @@ 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 @@ -34,7 +35,7 @@ class OutboundConnector @Inject()(appConfig: AppConfig, httpClient: HttpClient)( 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 diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala index 209ec2f..919fa31 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala @@ -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) } @@ -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(_ => ()) } }