本文整理汇总了Scala中play.api.libs.ws.WSAuthScheme类的典型用法代码示例。如果您正苦于以下问题:Scala WSAuthScheme类的具体用法?Scala WSAuthScheme怎么用?Scala WSAuthScheme使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WSAuthScheme类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: payloadJson
//设置package包名称以及导入依赖的类
package neo4j.client
import com.typesafe.config.Config
import play.api.libs.json._
import play.api.libs.ws.{ WSAuthScheme, WSRequest, WSResponse }
import scala.concurrent.Future
trait Neo4jRestConnection {
protected val config: Config
protected val client = WSClient.client
val SERVER_ROOT_HOST = config.getString("neo4j-scala-dsl.neo4j.rest.host")
val SERVER_ROOT_PORT = config.getInt("neo4j-scala-dsl.neo4j.rest.port")
val SERVER_ROOT_URI = s"http://$SERVER_ROOT_HOST:$SERVER_ROOT_PORT"
val SERVER_ROOT_DATA_URI = s"$SERVER_ROOT_URI/db/data"
val SERVER_USERNAME = config.getString("neo4j-scala-dsl.neo4j.rest.username")
val SERVER_PASSWORD = config.getString("neo4j-scala-dsl.neo4j.rest.password")
val txUri = s"$SERVER_ROOT_DATA_URI/transaction/commit"
def payloadJson(statements: String*): JsObject =
Json.obj("statements" -> statements.map(s ? Map("statement" -> s)).toList)
def request(url: String): WSRequest = client.url(url)
.withHeaders(
("Content-Type", "application/json"),
("Accept", "application/json"))
.withAuth(SERVER_USERNAME, SERVER_PASSWORD, WSAuthScheme.BASIC)
def txCommit(queries: String*): Future[WSResponse] = {
println(s"txCommit: $queries")
request(txUri).post(payloadJson(queries: _*))
}
}
开发者ID:mardambey,项目名称:neo4j-scala-dsl,代码行数:37,代码来源:Neo4jRestConnection.scala
示例2: ElasticsearchClient
//设置package包名称以及导入依赖的类
package utils
import javax.inject.{Inject, Singleton}
import play.api.libs.ws.{WSAuthScheme, WSClient, WSRequest, WSResponse}
import play.api.{Configuration, Environment, Logger}
import scala.concurrent.{ExecutionContext, Future}
@Singleton
class ElasticsearchClient @Inject()(ws: WSClient, environment: Environment, configuration: Configuration)(implicit ec: ExecutionContext) {
val logger = Logger("ElasticsearchClient")
val elasticsearchUri: String = configuration.getString("elasticsearch.uri").getOrElse("http://localhost:9200")
val elasticsearchUser: Option[String] = configuration.getString("elasticsearch.user")
val elasticsearchPassword: Option[String] = configuration.getString("elasticsearch.password")
logger.info(s"Elasticsearch URI = $elasticsearchUri")
private def client(path: String): WSRequest = {
val sanitizedPath: String = if (path.startsWith("/")) {
path
} else {
s"/$path"
}
elasticsearchUser match {
case None => ws.url(s"$elasticsearchUri$sanitizedPath")
case Some(user) => ws.url(s"$elasticsearchUri$sanitizedPath").withAuth(user, elasticsearchPassword.getOrElse(""), WSAuthScheme.BASIC)
}
}
def bulk(body: String): Future[WSResponse] = {
client(s"/_bulk").post(body)
}
}
开发者ID:devconferences,项目名称:devconferences,代码行数:39,代码来源:ElasticsearchClient.scala
注:本文中的play.api.libs.ws.WSAuthScheme类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论