• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala _类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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 
开发者ID:littlenag,项目名称:scala-essentials-petstore,代码行数:35,代码来源:RestServer.scala


示例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 
开发者ID:ThoughtWorksInc,项目名称:akka-http-rpc,代码行数:51,代码来源:RpcSupport.scala


示例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))
  }
} 
开发者ID:bwsw,项目名称:simple-rtb-exchange,代码行数:53,代码来源:HttpRequestMaker.scala


示例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}""")))
        }
      }
    }
} 
开发者ID:olka,项目名称:stanoq,代码行数:20,代码来源:VersionService.scala



注:本文中的akka.http.scaladsl.model._类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Handler类代码示例发布时间:2022-05-23
下一篇:
Scala ScallopConf类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap