play.api.libs.ws.ahc.AhcWSComponents Scala Examples

The following examples show how to use play.api.libs.ws.ahc.AhcWSComponents. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: MyApplicationLoader.scala    From get-you-a-license   with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
import controllers.{AssetsComponents, Main}
import filters.OnlyHttpsFilter
import org.webjars.play.{RequireJS, WebJarAssets, WebJarsUtil}
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
import play.api.ApplicationLoader.Context
import play.api.libs.concurrent.{DefaultFutures, Futures}
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.filters.HttpFiltersComponents
import play.filters.csrf.CSRFFilter
import router.Routes
import utils.GitHub

class MyApplicationLoader extends ApplicationLoader {
  def load(context: Context): Application = {
    new MyComponents(context).application
  }
}

class MyComponents(context: Context) extends BuiltInComponentsFromContext(context) with AhcWSComponents with AssetsComponents with HttpFiltersComponents {

  override def httpFilters: Seq[EssentialFilter] = {
    super.httpFilters.filterNot(_.isInstanceOf[CSRFFilter]) :+ new OnlyHttpsFilter(environment)
  }

  lazy val futures = new DefaultFutures(actorSystem)

  lazy val webJarsUtil = new WebJarsUtil(context.initialConfiguration, context.environment)

  lazy val indexView = new views.html.index(webJarsUtil)
  lazy val setupView = new views.html.setup(webJarsUtil)
  lazy val orgView = new views.html.org(webJarsUtil)

  lazy val gitHub = new GitHub(context.initialConfiguration, wsClient, futures)
  lazy val main = new Main(gitHub, controllerComponents)(indexView, orgView, setupView)

  lazy val requireJs = new RequireJS(webJarsUtil)
  lazy val webJarAssets = new WebJarAssets(httpErrorHandler, assetsMetadata)
  lazy val webJarsRoutes = new webjars.Routes(httpErrorHandler, requireJs, webJarAssets)

  lazy val router: Router = new Routes(httpErrorHandler, main, assets, webJarsRoutes)
} 
Example 2
Source File: PublishServiceSpec.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package docs.scaladsl.mb

import com.lightbend.lagom.scaladsl.api.broker.Topic
import com.lightbend.lagom.scaladsl.server.LagomApplication
import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
import com.lightbend.lagom.scaladsl.server.LagomServer
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import com.lightbend.lagom.scaladsl.testkit.TestTopicComponents
import play.api.libs.ws.ahc.AhcWSComponents
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
import akka.NotUsed
import akka.Done
import akka.stream.scaladsl.Source
import akka.stream.testkit.scaladsl.TestSink
import akka.stream.testkit.TestSubscriber
import akka.stream.testkit.TestSubscriber.Probe

abstract class PublishApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with AhcWSComponents {
  override lazy val lagomServer = serverFor[service.PublishService](new service.PublishServiceImpl())
}

package service {
  import com.lightbend.lagom.scaladsl.api.Service
  import com.lightbend.lagom.scaladsl.broker.TopicProducer

  object PublishService {
    val TOPIC_NAME = "events"
  }

  trait PublishService extends Service {
    final override def descriptor = {
      import Service._
      named("brokerdocs")
        .withTopics(topic(PublishService.TOPIC_NAME, events))
        .withAutoAcl(true)
    }

    def events(): Topic[PubMessage]
  }

  case class PubMessage(message: String)

  object PubMessage {
    import play.api.libs.json.Format
    import play.api.libs.json.Json
    implicit val format: Format[PubMessage] = Json.format[PubMessage]
  }

  class PublishServiceImpl() extends PublishService {
    override def events(): Topic[PubMessage] =
      TopicProducer.singleStreamWithOffset { offset =>
        Source((1 to 10)).map(i => (PubMessage(s"msg $i"), offset))
      }
  }
}

class PublishServiceSpec extends AsyncWordSpec with Matchers {
  import service._

  //#topic-test-publishing-into-a-topic
  "The PublishService" should {
    "publish events on the topic" in ServiceTest.withServer(ServiceTest.defaultSetup) { ctx =>
      new PublishApplication(ctx) with LocalServiceLocator with TestTopicComponents
    } { server =>
      implicit val system = server.actorSystem
      implicit val mat    = server.materializer

      val client: PublishService = server.serviceClient.implement[PublishService]
      val source                 = client.events().subscribe.atMostOnceSource
      source
        .runWith(TestSink.probe[PubMessage])
        .request(1)
        .expectNext should ===(PubMessage("msg 1"))
    }
  }
  //#topic-test-publishing-into-a-topic
} 
Example 3
Source File: JdbcBlogApplicationLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package docs.home.scaladsl.persistence

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.jdbc.JdbcPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents

class JdbcBlogApplicationLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new BlogApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BlogApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[BlogService])
}

//#load-components
abstract class BlogApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with JdbcPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {
//#load-components

  // Bind the services that this server provides
  override lazy val lagomServer = ???

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = BlogPostSerializerRegistry

  // Register the Blog application persistent entity
  persistentEntityRegistry.register(wire[Post])
} 
Example 4
Source File: SlickBlogApplicationLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package docs.home.scaladsl.persistence

import com.lightbend.lagom.scaladsl.server.LagomApplication
import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
import com.lightbend.lagom.scaladsl.server.LagomServer
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.db.HikariCPComponents
import com.softwaremill.macwire._
import com.lightbend.lagom.scaladsl.persistence.jdbc._
import com.lightbend.lagom.scaladsl.persistence.slick._

//#load-components
abstract class SlickBlogApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with JdbcPersistenceComponents
    with SlickPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {
//#load-components

  // Bind the services that this server provides
  override lazy val lagomServer = ???

  lazy val myDatabase: MyDatabase = MyDatabase

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = BlogPostSerializerRegistry

  // Register the Blog application persistent entity
  persistentEntityRegistry.register(wire[Post])

  // Register the event processor
  //#register-event-processor
  readSide.register(wire[BlogEventProcessor])
  //#register-event-processor
} 
Example 5
Source File: ServiceLoaders.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.lightbend.lagom.api.tools.tests.scaladsl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server.LagomApplication
import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
import com.lightbend.lagom.scaladsl.server.LagomApplicationLoader
import play.api.libs.ws.ahc.AhcWSComponents

class AclServiceLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new AclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new AclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def describeService = Some(readDescriptor[AclService])
}

abstract class AclServiceApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with AhcWSComponents {
  override lazy val lagomServer = serverFor[AclService](new AclServiceImpl)
}

// ---------------------------------------

class NoAclServiceLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new NoAclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new NoAclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def describeService = Some(readDescriptor[NoAclService])
}

abstract class NoAclServiceApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with AhcWSComponents {
  override lazy val lagomServer = serverFor[NoAclService](new NoAclServiceImpl)
}
// ---------------------------------------
class UndescribedServiceLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new NoAclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new NoAclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }
  override def describeService = None
}

// Just like AclServiceLoader but overriding the deprecated describeServices method instead of describeService
class LegacyUndescribedServiceLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new NoAclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new NoAclServiceApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }
}

abstract class UndescribedServiceApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with AhcWSComponents {
  override lazy val lagomServer = serverFor[UndescribedService](new UndescribedServiceImpl)
}
// --------------------------------------- 
Example 6
Source File: AkkaDiscoveryServiceLocatorSpec.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.lightbend.lagom.scaladsl.akka.discovery

import akka.NotUsed
import com.lightbend.lagom.scaladsl.api.Service
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.server.LagomApplication
import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
import com.lightbend.lagom.scaladsl.server.LagomServer
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest._
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSComponents

import scala.concurrent.Future
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec

class AkkaDiscoveryServiceLocatorSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll with OptionValues {
  "ServiceLocator" should {
    "retrieve registered services" in {
      val serviceLocator = server.application.serviceLocator

      serviceLocator.locate("fake-service").map { res =>
        res.value.toString shouldBe "http://fake-service-host:9119"
      }
    }
  }

  private val server = ServiceTest.startServer(ServiceTest.defaultSetup) { ctx =>
    new LagomTestApplication(ctx)
  }

  protected override def afterAll() = server.stop()

  class LagomTestApplication(ctx: LagomApplicationContext)
      extends LagomApplication(ctx)
      with AhcWSComponents
      with AkkaDiscoveryComponents {
    override def lagomServer: LagomServer = serverFor[TestService](new TestServiceImpl)
  }

  trait TestService extends Service {
    def hello(name: String): ServiceCall[NotUsed, String]

    override def descriptor = {
      import Service._
      named("test-service")
        .withCalls(
          pathCall("/hello/:name", hello _)
        )
        .withAutoAcl(true)
    }
  }

  class TestServiceImpl extends TestService {
    override def hello(name: String) = ServiceCall { _ =>
      Future.successful(s"Hello $name")
    }
  }
} 
Example 7
Source File: AdditionalRoutersSpec.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.lightbend.lagom.scaladsl.it.routers

import akka.NotUsed
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.server.LagomApplication
import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
import com.lightbend.lagom.scaladsl.server.LagomServer
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import com.lightbend.lagom.scaladsl.testkit.ServiceTest.TestServer
import org.scalatest.concurrent.ScalaFutures
import play.api.http.DefaultWriteables
import play.api.http.HeaderNames
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc
import play.api.mvc._
import play.api.routing.SimpleRouterImpl
import play.api.test.FakeHeaders
import play.api.test.FakeRequest
import play.api.test.Helpers
import play.core.j.JavaRouterAdapter
import play.api.test.Helpers._

import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class AdditionalRoutersSpec extends AnyWordSpec with Matchers with ScalaFutures {
  "A LagomServer " should {
    "be extensible with a Play Router" in withServer { server =>
      val request = FakeRequest(GET, "/hello/")
      val result  = Helpers.route(server.application.application, request).get.futureValue

      result.header.status shouldBe OK
      val body = result.body.consumeData(server.materializer).futureValue.utf8String
      body shouldBe "hello"
    }
  }

  def withServer(block: TestServer[TestApp] => Unit): Unit = {
    ServiceTest.withServer(ServiceTest.defaultSetup.withCassandra(false).withCluster(false)) { ctx =>
      new TestApp(ctx)
    } { server =>
      block(server)
    }
  }

  class TestApp(context: LagomApplicationContext)
      extends LagomApplication(context)
      with AhcWSComponents
      with LocalServiceLocator {
    override def lagomServer: LagomServer =
      serverFor[AdditionalRoutersService](new AdditionalRoutersServiceImpl)
        .additionalRouter(FixedResponseRouter("hello").withPrefix("/hello"))
  }
}


object FixedResponseRouter {
  def apply(msg: String) =
    new SimpleRouterImpl({
      case _ =>
        new Action[Unit] {
          override def parser: BodyParser[Unit] = mvc.BodyParsers.utils.empty

          override def apply(request: Request[Unit]): Future[Result] =
            Future.successful(Results.Ok(msg))

          override def executionContext: ExecutionContext =
            scala.concurrent.ExecutionContext.global
        }
    })
} 
Example 8
Source File: ServiceTestSpec.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.lightbend.lagom.scaladsl.testkit

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

import com.lightbend.lagom.scaladsl.api.Descriptor
import com.lightbend.lagom.scaladsl.api.Service
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.persistence.jdbc.JdbcPersistenceComponents
import com.lightbend.lagom.scaladsl.persistence.PersistenceComponents
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server._
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.JavaConverters._
import scala.util.Properties
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class ServiceTestSpec extends AnyWordSpec with Matchers {
  "ServiceTest" when {
    "started with Cassandra" should {
      "create a temporary directory" in {
        val temporaryFileCountBeforeRun = listTemporaryFiles().size

        ServiceTest.withServer(ServiceTest.defaultSetup.withCassandra())(new CassandraTestApplication(_)) { _ =>
          val temporaryFilesDuringRun = listTemporaryFiles()

          temporaryFilesDuringRun should have size (temporaryFileCountBeforeRun + 1)
        }
      }
    }

    "stopped after starting" should {
      "remove its temporary directory" in {
        val temporaryFileCountBeforeRun = listTemporaryFiles().size

        ServiceTest.withServer(ServiceTest.defaultSetup.withCassandra())(new CassandraTestApplication(_)) { _ =>
          ()
        }

        val temporaryFilesAfterRun = listTemporaryFiles()

        temporaryFilesAfterRun should have size temporaryFileCountBeforeRun
      }
    }

    "started with JDBC" should {
      "start successfully" in {
        ServiceTest.withServer(ServiceTest.defaultSetup.withJdbc())(new JdbcTestApplication(_)) { _ =>
          ()
        }
      }
    }
  }

  def listTemporaryFiles(): Iterator[Path] = {
    val tmpDir = Paths.get(Properties.tmpDir)
    Files
      .newDirectoryStream(tmpDir, "ServiceTest_*")
      .iterator()
      .asScala
  }
}

trait TestService extends Service {
  import Service._

  final override def descriptor: Descriptor = named("test")
}

class TestServiceImpl(persistentEntityRegistry: PersistentEntityRegistry) extends TestService

class TestApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with LocalServiceLocator
    with AhcWSComponents { self: PersistenceComponents =>

  override lazy val jsonSerializerRegistry: JsonSerializerRegistry = EmptyJsonSerializerRegistry

  override lazy val lagomServer: LagomServer = serverFor[TestService](new TestServiceImpl(persistentEntityRegistry))
}

class CassandraTestApplication(context: LagomApplicationContext)
    extends TestApplication(context)
    with CassandraPersistenceComponents

class JdbcTestApplication(context: LagomApplicationContext)
    extends TestApplication(context)
    with JdbcPersistenceComponents
    with HikariCPComponents 
Example 9
Source File: TopicPublishingSpec.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.lightbend.lagom.scaladsl.testkit

import akka.persistence.query.Offset
import akka.stream.scaladsl.Source
import akka.stream.testkit.scaladsl.TestSink
import com.lightbend.lagom.scaladsl.api.broker.Topic
import com.lightbend.lagom.scaladsl.broker.TopicProducer
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.LagomApplication
import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
import com.lightbend.lagom.scaladsl.server.LagomServer
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.services.AlphaEvent
import com.lightbend.lagom.scaladsl.testkit.services.AlphaService
import play.api.libs.ws.ahc.AhcWSComponents
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec

abstract class AlphaApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with CassandraPersistenceComponents
    with TestTopicComponents
    with AhcWSComponents {
  override lazy val lagomServer = serverFor[AlphaService](new AlphaServiceImpl())

  override lazy val jsonSerializerRegistry = EmptyJsonSerializerRegistry
}

class AlphaServiceImpl extends AlphaService {
  override def messages: Topic[AlphaEvent] =
    TopicProducer.singleStreamWithOffset { offset =>
      val events = (1 to 10).filter(_ % 2 == 0).map(AlphaEvent.apply)
      Source(events).map(event => (event, Offset.sequence(event.message / 2)))
    }
}

class TopicPublishingSpec extends AsyncWordSpec with Matchers {
  "The AlphaService" should {
    "publish events on alpha topic" in ServiceTest.withServer(ServiceTest.defaultSetup.withCluster()) { ctx =>
      new AlphaApplication(ctx) with LocalServiceLocator
    } { server =>
      implicit val system = server.actorSystem
      implicit val mat    = server.materializer

      val client: AlphaService = server.serviceClient.implement[AlphaService]
      val source               = client.messages.subscribe.atMostOnceSource

      source
        .runWith(TestSink.probe[AlphaEvent])
        .request(1)
        .expectNext should ===(AlphaEvent(2))
    }
  }
} 
Example 10
Source File: MyCompileTimeSpecs.scala    From slim-play   with MIT License 5 votes vote down vote up
import helpers.{
  OneAppPerSuiteWithComponents,
  OneAppPerTestWithComponents,
  OneServerPerSuiteWithComponents,
  OneServerPerTestWithComponents
}
import org.scalatest.TestSuite
import play.api.ApplicationLoader.Context
import play.api.libs.ws.ahc.AhcWSComponents

class AppWithTestComponents(context: Context) extends AppComponents(context) with AhcWSComponents

trait OneAppPerTestWithMyComponents extends OneAppPerTestWithComponents[AppWithTestComponents] {
  this: TestSuite =>

  override def createComponents(context: Context) = new AppWithTestComponents(context)
}

trait OneAppPerSuiteWithMyComponents extends OneAppPerSuiteWithComponents[AppWithTestComponents] {
  this: TestSuite =>

  override def createComponents(context: Context) = new AppWithTestComponents(context)
}

trait OneServerPerTestWithMyComponents
    extends OneServerPerTestWithComponents[AppWithTestComponents] { this: TestSuite =>

  override def createComponents(context: Context) = new AppWithTestComponents(context)
}

trait OneServerPerSuiteWithMyComponents
    extends OneServerPerSuiteWithComponents[AppWithTestComponents] { this: TestSuite =>

  override def createComponents(context: Context) = new AppWithTestComponents(context)
} 
Example 11
package config

import java.util.UUID

import _root_.controllers.AssetsComponents
import articles.ArticleComponents
import authentication.AuthenticationComponents
import users.UserComponents
import play.api.ApplicationLoader.Context
import play.api._
import play.api.cache.AsyncCacheApi
import play.api.cache.ehcache.EhCacheComponents
import play.api.db.evolutions.{DynamicEvolutions, EvolutionsComponents}
import play.api.db.slick._
import play.api.db.slick.evolutions.SlickEvolutionsComponents
import play.api.i18n._
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc._
import play.api.routing.Router
import play.filters.cors.{CORSConfig, CORSFilter}
import slick.basic.{BasicProfile, DatabaseConfig}

class RealWorldApplicationLoader extends ApplicationLoader {
  def load(context: Context): Application = new RealWorldComponents(context).application
}

class RealWorldComponents(context: Context) extends BuiltInComponentsFromContext(context)
  with SlickComponents
  with SlickEvolutionsComponents
  with AssetsComponents
  with I18nComponents
  with EvolutionsComponents
  with AhcWSComponents
  with AuthenticationComponents
  with  UserComponents
  with ArticleComponents
  with EhCacheComponents {

  override lazy val slickApi: SlickApi =
    new DefaultSlickApi(environment, configuration, applicationLifecycle)(executionContext)

  override lazy val databaseConfigProvider: DatabaseConfigProvider = new DatabaseConfigProvider {
    def get[P <: BasicProfile]: DatabaseConfig[P] = slickApi.dbConfig[P](DbName("default"))
  }

  override lazy val dynamicEvolutions: DynamicEvolutions = new DynamicEvolutions

  def onStart(): Unit = {
    // applicationEvolutions is a val and requires evaluation
    applicationEvolutions
  }

  onStart()

  // set up logger
  LoggerConfigurator(context.environment.classLoader).foreach {
    _.configure(context.environment, context.initialConfiguration, Map.empty)
  }

  protected lazy val routes: PartialFunction[RequestHeader, Handler] = userRoutes.orElse(articleRoutes)

  override lazy val router: Router = Router.from(routes)

  override lazy val defaultCacheApi: AsyncCacheApi = cacheApi(UUID.randomUUID().toString)

  private lazy val corsFilter: CORSFilter = {
    val corsConfig = CORSConfig.fromConfiguration(configuration)

    CORSFilter(corsConfig)
  }

  override def httpFilters: Seq[EssentialFilter] = List(corsFilter)
} 
Example 12
Source File: LeagueLoader.scala    From eventsourcing-intro   with Apache License 2.0 5 votes vote down vote up
package eu.reactivesystems.league.impl

import akka.actor.PoisonPill
import akka.cluster.singleton.{
  ClusterSingletonManager,
  ClusterSingletonManagerSettings
}
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.WriteSideCassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.persistence.jdbc.ReadSideJdbcPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{
  JsonSerializer,
  JsonSerializerRegistry
}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import com.softwaremill.macwire.akkasupport._
import eu.reactivesystems.league.api.LeagueService
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

class LeagueLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LeagueApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(
      context: LagomApplicationContext): LagomApplication =
    new LeagueApplication(context) with LagomDevModeComponents

  override def describeServices = List(
    readDescriptor[LeagueService]
  )
}

abstract class LeagueApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with WriteSideCassandraPersistenceComponents
    with ReadSideJdbcPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer =
    serverFor[LeagueService](wire[LeagueServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = LeagueSerializerRegistry

  // Register the league persistent entity
  persistentEntityRegistry.register(wire[LeagueEntity])

  // Register read side processor

  val leagueProjectionProps = wireProps[LeagueProjection]

  actorSystem.actorOf(
    ClusterSingletonManager.props(
      singletonProps = leagueProjectionProps,
      terminationMessage = PoisonPill,
      settings = ClusterSingletonManagerSettings(actorSystem)),
    name = "leagueProjection"
  )

}


object LeagueSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[AddClub],
    JsonSerializer[AddGame],
    JsonSerializer[ChangeGame],
    JsonSerializer[ClubRegistered],
    JsonSerializer[GamePlayed],
    JsonSerializer[ResultRevoked],
    JsonSerializer[LeagueState]
  )
} 
Example 13
Source File: WolframServiceLoader.scala    From lagom-on-kube   with Apache License 2.0 5 votes vote down vote up
package me.alexray.wolfram.impl

import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.server._
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._
import me.alexray.lagom.kube.client.LagomKubeModeComponents
import me.alexray.wolfram.api.WolframService

class WolframServiceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WolframServiceApplication(context) with LagomKubeModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WolframServiceApplication(context) with LagomKubeModeComponents

  override def describeServices = List(
    readDescriptor[WolframService]
  )
}

abstract class WolframServiceApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents
{
  implicit val system = ActorSystem("WolframServiceApplication")

  // Bind the service that this server provides
  override lazy val lagomServer: LagomServer = serverFor[WolframService](wire[WolframServiceImpl])
} 
Example 14
Source File: TelegramBotServiceLoader.scala    From lagom-on-kube   with Apache License 2.0 5 votes vote down vote up
package me.alexray.telegramBot.impl

import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import me.alexray.telegramBot.api.TelegramBotService
import com.softwaremill.macwire._
import me.alexray.lagom.kube.client.LagomKubeModeComponents
import me.alexray.wolfram.api.WolframService

class TelegramBotServiceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new TelegramBotServiceApplication(context) with LagomKubeModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new TelegramBotServiceApplication(context) with LagomKubeModeComponents

  override def describeServices = List(
    readDescriptor[TelegramBotService]
  )
}

abstract class TelegramBotServiceApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents
{
  // Bind the service that this server provides
  override lazy val lagomServer: LagomServer = serverFor[TelegramBotService](wire[TelegramBotServiceImpl])

  // Bind the TwbService client
  lazy val wolframService: WolframService = serviceClient.implement[WolframService]
} 
Example 15
Source File: HelloWorldServiceLoader.scala    From lagom-on-kube   with Apache License 2.0 5 votes vote down vote up
package me.alexray.helloWorldService.impl

import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire.wire
import me.alexray.lagom.kube.client.LagomKubeModeComponents
import me.alexray.helloWorldService.api.HelloWorldService
import play.api.libs.ws.ahc.AhcWSComponents

class HelloWorldServiceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloWorldServiceApplication(context) with LagomKubeModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloWorldServiceApplication(context) with LagomKubeModeComponents

  override def describeServices = List(
    readDescriptor[HelloWorldService]
  )
}

abstract class HelloWorldServiceApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents
{
  // Bind the service that this server provides
  override lazy val lagomServer: LagomServer = serverFor[HelloWorldService](wire[HelloWorldServiceImpl])

} 
Example 16
Source File: ServiceClients.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package docs.scaladsl.services

package implementhelloclient {
  import helloservice.HelloService

  import com.lightbend.lagom.scaladsl.server.LagomApplication
  import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
  import play.api.libs.ws.ahc.AhcWSComponents

  //#implement-hello-client
  abstract class MyApplication(context: LagomApplicationContext)
      extends LagomApplication(context)
      with AhcWSComponents {
    lazy val helloService = serviceClient.implement[HelloService]
  }
  //#implement-hello-client
}

package helloconsumer {
  import akka.NotUsed
  import com.lightbend.lagom.scaladsl.api.Service
  import com.lightbend.lagom.scaladsl.api.ServiceCall
  import helloservice.HelloService

  import scala.concurrent.ExecutionContext
  import scala.concurrent.Future

  trait MyService extends Service {
    def sayHelloLagom: ServiceCall[NotUsed, String]

    override def descriptor = {
      import Service._

      named("myservice").withCalls(call(sayHelloLagom))
    }
  }

  //#hello-consumer
  class MyServiceImpl(helloService: HelloService)(implicit ec: ExecutionContext) extends MyService {
    override def sayHelloLagom = ServiceCall { _ =>
      val result: Future[String] =
        helloService.sayHello.invoke("Lagom")

      result.map { response =>
        s"Hello service said: $response"
      }
    }
  }
  //#hello-consumer
}

package circuitbreakers {
  import com.lightbend.lagom.scaladsl.api.Descriptor
  import com.lightbend.lagom.scaladsl.api.Service
  import com.lightbend.lagom.scaladsl.api.ServiceCall

  trait HelloServiceWithCircuitBreaker extends Service {
    def sayHi: ServiceCall[String, String]

    def hiAgain: ServiceCall[String, String]

    // @formatter:off
    //#circuit-breaker
    import com.lightbend.lagom.scaladsl.api.CircuitBreaker

    def descriptor: Descriptor = {
      import Service._

      named("hello").withCalls(
        namedCall("hi", this.sayHi),
        namedCall("hiAgain", this.hiAgain)
          .withCircuitBreaker(CircuitBreaker.identifiedBy("hello2"))
      )
    }
    //#circuit-breaker
    // @formatter:on
  }
} 
Example 17
Source File: WFLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService

class WFLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFApplication(context) with LagomDevModeComponents
}

abstract class WFApplication(context: LagomApplicationContext) extends WFComponents(context)
  with LagomKafkaComponents {

}

abstract class WFComponents(context: LagomApplicationContext) extends LagomApplication(context)
  with CassandraPersistenceComponents
  with AhcWSComponents {

  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFService].to(wire[WFServiceImpl])
  )

  override lazy val jsonSerializerRegistry = WFSerializerRegistry

  persistentEntityRegistry.register(wire[WFEntity])
} 
Example 18
Source File: WebGatewayLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
import javax.inject.Inject
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.softwaremill.macwire._
import controllers.{Assets, WFConsumerController, WFController}
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api._
import play.api.Play.current
import play.api.i18n.Messages.Implicits._
import router.Routes

import scala.collection.immutable
import scala.concurrent.ExecutionContext

abstract class WebGateway @Inject()(context: Context) extends BuiltInComponentsFromContext(context)
  with I18nComponents
  with AhcWSComponents
  with LagomServiceClientComponents{

  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "wf-frontend",
    Map(
      "wf-frontend" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val wfService = serviceClient.implement[WFService]
  lazy val wfConsumerService = serviceClient.implement[WFConsumerService]
  lazy val wfController = wire[WFController]
  lazy val wfConsumerController = wire[WFConsumerController]
  lazy val assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context): Application = context.environment.mode match {
    case Mode.Dev =>
      new WebGateway(context) with LagomDevModeComponents {}.application
    case _ =>
      new WebGateway(context) {
        override def serviceLocator = NoServiceLocator
      }.application
  }
} 
Example 19
Source File: WFConsumerLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.consumer.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.packt.publishing.wf.consumer.impl.repositories.WFRepository

class WFConsumerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) with LagomDevModeComponents
}

abstract class WFConsumerApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFConsumerService].to(wire[WFConsumerServiceImpl])
  )

  //Bind the WFService client
  lazy val wfService = serviceClient.implement[WFService]

  lazy val messageRepository = wire[WFRepository]

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = WFConsumerSerializerRegistry

  // Register the Message persistent entity
   persistentEntityRegistry.register(wire[WFEntity])

  readSide.register(wire[WFEventProcessor])
} 
Example 20
Source File: LagomscalahelloserviceLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.lagomscalahelloservice.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceService])
}

abstract class LagomscalahelloserviceApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceService](wire[LagomscalahelloserviceServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = LagomscalahelloserviceSerializerRegistry

  // Register the lagom-scala-hello-service persistent entity
  persistentEntityRegistry.register(wire[LagomscalahelloserviceEntity])
} 
Example 21
package com.packt.publishing.lagomscalahelloservicestream.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservicestream.api.LagomscalahelloserviceStreamService
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceStreamLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceStreamService])
}

abstract class LagomscalahelloserviceStreamApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceStreamService](wire[LagomscalahelloserviceStreamServiceImpl])

  // Bind the LagomscalahelloserviceService client
  lazy val lagomscalahelloserviceService = serviceClient.implement[LagomscalahelloserviceService]
} 
Example 22
Source File: WFProducerLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class WFProducerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFProducerApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFProducerApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[WFService])
}

abstract class WFProducerApplication(context: LagomApplicationContext) extends WFComponents(context)
  with LagomKafkaComponents {

}

abstract class WFComponents(context: LagomApplicationContext) extends LagomApplication(context)
  with CassandraPersistenceComponents
  with AhcWSComponents {

  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFService].to(wire[WFServiceImpl])
  )

  override lazy val jsonSerializerRegistry = WFSerializerRegistry

  persistentEntityRegistry.register(wire[WFEntity])
} 
Example 23
Source File: WebGatewayLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
import javax.inject.Inject
import com.lightbend.lagom.internal.client.CircuitBreakerMetricsProviderImpl
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.softwaremill.macwire._
import controllers.{Assets, WFConsumerController, WFController}
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api._
import play.api.Play.current
import play.api.i18n.Messages.Implicits._
import router.Routes
import scala.collection.immutable
import scala.concurrent.ExecutionContext
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

abstract class WebGateway @Inject()(context: Context) extends BuiltInComponentsFromContext(context)
  with I18nComponents
  with AhcWSComponents
  with LagomServiceClientComponents {

  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "wf-frontend",
    Map(
      "wf-frontend" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val wfService = serviceClient.implement[WFService]
  lazy val wfConsumerService = serviceClient.implement[WFConsumerService]
  lazy val wfController = wire[WFController]
  lazy val wfConsumerController = wire[WFConsumerController]
  lazy val assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context): Application = context.environment.mode match {
    case Mode.Dev =>
      new WebGateway(context) with LagomDevModeComponents {}.application
    case _ =>
      (new WebGateway(context) with ConductRApplicationComponents {
        override lazy val circuitBreakerMetricsProvider = new CircuitBreakerMetricsProviderImpl(actorSystem)
      }).application
  }
} 
Example 24
Source File: WFConsumerLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.wf.consumer.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.wf.api.WFService
import com.packt.publishing.wf.consumer.api.WFConsumerService
import com.packt.publishing.wf.consumer.impl.repositories.WFRepository
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class WFConsumerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new WFConsumerApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[WFConsumerService])
}

abstract class WFConsumerApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  override lazy val lagomServer = LagomServer.forServices(
    bindService[WFConsumerService].to(wire[WFConsumerServiceImpl])
  )

  lazy val wfService = serviceClient.implement[WFService]

  lazy val messageRepository = wire[WFRepository]

  override lazy val jsonSerializerRegistry = WFConsumerSerializerRegistry

  persistentEntityRegistry.register(wire[WFEntity])
  readSide.register(wire[WFEventProcessor])
} 
Example 25
Source File: LagomscalahelloserviceLoader.scala    From Scala-Reactive-Programming   with MIT License 5 votes vote down vote up
package com.packt.publishing.lagomscalahelloservice.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceService])
}

abstract class LagomscalahelloserviceApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with LagomKafkaComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceService](wire[LagomscalahelloserviceServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = LagomscalahelloserviceSerializerRegistry

  // Register the lagom-scala-hello-service persistent entity
  persistentEntityRegistry.register(wire[LagomscalahelloserviceEntity])
} 
Example 26
package com.packt.publishing.lagomscalahelloservicestream.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.publishing.lagomscalahelloservicestream.api.LagomscalahelloserviceStreamService
import com.packt.publishing.lagomscalahelloservice.api.LagomscalahelloserviceService
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents

class LagomscalahelloserviceStreamLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with ConductRApplicationComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new LagomscalahelloserviceStreamApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[LagomscalahelloserviceStreamService])
}

abstract class LagomscalahelloserviceStreamApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LagomscalahelloserviceStreamService](wire[LagomscalahelloserviceStreamServiceImpl])

  // Bind the LagomscalahelloserviceService client
  lazy val lagomscalahelloserviceService = serviceClient.implement[LagomscalahelloserviceService]
} 
Example 27
Source File: package.scala    From quill   with Apache License 2.0 5 votes vote down vote up
package io.getquill.context.cassandra

import akka.stream.Materializer
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.{ CassandraPersistenceComponents, CassandraSession }
import com.lightbend.lagom.scaladsl.playjson.{ EmptyJsonSerializerRegistry, JsonSerializerRegistry }
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomServer }
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import play.api.libs.ws.ahc.AhcWSComponents

import scala.concurrent.ExecutionContext

package object utils {

  val server = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(false)) { ctx =>
    new LagomApplication(ctx) with AhcWSComponents with CassandraPersistenceComponents with ConfigurationServiceLocatorComponents {

      override def lagomServer: LagomServer = serverFor[DummyService](new DummyService)

      override def jsonSerializerRegistry: JsonSerializerRegistry = EmptyJsonSerializerRegistry
    }
  }

  val cassandraSession: CassandraSession = server.application.cassandraSession
  implicit val executionContext: ExecutionContext = server.application.executionContext
  implicit val materializer: Materializer = server.application.materializer
} 
Example 28
Source File: ServerSpec.scala    From metronome   with Apache License 2.0 5 votes vote down vote up
package dcos.metronome
package api

import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Millis, Second, Span}
import org.scalatestplus.play._
import play.api.ApplicationLoader.Context
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc.Results
import play.api.test.Helpers._

class ServerSpec
    extends PlaySpec
    with OneServerPerSuiteWithComponents[MockApiComponents with AhcWSComponents]
    with Results
    with ScalaFutures {

  override implicit def patienceConfig: PatienceConfig = PatienceConfig(Span(1, Second), Span(50, Millis))
  override def createComponents(context: Context) = new MockApiComponents(context) with AhcWSComponents

  "Server query" should {
    "work" in {
      implicit val ec = app.materializer.executionContext
      val wsClient = components.wsClient

      whenReady(wsUrl("/ping")(portNumber, wsClient).get) { response =>
        response.status mustBe OK
        response.body mustBe "pong"
      }
    }
  }
} 
Example 29
Source File: FrontEndLoader.scala    From lagom-scala-chirper   with Apache License 2.0 5 votes vote down vote up
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.dns.DnsServiceLocatorComponents
import com.softwaremill.macwire._
import play.api.ApplicationLoader._
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext, Mode}
import router.Routes

import scala.concurrent.ExecutionContext

class FrontEndLoader extends ApplicationLoader {
  override def load(context: Context): Application = context.environment.mode match {
    case Mode.Dev => (new FrontEndModule(context) with LagomDevModeComponents).application
    case _ => (new FrontEndModule(context) with DnsServiceLocatorComponents).application
  }
}

abstract class FrontEndModule(context: Context)
  extends BuiltInComponentsFromContext(context)
    with I18nComponents
    with AhcWSComponents
    with LagomServiceClientComponents {

  override lazy val serviceInfo = ServiceInfo(
    "front-end",
    Map("front-end" -> List(ServiceAcl.forPathRegex("(?!/api/).*")))
  )

  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher

  override lazy val router = {
    wire[Routes]
  }

} 
Example 30
Source File: HelloLoader.scala    From scala-tutorials   with MIT License 5 votes vote down vote up
package com.baeldung.hello.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.baeldung.hello.api.HelloService
import com.baeldung.hello.play.SimplePlayRouter
import com.lightbend.lagom.scaladsl.pubsub.PubSubComponents
import com.softwaremill.macwire._

class HelloLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with LagomDevModeComponents {
    }

  override def describeService = Some(readDescriptor[HelloService])
}

abstract class HelloApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with PubSubComponents
    with AhcWSComponents {

  override lazy val lagomServer: LagomServer = serverFor[HelloService](wire[HelloServiceImpl])
    .additionalRouter(wire[SimplePlayRouter].router)

} 
Example 31
Source File: TokenLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.token.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.packt.chapter11.token.api.TokenService
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

class TokenLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new TokenApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new TokenApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[TokenService])
}

abstract class TokenApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[TokenService].to(wire[TokenServiceImpl])
  )
} 
Example 32
Source File: EchoLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.EchoService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class EchoLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[EchoService])
}

abstract class EchoApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[EchoService](new EchoServiceImpl)
} 
Example 33
Source File: HelloLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.HelloService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class HelloLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[HelloService])
}

abstract class HelloApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[HelloService](new HelloServiceImpl)
} 
Example 34
Source File: SimpleLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package left

import com.lightbend.lagom.scaladsl.api.Descriptor
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer }
import play.api.libs.ws.ahc.AhcWSComponents

class SimpleLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new SimpleApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new SimpleApplication(context) with LagomDevModeComponents

  override def describeService: Option[Descriptor] = Some(readDescriptor[SimpleService])
}

abstract class SimpleApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer: LagomServer = serverFor[SimpleService](new SimpleServiceImpl)
} 
Example 35
Source File: EchoLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.EchoService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class EchoLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new EchoApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[EchoService])
}

abstract class EchoApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[EchoService](new EchoServiceImpl)
} 
Example 36
Source File: HelloLoader.scala    From sbt-reactive-app   with Apache License 2.0 5 votes vote down vote up
package lagomendpoints.impl

import lagomendpoints.api.HelloService
import com.lightbend.lagom.scaladsl.client.ConfigurationServiceLocatorComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomApplicationLoader }
import play.api.libs.ws.ahc.AhcWSComponents

class HelloLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with ConfigurationServiceLocatorComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[HelloService])
}

abstract class HelloApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {
  override lazy val lagomServer = serverFor[HelloService](new HelloServiceImpl)
} 
Example 37
Source File: bakerLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class BakerApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents {
  override lazy val lagomServer: LagomServer = serverFor[BakerService](wire[BakerServiceImpl])
}

class BakerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BakerApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BakerApplication(context) with LagomDevModeComponents

} 
Example 38
Source File: cookLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class CookApplication(context: LagomApplicationContext)
  extends LagomApplication(context) {
  override lazy val lagomServer: LagomServer = serverFor[CookService](wire[CookServiceImpl])
}

class CookLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new CookApplication(context) with AhcWSComponents {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new CookApplication(context) with AhcWSComponents with LagomDevModeComponents

} 
Example 39
Source File: CookServiceSpec.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import ch15.model.Dough
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, Matchers}
import play.api.libs.ws.ahc.AhcWSComponents

class CookServiceSpec extends AsyncWordSpec with Matchers {

  "The CookService" should {
    "make cookies from Dough" in ServiceTest.withServer(ServiceTest.defaultSetup) { ctx =>
      new CookApplication(ctx) with LocalServiceLocator with AhcWSComponents
    } { server =>
      val client = server.serviceClient.implement[CookService]

      client.cook.invoke(Dough(200)).map { cookies =>
        cookies.count should ===(3)
      }
    }
  }
} 
Example 40
Source File: managerLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class ManagerApplication(context: LagomApplicationContext)
    extends LagomApplication(context) with LagomKafkaClientComponents {
  lazy val boyService: BoyService = serviceClient.implement[BoyService]
  lazy val chefService: ChefService = serviceClient.implement[ChefService]
  lazy val cookService: CookService = serviceClient.implement[CookService]
  lazy val bakerService: BakerService = serviceClient.implement[BakerService]
  override lazy val lagomServer: LagomServer =
    serverFor[ManagerService](wire[ManagerServiceImpl])
}

class ManagerLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ManagerApplication(context) with AhcWSComponents {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ManagerApplication(context) with AhcWSComponents
    with LagomDevModeComponents

} 
Example 41
Source File: chefLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents


abstract class ChefApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with CassandraPersistenceComponents with LagomKafkaComponents {
  override lazy val lagomServer: LagomServer = serverFor[ChefService](wire[ChefServiceImpl])
  override lazy val jsonSerializerRegistry = new JsonSerializerRegistry {
    override def serializers = ChefModel.serializers
  }
}

class ChefLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ChefApplication(context) with AhcWSComponents {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ChefApplication(context) with AhcWSComponents with LagomDevModeComponents

} 
Example 42
Source File: boyLoader.scala    From Learn-Scala-Programming   with MIT License 5 votes vote down vote up
package ch15

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

abstract class BoyApplication(context: LagomApplicationContext)
  extends LagomApplication(context) with AhcWSComponents {
  lazy val shopService: ShopService = serviceClient.implement[ShopService]
  override lazy val lagomServer: LagomServer = serverFor[BoyService](wire[BoyServiceImpl])
}

class BoyLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext) =
    new BoyApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext) =
    new BoyApplication(context) with LagomDevModeComponents

} 
Example 43
Source File: CalculatorLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.akka.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.packt.chapter11.akka.api.CalculatorService
import com.softwaremill.macwire.wire
import play.api.libs.ws.ahc.AhcWSComponents

class CalculatorLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new CalculatorApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
    new CalculatorApplication(context) with LagomDevModeComponents
  }

  override def describeServices = List(
    readDescriptor[CalculatorService]
  )
}

abstract class CalculatorApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[CalculatorService].to(wire[CalculatorServiceImpl])
  )
} 
Example 44
Source File: AkkacookbookLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.akkacookbook.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.chapter11.akkacookbook.api.AkkacookbookService
import com.softwaremill.macwire._

class AkkacookbookLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookApplication(context) with LagomDevModeComponents

  override def describeServices = List(
    readDescriptor[AkkacookbookService]
  )
}

abstract class AkkacookbookApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[AkkacookbookService].to(wire[AkkacookbookServiceImpl])
  )

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = AkkacookbookSerializerRegistry

  // Register the AkkaCookbook persistent entity
  persistentEntityRegistry.register(wire[AkkacookbookEntity])
} 
Example 45
Source File: AkkacookbookStreamLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.akkacookbookstream.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.packt.chapter11.akkacookbookstream.api.AkkacookbookStreamService
import com.packt.chapter11.akkacookbook.api.AkkacookbookService
import com.softwaremill.macwire._

class AkkacookbookStreamLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookStreamApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new AkkacookbookStreamApplication(context) with LagomDevModeComponents

  override def describeServices = List(
    readDescriptor[AkkacookbookStreamService]
  )
}

abstract class AkkacookbookStreamApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[AkkacookbookStreamService].to(wire[AkkacookbookStreamServiceImpl])
  )

  // Bind the AkkacookbookService client
  lazy val akkacookbookService = serviceClient.implement[AkkacookbookService]
} 
Example 46
Source File: CatalogServiceComponent.scala    From daf   with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
package it.gov.daf.catalogmanager.service


import catalog_manager.yaml.{Dataset, Error, MetaCatalog, MetadataCat, Success}
import it.gov.daf.catalogmanager.repository.catalog.CatalogRepositoryComponent
import play.api.libs.json.JsValue

import scala.concurrent.Future
import play.api.libs.ws._
import play.api.libs.ws.ahc.AhcWSComponents


trait CatalogServiceComponent {
  this: CatalogRepositoryComponent  =>
  val catalogService: CatalogService

  class CatalogService {


    def listCatalogs(page :Option[Int], limit :Option[Int]) :Seq[MetaCatalog] = {
       catalogRepository.listCatalogs(page, limit)

    }
    def catalog(catalogId :String): Option[MetaCatalog] = {
      catalogRepository.catalog(catalogId)
    }

    def catalogByName(name :String, groups: List[String]): Option[MetaCatalog] = {
      catalogRepository.catalogByName(name, groups)
    }

    def publicCatalogByName(name :String): Option[MetaCatalog] = {
      catalogRepository.publicCatalogByName(name)
    }

    def createCatalog(metaCatalog: MetaCatalog, callingUserid :MetadataCat, ws :WSClient) :Success = {
      println("Service : " +  callingUserid)
      catalogRepository.createCatalog(metaCatalog, callingUserid, ws)
    }

    def createCatalogExtOpenData(metaCatalog: MetaCatalog, callingUserid :MetadataCat, ws :WSClient) :Success = {
      println("Service : " +  callingUserid)
      catalogRepository.createCatalogExtOpenData(metaCatalog, callingUserid, ws)
    }

    def isPresentOnCatalog(name :String) :Option[Boolean] = {
      catalogRepository.isDatasetOnCatalog(name)
    }

    def deleteCatalogByName(nameCatalog: String, user: String, isAdmin: Boolean): Either[Error, Success] = {
      catalogRepository.deleteCatalogByName(nameCatalog, user, isAdmin)
    }

  }
} 
Example 47
Source File: ConsumerLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.consumer.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.packt.chapter11.consumer.api.ConsumerService
import com.packt.chapter11.token.api.TokenService
import com.softwaremill.macwire.wire
import play.api.libs.ws.ahc.AhcWSComponents

class ConsumerLoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new ConsumerApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ConsumerApplication(context) with LagomDevModeComponents

  override def describeServices = List(readDescriptor[ConsumerService])
}

abstract class ConsumerApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[ConsumerService].to(wire[ConsumerServiceImpl])
  )

  lazy val tokenService = serviceClient.implement[TokenService]
} 
Example 48
Source File: TripLoader.scala    From Akka-Cookbook   with MIT License 5 votes vote down vote up
package com.packt.chapter11.trip.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.packt.chapter11.trip.api.TripService
import com.softwaremill.macwire.wire
import play.api.libs.ws.ahc.AhcWSComponents

class TripLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new TripApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
    new TripApplication(context) with LagomDevModeComponents
  }

  override def describeServices = List(
    readDescriptor[TripService]
  )
}

abstract class TripApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents
    with AhcWSComponents {

  // Bind the services that this server provides
  override lazy val lagomServer = LagomServer.forServices(
    bindService[TripService].to(wire[TripServiceImpl])
  )

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = ClientSerializerRegistry

  // Register the AkkaCookbook persistent entity
  persistentEntityRegistry.register(wire[ClientEntity])
} 
Example 49
Source File: HelloWorldLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example.helloworld.impl

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.example.helloworld.api.HelloWorldService
import com.example.helloworld.impl.readsides.StartedReadSideProcessor
import com.example.helloworld.impl.readsides.StoppedReadSideProcessor
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.softwaremill.macwire._

class HelloWorldLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new HelloWorldApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new HelloWorldApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[HelloWorldService])
}

abstract class HelloWorldApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with CassandraPersistenceComponents
    with AhcWSComponents {

  override lazy val lagomServer: LagomServer =
    serverFor[HelloWorldService](wire[HelloWorldServiceImpl])
  override lazy val jsonSerializerRegistry: JsonSerializerRegistry =
    HelloWorldSerializerRegistry
  persistentEntityRegistry.register(wire[HelloWorldEntity])

  private lazy val startedProcessor = wire[StartedReadSideProcessor]
  private lazy val stoppedProcessor = wire[StoppedReadSideProcessor]

  // The following three lines are the key step on this scripted test:
  //  - request the workers of a projection to be started before registering the processor.
  // This service is setup to not start the projections eagerly (see application.conf) but we do
  // start one of the projections programmatically.
  projections.startAllWorkers(StartedReadSideProcessor.Name)

  readSide.register(startedProcessor)
  readSide.register(stoppedProcessor)

} 
Example 50
Source File: FooLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl


