2015-05-21 17:17:55 +02:00
|
|
|
/*
|
2016-02-23 12:58:39 +01:00
|
|
|
* Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
|
2015-05-21 17:17:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.http.javadsl.server
|
|
|
|
|
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import akka.http.scaladsl.Http.ServerBinding
|
2016-01-21 16:37:26 +01:00
|
|
|
import java.util.concurrent.CompletionStage
|
2015-05-21 17:17:55 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A convenience class to derive from to get everything from HttpService and Directives into scope.
|
2016-03-15 18:55:03 +01:00
|
|
|
* Implement the [[#createRoute]] method to provide the Route and then call [[#bindRoute]]
|
2015-05-21 17:17:55 +02:00
|
|
|
* to start the server on the specified interface.
|
|
|
|
|
*/
|
|
|
|
|
abstract class HttpApp
|
|
|
|
|
extends AllDirectives
|
|
|
|
|
with HttpServiceBase {
|
2015-07-17 14:02:23 +02:00
|
|
|
def createRoute(): Route
|
2015-05-21 17:17:55 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starts an HTTP server on the given interface and port. Creates the route by calling the
|
2016-03-15 18:55:03 +01:00
|
|
|
* user-implemented [[#createRoute]] method and uses the route to handle requests of the server.
|
2015-05-21 17:17:55 +02:00
|
|
|
*/
|
2016-01-21 16:37:26 +01:00
|
|
|
def bindRoute(interface: String, port: Int, system: ActorSystem): CompletionStage[ServerBinding] =
|
2015-05-21 17:17:55 +02:00
|
|
|
bindRoute(interface, port, createRoute(), system)
|
|
|
|
|
}
|