Created
March 9, 2012 19:57
-
-
Save elbowich/2008342 to your computer and use it in GitHub Desktop.
spray gateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Gateway { | |
import cc.spray.Directives._ | |
import cc.spray.directives.Remaining | |
import cc.spray.client.HttpConduit | |
val conduit = new HttpConduit("localhost", 8080) // this will connect to the back-end | |
val route = | |
path("test-service" / Remaining) { | |
path => ctx => val headers = ctx.request.headers.filter(_.name != "Host") | |
val request = ctx.request.copy(uri = "/mock/" + path, headers = headers) | |
ctx complete conduit.sendReceive(request).map { | |
_.withHeadersTransformed(_.filter(_.name != "Date")) | |
} | |
} ~ | |
pathPrefix("mock") { | |
_ complete "back-end response" | |
} | |
} | |
object Boot extends App { | |
import akka.actor.Actor._ | |
import akka.actor.Supervisor | |
import akka.config.Supervision.{Supervise, SupervisorConfig, Permanent, OneForOneStrategy} | |
import cc.spray.{SprayCanRootService, HttpService} | |
import cc.spray.can.{HttpClient, HttpServer} | |
locally { | |
val httpClient = actorOf(new HttpClient()) | |
val httpService = actorOf(new HttpService(Gateway.route)) | |
val rootService = actorOf(new SprayCanRootService(httpService)) | |
val httpServer = actorOf(new HttpServer()) | |
Supervisor( | |
SupervisorConfig( | |
OneForOneStrategy(List(classOf[Exception]), 3, 100), | |
List( | |
Supervise(httpClient, Permanent), | |
Supervise(httpService, Permanent), | |
Supervise(rootService, Permanent), | |
Supervise(httpServer, Permanent) | |
) | |
) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment