本文整理汇总了Scala中akka.http.scaladsl.model._类的典型用法代码示例。如果您正苦于以下问题:Scala _类的具体用法?Scala _怎么用?Scala _使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了_类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: waitForShutdownSignal
//设置package包名称以及导入依赖的类
package essentials.petstore.server
import akka.Done
import akka.actor.ActorSystem
import akka.http.scaladsl.model.{StatusCodes, _}
import akka.http.scaladsl.server.{ExceptionHandler, HttpApp, RejectionHandler, Route}
import akka.http.scaladsl.model.HttpResponse
import com.typesafe.scalalogging.LazyLogging
import play.api.libs.json.OFormat
import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport
import essentials.petstore.domain._
import essentials.petstore.database.{PetRecordsRepository, PetsRepository}
import scala.concurrent.{ExecutionContext, Future}
override def waitForShutdownSignal(actorSystem: ActorSystem)(implicit executionContext: ExecutionContext): Future[Done] = {
logger.info("Press Ctrl-C to shutdown the server...")
Future.never
}
}
trait ModelFormatters extends PlayJsonSupport {
import play.api.libs.json.Json
// TODO add validation to petFormat, for example age < 0 shouldn't be valid
// JSON formatters (i.e. convert object to/from JSON) that we can use
implicit val petFormat: OFormat[Pet] = Json.format[Pet]
implicit val petRecordsFormat: OFormat[PetRecord] = Json.format[PetRecord]
}
object ModelFormatters extends ModelFormatters
示例2: upickleJsValueMarshaller
//设置package包名称以及导入依赖的类
package com.thoughtworks.akka.http
import akka.http.scaladsl.model.{MediaTypes, _}
import akka.http.scaladsl.server.Directives._
import com.thoughtworks.Extractor._
import scala.concurrent.Future
import akka.http.scaladsl.marshalling.Marshaller
import akka.http.scaladsl.unmarshalling.Unmarshaller
trait RpcSupport extends autowire.Server[upickle.Js.Value, upickle.default.Reader, upickle.default.Writer] {
implicit private def upickleJsValueMarshaller = {
Marshaller.StringMarshaller.wrap[upickle.Js.Value, MessageEntity](MediaTypes.`application/json`)(_.toString)
}
implicit private def upickleJsValueUnmarshaller = {
Unmarshaller.stringUnmarshaller.map(upickle.json.read)
}
final def write[Result](r: Result)(implicit writer: upickle.default.Writer[Result]) = {
writer.write(r)
}
final def read[Result](p: upickle.Js.Value)(implicit reader: upickle.default.Reader[Result]) = {
reader.read(p)
}
final def rpc(packagePrefix: String*)(routes: PartialFunction[Request, Future[upickle.Js.Value]]) = {
path(Segments) { segments =>
entity(as[upickle.Js.Value]) {
case upickle.Js.Obj([email protected]_*) =>
autowire.Core.Request(packagePrefix ++ segments, keyValuePairs.toMap) match {
case routes.extract(response) =>
complete {
response
}
case _ =>
reject
}
case _ =>
complete(HttpResponse(StatusCodes.BadRequest))
}
}
}
}
object RpcSupport extends RpcSupport
示例3: extractHeaders
//设置package包名称以及导入依赖的类
package com.bitworks.rtb.service
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpHeader.ParsingResult.Ok
import akka.http.scaladsl.model.{HttpEntity, _}
import akka.stream.Materializer
import com.bitworks.rtb.model.ad.response.ErrorCode
import com.bitworks.rtb.model.http._
import com.bitworks.rtb.service.ContentTypeConversions._
import scala.concurrent.Future
private def extractHeaders(response: HttpResponse) = {
response.headers.map(x => HttpHeaderModel(x.name, x.value))
}
override def make(request: HttpRequestModel) = {
val entity = request.body match {
case None => HttpEntity(request.contentType, Array.emptyByteArray)
case Some(bytes) => HttpEntity(request.contentType, bytes)
}
val headers = request.headers.map { case [email protected](key, value) =>
HttpHeader.parse(key, value) match {
case Ok(header, _) => header
case _ => throw new DataValidationException(ErrorCode.INCORRECT_HEADER_VALUE)
}
}.toList
val akkaRequest = HttpRequest(
method = request.method match {
case GET => HttpMethods.GET
case POST => HttpMethods.POST
},
uri = request.uri,
entity = entity,
headers = headers
)
val fResponse = Http().singleRequest(akkaRequest)
for {
response <- fResponse
data <- extractData(response)
} yield HttpResponseModel(
data._1,
response.status.intValue,
data._2,
extractHeaders(response))
}
}
示例4: VersionService
//设置package包名称以及导入依赖的类
package org.stanoq.version
package org.stanoq.crawler
import akka.http.scaladsl.model.{HttpEntity, _}
import akka.http.scaladsl.server.Directives._
import com.typesafe.config.ConfigFactory
class VersionService {
val version = ConfigFactory.load().getString("stanoq.version")
val route = pathPrefix("version") {
pathEnd {
get {
complete(HttpResponse(StatusCodes.OK, entity = HttpEntity(ContentType(MediaTypes.`application/json`), s"""{"version": $version}""")))
}
}
}
}