Permalink
Browse files

Add `interface` to `SprayConfiguration` to allow custom bind interface.

Fixes #155
  • Loading branch information...
2rs2ts committed Sep 1, 2015
1 parent 1edb36f commit 702317c04240a00ede4ad0d7702f3a0234238829
@@ -73,7 +73,10 @@ with the different parsed bodies you send to it.
```scala
object MyServer extends CascadeApp {
val svcName = "sample-service"
val cfg = SprayConfiguration(serviceName = svcName, port = 8080, backlog = 5) {
val cfg = SprayConfiguration(serviceName = svcName,
interface = "localhost",
port = 8080,
backlog = 5) {
//This is where you put your routes. We recommend using spray-routing here,
//but you can also write your own routing code that returns a
//spray.routing.Route.
@@ -34,12 +34,13 @@ object MyHttpServer extends CascadeApp {
val systemWrapper = new ActorSystemWrapper("MyHttpService")
val TimeoutSecs = 10
val Interface = "localhost"
val Port = 8080
val Backlog = 5
private implicit val actorRefFactory = systemWrapper.actorRefFactory
private implicit val timeout = new Timeout(TimeoutSecs, TimeUnit.SECONDS)
val config = SprayConfiguration("my-http-server", Port, Backlog) {
val config = SprayConfiguration("my-http-server", Interface, Port, Backlog) {
get {
path("hello") {
ResourceDriver.serve(MyHttpResource.apply, MyHttpResource.requestParser)
@@ -15,17 +15,16 @@
*/
package com.paypal.cascade.http.actor
import spray.can.server.ServerSettings
import scala.concurrent.Future
import akka.actor.{Actor, Props}
import akka.io.{IO => AkkaIO}
import akka.pattern.ask
import akka.util.Timeout
import spray.can.Http
import spray.can.server.ServerSettings
import spray.io.ServerSSLEngineProvider
import spray.routing.{RejectionHandler, ExceptionHandler, RoutingSettings}
import spray.routing.{ExceptionHandler, RoutingSettings}
import spray.util.LoggingContext
import com.paypal.cascade.akka.actor.ActorSystemWrapper
@@ -80,7 +79,7 @@ object SprayActor {
val sprayActorProps = Props(new SprayActor(sprayConfig, systemWrapper))
val sprayActor = systemWrapper.system.actorOf(sprayActorProps)
val bindMsg = Http.Bind(sprayActor,
interface = "0.0.0.0",
interface = sprayConfig.interface,
port = sprayConfig.port,
backlog = sprayConfig.backlog,
settings = serverSettings)
@@ -21,14 +21,18 @@ import spray.routing.{RejectionHandler, Route}
* This class provides configuration information for a spray service
*/
class SprayConfiguration(val serviceName: String,
val interface: String,
val port: Int,
val backlog: Int,
val route: Route,
val customRejectionHandler: Option[RejectionHandler] = None)
object SprayConfiguration {
def apply(serviceName: String, port: Int, backlog: Int, customRejectionHandler: Option[RejectionHandler] = None)
def apply(serviceName: String,
interface: String,
port: Int, backlog: Int,
customRejectionHandler: Option[RejectionHandler] = None)
(route: Route): SprayConfiguration = {
new SprayConfiguration(serviceName, port, backlog, route, customRejectionHandler)
new SprayConfiguration(serviceName, interface, port, backlog, route, customRejectionHandler)
}
}
@@ -16,18 +16,20 @@
package com.paypal.cascade.http.tests.actor
import java.util.concurrent.TimeUnit
import scala.concurrent.Await
import akka.util.Timeout
import com.paypal.cascade.akka.actor.ActorSystemWrapper
import spray.can.server.ServerSettings
import spray.io.ServerSSLEngineProvider
import spray.routing._
import org.specs2._
import org.specs2.mock.Mockito
import com.paypal.cascade.akka.actor.ActorSystemWrapper
import com.paypal.cascade.common.tests.util.CommonImmutableSpecificationContext
import com.paypal.cascade.http.actor._
import com.paypal.cascade.http.server._
import spray.can.server.ServerSettings
import spray.routing._
import spray.io.ServerSSLEngineProvider
import scala.concurrent.Await
import scala.concurrent.duration.Duration
/**
* Tests for [[com.paypal.cascade.http.actor.SprayActor]]
@@ -43,12 +45,13 @@ class SprayActorSpecs
trait Context extends CommonImmutableSpecificationContext {
val backlog: Int = 0
val interface = "0.0.0.0"
val port: Int = 0
val serviceName = "http"
val route = mock[Route]
val wrapper = new ActorSystemWrapper(serviceName)
val config = new SprayConfiguration(serviceName, port, backlog, route, None)
val config = new SprayConfiguration(serviceName, interface, port, backlog, route, None)
implicit val timeout = Timeout(10, TimeUnit.SECONDS)
}
@@ -60,7 +60,7 @@ class ResourceServiceSpecs extends SpecificationLike with ScalaCheck { def is =
private lazy val systemWrapper = new ActorSystemWrapper(serviceName)
private lazy val config = SprayConfiguration(serviceName, 8080, 15) {
private lazy val config = SprayConfiguration(serviceName, "localhost", 8080, 15) {
path("ping") {
get {
ResourceDriver.serve(createDummyResource, parseRequest)(systemWrapper.actorRefFactory)

0 comments on commit 702317c

Please sign in to comment.