Skip to content

Commit

Permalink
DRTII-1706 Update CWL live feed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richbirch committed Dec 23, 2024
1 parent 4713e29 commit 0ce15aa
Show file tree
Hide file tree
Showing 7 changed files with 567 additions and 702 deletions.
2 changes: 1 addition & 1 deletion project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Settings {
/** Declare global dependency versions here to avoid mismatches in multi part dependencies */
//noinspection ScalaStyle
object versions {
val drtLib = "v993"
val drtLib = "v1009"

val scala = "2.13.12"
val scalaDom = "2.8.0"
Expand Down
9 changes: 9 additions & 0 deletions server/src/main/resources/config/feeds.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ feeds {
}
}

cwl {
iata {
endPointUrl = ""
endPointUrl = ${?CWL_IATA_ENDPOINT_URL}
username = ""
username = ${?CWL_IATA_USERNAME}
}
}

ltn {
live {
url = ${?LTN_LIVE_URL}
Expand Down
6 changes: 6 additions & 0 deletions server/src/main/scala/actors/ProdDrtParameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ trait DrtParameters {
val bhxIataUsername: String
val maybeBhxSoapEndPointUrl: Option[String]

val cwlIataEndPointUrl: String
val cwlIataUsername: String

val maybeLtnLiveFeedUrl: Option[String]
val maybeLtnLiveFeedUsername: Option[String]
val maybeLtnLiveFeedPassword: Option[String]
Expand Down Expand Up @@ -97,6 +100,9 @@ case class ProdDrtParameters @Inject()(config: Configuration) extends DrtParamet
override val bhxIataEndPointUrl: String = config.get[String]("feeds.bhx.iata.endPointUrl")
override val bhxIataUsername: String = config.get[String]("feeds.bhx.iata.username")

override val cwlIataEndPointUrl: String = config.get[String]("feeds.cwl.iata.endPointUrl")
override val cwlIataUsername: String = config.get[String]("feeds.cwl.iata.username")

override val maybeBhxSoapEndPointUrl: Option[String] = config.getOptional[String]("feeds.bhx.soap.endPointUrl")

override val maybeLtnLiveFeedUrl: Option[String] = config.getOptional[String]("feeds.ltn.live.url")
Expand Down
26 changes: 8 additions & 18 deletions server/src/main/scala/drt/server/feeds/cwl/CWLFeed.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package drt.server.feeds.cwl

import akka.actor.ActorSystem
import akka.http.scaladsl.{ConnectionContext, Http}
import akka.http.scaladsl.marshallers.xml.ScalaXmlSupport
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers._
import akka.http.scaladsl.unmarshalling.{FromResponseUnmarshaller, Unmarshal, Unmarshaller}
import akka.http.scaladsl.{ConnectionContext, Http}
import akka.stream.Materializer
import akka.stream.scaladsl.{Sink, Source}
import akka.stream.scaladsl.Source
import akka.util.ByteString
import drt.server.feeds.Feed.FeedTick
import drt.server.feeds.{ArrivalsFeedFailure, ArrivalsFeedResponse, ArrivalsFeedSuccess}
Expand All @@ -22,8 +22,7 @@ import java.security.SecureRandom
import javax.net.ssl.SSLContext
import scala.collection.immutable
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.DurationInt
import scala.concurrent.Future
import scala.util.Try
import scala.xml.{Node, NodeSeq}

Expand Down Expand Up @@ -115,16 +114,15 @@ trait CWLClientLike extends ScalaXmlSupport {
RawHeader("Accept-Encoding", "gzip,deflate"),
)

println(s"Making request to $soapEndPoint\nHeaders: $headers\nPost XML: $postXml")

makeRequest(soapEndPoint, headers, postXml)
.map { res =>
log.info(s"Got a response from CWL ${res.status}")
val response = Unmarshal[HttpResponse](res).to[CWLFlightsResponse]

response.map {
case s: CWLFlightsResponseSuccess =>
ArrivalsFeedSuccess(s.flights.map(fs => CWLFlight.portFlightToArrival(fs)))
val arrivals = s.flights.map(fs => CWLFlight.portFlightToArrival(fs))
ArrivalsFeedSuccess(arrivals)

case f: CWLFlightsResponseFailure =>
ArrivalsFeedFailure(f.message)
Expand Down Expand Up @@ -167,14 +165,8 @@ case class CWLClient(cwlLiveFeedUser: String, soapEndPoint: String) extends CWLC
val tls12Context = SSLContext.getInstance("TLSv1.2")
tls12Context.init(null, null, new SecureRandom())

Http().singleRequest(request, connectionContext = ConnectionContext.httpsClient(tls12Context))
// .map { r =>
// val x = r.entity.getDataBytes().map(_.utf8String).asScala.runWith(Sink.fold("")(_ + _)).map { body =>
// println(s"Got response from CWL: ${r.status} $body")
// }
// Await.result(x, 30.seconds)
// r
// }
Http()
.singleRequest(request, connectionContext = ConnectionContext.httpsClient(tls12Context))
.recoverWith {
case f =>
log.error(s"Failed to get CWL Live Feed: ${f.getMessage}")
Expand Down Expand Up @@ -221,8 +213,6 @@ object CWLFlight extends NodeSeqUnmarshaller {

val flightNodeSeq = xml \ "Body" \ "IATA_AIDX_FlightLegRS" \ "FlightLeg"

println(s"Got ${flightNodeSeq.length} flights in CWL XML")

val flights = flightNodeSeq
.filter { n =>
(n \ "LegData" \ "AirportResources" \ "Resource").exists { p =>
Expand Down Expand Up @@ -322,7 +312,7 @@ object CWLFlight extends NodeSeqUnmarshaller {
maxPax = f.seatCapacity,
totalPax = f.paxCount,
transPax = None,
terminal = Terminal(s"T${f.aircraftTerminal}"),
terminal = Terminal(f.aircraftTerminal),
voyageNumber = voyageNumber.numeric,
carrierCode = carrierCode.code,
flightCodeSuffix = suffix.map(_.suffix),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import drt.server.feeds.bhx.{BHXClient, BHXFeed}
import drt.server.feeds.chroma.ChromaLiveFeed
import drt.server.feeds.cirium.CiriumFeed
import drt.server.feeds.common.{ManualUploadArrivalFeed, ProdHttpClient}
import drt.server.feeds.cwl.{CWLClient, CWLFeed}
import drt.server.feeds.edi.EdiFeed
import drt.server.feeds.gla.GlaFeed
import drt.server.feeds.lcy.{LCYClient, LCYFeed}
Expand Down Expand Up @@ -429,6 +430,8 @@ case class ProdFeedService(journalType: StreamingJournalLike,
Feed(LGWFeed(azureClient)(system).source(Feed.actorRefSource), 5.seconds, 100.milliseconds)
case "BHX" if params.bhxIataEndPointUrl.nonEmpty =>
Feed(BHXFeed(BHXClient(params.bhxIataUsername, params.bhxIataEndPointUrl), Feed.actorRefSource), 5.seconds, 80.seconds)
case "CWL" if params.cwlIataEndPointUrl.nonEmpty =>
Feed(CWLFeed(CWLClient(params.cwlIataUsername, params.cwlIataEndPointUrl), Feed.actorRefSource), 5.seconds, 80.seconds)
case "LCY" if params.lcyLiveEndPointUrl.nonEmpty =>
Feed(LCYFeed(LCYClient(ProdHttpClient(), params.lcyLiveUsername, params.lcyLiveEndPointUrl, params.lcyLiveUsername, params.lcyLivePassword), Feed.actorRefSource), 5.seconds, 80.seconds)
case "LTN" =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ case class MockDrtParameters @Inject()() extends DrtParameters {
override val isSuperUserMode: Boolean = false
override val bhxIataEndPointUrl: String = ""
override val bhxIataUsername: String = ""
override val cwlIataEndPointUrl: String = ""
override val cwlIataUsername: String = ""
override val maybeBhxSoapEndPointUrl: Option[String] = None
override val maybeLtnLiveFeedUrl: Option[String] = None
override val maybeLtnLiveFeedUsername: Option[String] = None
Expand Down
Loading

0 comments on commit 0ce15aa

Please sign in to comment.