import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.FooService
import com.softwaremill.macwire._

class FooLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) with LagomDevModeComponents
}

abstract class FooApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {
  override lazy val lagomServer = serverFor[FooService](wire[FooServiceImpl])
} 
Example 51
Source File: ShoppingCartLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example.shoppingcart.impl

import com.example.shoppingcart.api.ShoppingCartService
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.slick.SlickPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents

class ShoppingCartLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[ShoppingCartService])
}

abstract class ShoppingCartApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with SlickPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[ShoppingCartService](wire[ShoppingCartServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = ShoppingCartSerializerRegistry

  lazy val reportRepository = wire[ShoppingCartReportRepository]
  readSide.register(wire[ShoppingCartReportProcessor])

  //#akka-persistence-register-classic
  // Register the ShoppingCart persistent entity
  persistentEntityRegistry.register(wire[ShoppingCartEntity])
  //#akka-persistence-register-classic

} 
Example 52
Source File: ShoppingCartLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example.shoppingcart.impl

import com.example.shoppingcart.api.ShoppingCartService
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.slick.SlickPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.db.HikariCPComponents
import play.api.libs.ws.ahc.AhcWSComponents
import akka.cluster.sharding.typed.scaladsl.Entity
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry

class ShoppingCartLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new ShoppingCartApplication(context) with LagomDevModeComponents

  override def describeService = Some(readDescriptor[ShoppingCartService])
}

abstract class ShoppingCartApplication(context: LagomApplicationContext)
    extends LagomApplication(context)
    with SlickPersistenceComponents
    with HikariCPComponents
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[ShoppingCartService](wire[ShoppingCartServiceImpl])

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = ShoppingCartSerializerRegistry

  lazy val reportRepository = wire[ShoppingCartReportRepository]
  readSide.register(wire[ShoppingCartReportProcessor])

  //#akka-persistence-init-sharded-behavior
  // in Akka Typed, this is the equivalent of Lagom's PersistentEntityRegistry.register
  clusterSharding.init(
    Entity(ShoppingCart.typeKey) {
      ctx => ShoppingCart.behavior(ctx)
    }
  )
  //#akka-persistence-init-sharded-behavior

} 
Example 53
Source File: A.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package com.example

import akka.NotUsed
import com.lightbend.lagom.scaladsl.api._
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import scala.concurrent.Future

trait A extends Service {
  def hello(name: String): ServiceCall[NotUsed, String]

  override def descriptor = {
    import Service._
    named("a")
      .withCalls(
        pathCall("/hello/:name", hello _)
      )
      .withAutoAcl(true)
  }
}

class AImpl extends A {
  override def hello(name: String) = ServiceCall { _ =>
    Future.successful(s"Hello $name")
  }
}

abstract class AApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override def lagomServer = serverFor[A](new AImpl)
}

class ALoader extends LagomApplicationLoader {
  override def load(context: LagomApplicationContext): LagomApplication =
    new AApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new AApplication(context) with LagomDevModeComponents
} 
Example 54
Source File: BarLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.util.Date

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.BarService
import api.FooService
import com.softwaremill.macwire._

class BarLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) with LagomDevModeComponents
}

abstract class BarApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override lazy val lagomServer = serverFor[BarService](wire[BarServiceImpl])

  lazy val fooService = serviceClient.implement[FooService]

  Files.write(
    environment.getFile("target/reload.log").toPath,
    s"${new Date()} - reloaded\n".getBytes("utf-8"),
    StandardOpenOption.CREATE,
    StandardOpenOption.APPEND
  )
} 
Example 55
Source File: BazLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.util.Date

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.BazService
import com.softwaremill.macwire._

class BazLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BazApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BazApplication(context) with LagomDevModeComponents
}

abstract class BazApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override lazy val lagomServer = serverFor[BazService](wire[BazServiceImpl])

  Files.write(
    environment.getFile("target/reload.log").toPath,
    s"${new Date()} - reloaded\n".getBytes("utf-8"),
    StandardOpenOption.CREATE,
    StandardOpenOption.APPEND
  )
} 
Example 56
Source File: Loader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
import play.api.Application
import play.api.ApplicationLoader
import play.api.BuiltInComponentsFromContext
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._
import router.Routes
import com.lightbend.lagom.scaladsl.api._
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import scala.collection.immutable

class Loader extends ApplicationLoader {
  def load(context: ApplicationLoader.Context): Application = {
    new BuiltInComponentsFromContext(context) with LagomServiceClientComponents with AhcWSComponents
    with LagomDevModeComponents with controllers.AssetsComponents {
      override lazy val serviceInfo = ServiceInfo(
        "p",
        Map(
          "p" -> immutable.Seq(
            ServiceAcl.forPathRegex("/p"),
            ServiceAcl.forPathRegex("/assets/.*")
          )
        )
      )
      override lazy val router = {
        val prefix = "/"
        wire[Routes]
      }
      override lazy val httpFilters  = Nil
      lazy val applicationController = wire[controllers.Application]
    }.application
  }
} 
Example 57
Source File: FooLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.util.Date

import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import api.FooService
import com.softwaremill.macwire._

class FooLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) with LagomDevModeComponents
}

abstract class FooApplication(context: LagomApplicationContext) extends LagomApplication(context) with AhcWSComponents {

  override lazy val lagomServer = serverFor[FooService](wire[FooServiceImpl])

  Files.write(
    environment.getFile("target/reload.log").toPath,
    s"${new Date()} - reloaded\n".getBytes("utf-8"),
    StandardOpenOption.CREATE,
    StandardOpenOption.APPEND
  )
} 
Example 58
Source File: BarLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import api.BarService
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.cluster.ClusterComponents
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

class BarLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BarApplication(context) with LagomDevModeComponents
}

abstract class BarApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents
    with ClusterComponents {

  override lazy val lagomServer = serverFor[BarService](wire[BarServiceImpl])

  lazy val jsonSerializerRegistry = EmptyJsonSerializerRegistry
} 
Example 59
Source File: FooLoader.scala    From lagom   with Apache License 2.0 5 votes vote down vote up
package impl

import api.FooService
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.cluster.ClusterComponents
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents

class FooLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new FooApplication(context) with LagomDevModeComponents
}

abstract class FooApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents
    with ClusterComponents {

  override lazy val lagomServer = serverFor[FooService](wire[FooServiceImpl])

  lazy val jsonSerializerRegistry = EmptyJsonSerializerRegistry
}