Skip to content

Commit

Permalink
APIS-7198 - Upgrading HttpClient to V2 (#116)
Browse files Browse the repository at this point in the history
* APIS-7198 - Upgrading HttpClient to V2

* APIS-7198 - PR Bot comments

* APIS-7198 - Removing acceptance reports config from build
  • Loading branch information
peteslater-ee authored Jul 15, 2024
1 parent 657bae7 commit bc34ba1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

import play.api.libs.json.Json
import uk.gov.hmrc.apiplatform.modules.common.domain.models.ClientId
import uk.gov.hmrc.http.HttpReads.Implicits._
import uk.gov.hmrc.http.{HeaderCarrier, HttpClient}
import uk.gov.hmrc.http.client.HttpClientV2
import uk.gov.hmrc.http.{HeaderCarrier, StringContextOps}
import uk.gov.hmrc.play.http.metrics.common._

import uk.gov.hmrc.apisubscriptionfields.config.ApplicationConfig
import uk.gov.hmrc.apisubscriptionfields.model.Types.FieldValue
import uk.gov.hmrc.apisubscriptionfields.model._

@Singleton
class PushPullNotificationServiceConnector @Inject() (http: HttpClient, appConfig: ApplicationConfig, val apiMetrics: ApiMetrics)(implicit ec: ExecutionContext)
class PushPullNotificationServiceConnector @Inject() (http: HttpClientV2, appConfig: ApplicationConfig, val apiMetrics: ApiMetrics)(implicit ec: ExecutionContext)
extends RecordMetrics {
import uk.gov.hmrc.apisubscriptionfields.connector.JsonFormatters._

Expand All @@ -42,7 +44,9 @@ class PushPullNotificationServiceConnector @Inject() (http: HttpClient, appConfi
val payload = CreateBoxRequest(boxName, clientId)

http
.PUT[CreateBoxRequest, CreateBoxResponse](s"$externalServiceUri/box", payload)
.put(url"$externalServiceUri/box")
.withBody(Json.toJson(payload))
.execute[CreateBoxResponse]
.map(_.boxId)
.recover { case NonFatal(e) =>
throw new RuntimeException(s"Unexpected response from $externalServiceUri: ${e.getMessage}")
Expand All @@ -53,7 +57,9 @@ class PushPullNotificationServiceConnector @Inject() (http: HttpClient, appConfi
val payload = UpdateSubscriberRequest(SubscriberRequest(callbackUrl, "API_PUSH_SUBSCRIBER"))

http
.PUT[UpdateSubscriberRequest, UpdateSubscriberResponse](s"$externalServiceUri/box/${boxId.value.toString}/subscriber", payload)
.put(url"$externalServiceUri/box/${boxId.value.toString}/subscriber")
.withBody(Json.toJson(payload))
.execute[UpdateSubscriberResponse]
.map(_ => ())
.recover { case NonFatal(e) =>
throw new RuntimeException(s"Unexpected response from $externalServiceUri: ${e.getMessage}")
Expand All @@ -63,7 +69,9 @@ class PushPullNotificationServiceConnector @Inject() (http: HttpClient, appConfi
def updateCallBackUrl(clientId: ClientId, boxId: BoxId, callbackUrl: FieldValue)(implicit hc: HeaderCarrier): Future[Either[String, Unit]] = {
val payload = UpdateCallBackUrlRequest(clientId, callbackUrl)
http
.PUT[UpdateCallBackUrlRequest, UpdateCallBackUrlResponse](s"$externalServiceUri/box/${boxId.value.toString}/callback", payload)
.put(url"$externalServiceUri/box/${boxId.value.toString}/callback")
.withBody(Json.toJson(payload))
.execute[UpdateCallBackUrlResponse]
.map(response =>
if (response.successful)
Right(())
Expand Down
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ lazy val acceptance = (project in file("acceptance"))
.settings(
name := "acceptance-tests",
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-eT"),
DefaultBuildSettings.itSettings(),
addTestReportOption(Test, "acceptance-reports")
DefaultBuildSettings.itSettings()
)

commands ++= Seq(
Expand Down
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ play.http.errorHandler = "uk.gov.hmrc.play.bootstrap.backend.http.JsonErrorHandl
# ~~~~
# Additional play modules can be added here
play.modules.enabled += "uk.gov.hmrc.mongo.play.PlayMongoModule"
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientModule"
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientV2Module"
play.modules.enabled += "uk.gov.hmrc.play.http.metrics.Module"


Expand Down
21 changes: 0 additions & 21 deletions conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,13 @@
</encoder>
</appender>

<appender name="STDOUT_IGNORE_NETTY" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date{ISO8601} level=[%level] logger=[%logger] thread=[%thread] rid=[not-available] user=[not-available] message=[%message] %replace(exception=[%xException]){'^exception=\[\]$',''}%n</pattern>
</encoder>
</appender>

<appender name="ACCESS_LOG_FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/access.log</file>
<encoder>
<pattern>%message%n</pattern>
</encoder>
</appender>

<appender name="CONNECTOR_LOG_FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/connector.log</file>
<encoder>
<pattern>%message%n</pattern>
</encoder>
</appender>

<logger name="accesslog" level="INFO" additivity="false">
<appender-ref ref="ACCESS_LOG_FILE" />
</logger>

<logger name="com.ning.http.client.providers.netty" additivity="false">
<appender-ref ref="STDOUT_IGNORE_NETTY" />
</logger>

<logger name="com.google.inject" level="INFO"/>

<logger name="uk.gov" level="INFO"/>
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.9
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefac
resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)
resolvers += Resolver.typesafeRepo("releases")

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0")
Expand Down

0 comments on commit bc34ba1

Please sign in to comment.