本文整理汇总了Scala中com.twitter.finatra.http.Controller类的典型用法代码示例。如果您正苦于以下问题:Scala Controller类的具体用法?Scala Controller怎么用?Scala Controller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Controller类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: QwebmonController
//设置package包名称以及导入依赖的类
package com.criteo.qwebmon
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
class QwebmonController(drivers: Map[String, DbDriver]) extends Controller {
get("/refresh/:target") { r: Request =>
val targetName = r.getParam("target")
drivers.get(targetName).map { driver =>
val runningQueries = driver.runningQueries
DbStatus(runningQueries, runningQueries.length)
}.getOrElse(response.badRequest(s"invalid target supplied: $targetName"))
}
get("/") { r: Request =>
response.ok.file("/index.html")
}
}
case class DbStatus(runningQueries: Seq[RunningQuery], runningQueryCount: Int)
开发者ID:jqcoffey,项目名称:qwebmon,代码行数:23,代码来源:QwebmonController.scala
示例2: ServerStatsController
//设置package包名称以及导入依赖的类
package br.com.verde.serverstats
import com.twitter.finatra.http.Controller
import com.google.inject.Inject
import com.twitter.finatra.validation._
import com.google.inject.Singleton
import com.twitter.finagle.http.Request
import java.lang.management.ManagementFactory
import java.lang.management.OperatingSystemMXBean
import java.io.File
@Singleton
class ServerStatsController @Inject() extends Controller {
val runtime = Runtime.getRuntime
val osBean = ManagementFactory.getOperatingSystemMXBean
val runtimeBean = ManagementFactory.getRuntimeMXBean
val memoryBean = ManagementFactory.getMemoryMXBean
val megabyte = 1024 * 1024
val second = 1000 // milisecond
get("/serverStats") {
request: Request =>
val jvmTotalRam = runtime.maxMemory
val jvmFreeRam = runtime.freeMemory
val availableProcessors = osBean.getAvailableProcessors
val freeSpace = File.listRoots.head.getFreeSpace
val serverSystemLoad = osBean.getSystemLoadAverage
val serverUptime = runtimeBean.getUptime
val param = request.getParam("onlyRam")
if (param == null) {
response
.ok
.json(s"""{ "jvm_total_ram": "${jvmTotalRam / megabyte} Mb",
"jvm_free_ram": "${jvmFreeRam / megabyte} Mb",
"free_space": "${freeSpace / megabyte} Mb",
"server_system_load": "${serverSystemLoad} %",
"server_uptime": "${serverUptime / second} s",
"available_processors": "${availableProcessors}" }""")
} else {
response
.ok
.json(s"""{ "jvm_total_ram": "${jvmTotalRam / megabyte} Mb",
"jvm_free_ram": "${jvmFreeRam / megabyte} Mb" }""")
}
}
}
开发者ID:verdetecnologia,项目名称:ServerStats,代码行数:54,代码来源:ServerStatsController.scala
示例3: WishListsController
//设置package包名称以及导入依赖的类
package me.kamkor.wishlists.controllers
import javax.inject.{Inject, Singleton}
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import com.twitter.inject.Logging
import me.kamkor.wishlists.domain.http.WishListPutRequest
import me.kamkor.wishlists.repository.WishListsRepository
@Singleton
class WishListsController @Inject()(
wishListsRepository: WishListsRepository
) extends Controller with Logging {
get("/:tenant/wishlists/:id") { request: Request =>
wishListsRepository.get(request.getParam("tenant"), request.getParam("id"))
}
put("/:tenant/wishlists/:id") { request: WishListPutRequest =>
wishListsRepository.update(request.tenant, request.toDomain()) map (_ => response.noContent)
}
delete("/:tenant/wishlists/:id") { request: Request =>
wishListsRepository.delete(request.getParam("tenant"), request.getParam("id")) map (_ => response.noContent)
}
}
开发者ID:kamkor,项目名称:yaas-wishlist-service,代码行数:30,代码来源:WishListsController.scala
示例4: LoginController
//设置package包名称以及导入依赖的类
package com.example
import java.util.concurrent.TimeUnit
import com.example.db.DB
import com.twitter.finagle.http.{Cookie, Request}
import com.twitter.finatra.http.Controller
import com.twitter.finatra.request.{FormParam, QueryParam}
import com.twitter.util.Await
import scala.concurrent.duration._
class LoginController extends Controller {
post("/login") { request: Request =>
val username = request.params("loginName")
val password = request.params("loginPass")
if (username == "god" && password == "multipass") {
val f = DB.createToken(1).map { token =>
info(s"token generated: $token")
response
.ok("You are logged in! That's very cool:)")
.cookie("auth_token", token)
}
Await.result(f)
}
else response.unauthorized()
}
}
开发者ID:Sergey778,项目名称:finatra_test,代码行数:31,代码来源:LoginController.scala
示例5: HealthController
//设置package包名称以及导入依赖的类
package io.sokol.finatra.protobuf.integration.app
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import io.sokol.finatra.protobuf.messages.Protos.Health
import io.sokol.finatra.protobuf.messages.Protos.Health.Status
class HealthController extends Controller {
get("/marshal") { request: Request =>
Health.newBuilder()
.setStatus(Status.OK)
.build()
}
post("/unmarshal") { payload: Health =>
payload
}
}
开发者ID:csokol,项目名称:finatra-protobuf,代码行数:21,代码来源:HealthController.scala
示例6: FitmanApp
//设置package包名称以及导入依赖的类
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.routing.HttpRouter
import com.twitter.finatra.http.{Controller, HttpServer}
object FitmanApp extends FitmanServer
class FitmanServer extends HttpServer {
override protected def configureHttp(router: HttpRouter): Unit = {
router.add(new HelloController)
}
}
class HelloController extends Controller {
get("/hello") { request: Request =>
"Fitman says hello"
}
}
开发者ID:simoncyl,项目名称:Fitman,代码行数:20,代码来源:FitmanApp.scala
示例7: QuoteController
//设置package包名称以及导入依赖的类
package net.songpon.controller
import javax.inject.Inject
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import net.songpon.service.QuoteServiceImpl
class QuoteController @Inject()(quoteService: QuoteServiceImpl) extends Controller {
get("/scalaquote/api/v1/quotes") { request : Request =>
try {
response.ok.json(quoteService.getQuotes())
} catch {
case e: Throwable => {
println(e.getMessage)
}
}
}
}
开发者ID:tsongpon,项目名称:scala-quote,代码行数:22,代码来源:QuoteController.scala
示例8: Test
//设置package包名称以及导入依赖的类
package com.example
import com.github.xiaodongw.swagger.finatra.SwaggerSupport
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import io.swagger.models.{Info, Swagger}
import com.twitter.util.Future
class Test {
def doThing : Future[String] = {
Future value "This is a string"
}
}
case class Pong(pong: String)
object FinatraSwaggerDocument extends Swagger
class PingController extends Controller with SwaggerSupport {
FinatraSwaggerDocument.info(new Info()
.description("Simple ping service with both get and post methods")
.version("0.0.1")
.title("Finagle Http Example Server")
)
implicit protected val swagger = FinatraSwaggerDocument
get("/ping",
swagger { o =>
o.summary("Get service for pings")
.tag("Ping")
.responseWith[Pong](200, "the pong message payload")
.responseWith(404, "there is no pong")
}
) { request: Request =>
info("get ping")
Future.value(Pong("pong"))
}
post("/ping",
swagger { o =>
o.summary("Post service for ping")
.tag("Ping")
.bodyParam[String]("a stringy payload")
.responseWith[Pong](200, "the pong message payload")
.responseWith(420, "you need to enhance your calm")
.responseWith(404, "something is not right")
}
) { request: Request =>
info("post ping")
val contentString = request.getContentString()
Future.value(Pong(s"$contentString ping"))
}
}
开发者ID:divanvisagie,项目名称:finagle-http-example,代码行数:58,代码来源:PingController.scala
示例9: ManagementController
//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.reindexer.controllers
import javax.inject.{Inject, Singleton}
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import uk.ac.wellcome.platform.reindexer.models.{JobStatus, ReindexStatus}
@Singleton
class ManagementController @Inject()() extends Controller {
get("/management/healthcheck") { request: Request =>
val currentStatus = ReindexStatus.currentStatus
val respond = currentStatus match {
case ReindexStatus(JobStatus.Init, _, _) => response.ok.json _
case ReindexStatus(JobStatus.Working, _, _) => response.ok.json _
case ReindexStatus(JobStatus.Success, _, _) => response.created.json _
case ReindexStatus(JobStatus.Failure, _, _) =>
response.internalServerError.json _
}
respond(currentStatus.toMap)
}
}
开发者ID:wellcometrust,项目名称:platform-api,代码行数:25,代码来源:ManagementController.scala
示例10: ManagementController
//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.api.controllers
import javax.inject.{Inject, Singleton}
import com.sksamuel.elastic4s.http.HttpClient
import com.sksamuel.elastic4s.http.ElasticDsl._
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import uk.ac.wellcome.utils.GlobalExecutionContext.context
@Singleton
class ManagementController @Inject()(
elasticClient: HttpClient
) extends Controller {
get("/management/healthcheck") { request: Request =>
response.ok.json(Map("message" -> "ok"))
}
get("/management/clusterhealth") { request: Request =>
elasticClient
.execute { clusterHealth() }
.map(health => response.ok.json(health.status))
}
}
开发者ID:wellcometrust,项目名称:platform-api,代码行数:26,代码来源:ManagementController.scala
示例11: ContextController
//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.api.controllers
import com.twitter.inject.annotations.Flag
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import javax.inject.{Inject, Singleton}
@Singleton
class ContextController @Inject()(
@Flag("api.prefix") apiPrefix: String
) extends Controller {
prefix(apiPrefix) {
get("/context.json") { request: Request =>
response.ok.file("context.json")
}
}
}
开发者ID:wellcometrust,项目名称:platform-api,代码行数:22,代码来源:ContextController.scala
示例12: SwaggerController
//设置package包名称以及导入依赖的类
package uk.ac.wellcome.platform.api.controllers
import com.twitter.inject.annotations.Flag
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import io.swagger.util.Json
import io.swagger.models.{Info, Scheme}
import javax.inject.{Inject, Singleton}
import uk.ac.wellcome.platform.api.ApiSwagger
@Singleton
class SwaggerController @Inject()(
@Flag("api.scheme") apiScheme: String,
@Flag("api.prefix") apiPrefix: String,
@Flag("api.version") apiVersion: String,
@Flag("api.host") apiHost: String
) extends Controller {
val scheme = apiScheme match {
case "https" => Scheme.HTTPS
case _ => Scheme.HTTP
}
prefix(apiPrefix) {
get("/swagger.json") { request: Request =>
ApiSwagger.info(
new Info()
.description("Search our collections")
.version(apiVersion)
.title("Catalogue"))
ApiSwagger.scheme(scheme)
ApiSwagger.host(apiHost)
ApiSwagger.basePath(apiPrefix)
ApiSwagger.produces("application/json")
ApiSwagger.produces("application/ld+json")
response.ok.json(Json.mapper.writeValueAsString(ApiSwagger))
}
}
}
开发者ID:wellcometrust,项目名称:platform-api,代码行数:46,代码来源:SwaggerController.scala
示例13: AuthenticationController
//设置package包名称以及导入依赖的类
package com.writ.api.controllers
import javax.inject.Inject
import com.twitter.finatra.http.Controller
import com.writ.api.domain.http.{LoginRequest, RegisterUserRequest}
import com.writ.api.services.AuthenticationService
class AuthenticationController @Inject()(authenticationService: AuthenticationService)
extends Controller {
post("/register") { request: RegisterUserRequest =>
authenticationService.createUser(request) handle {
case _: Exception => response.conflict("User already exists")
}
}
post("/login") { request: LoginRequest =>
authenticationService.login(request) handle {
case _: Exception => response.unauthorized("Invalid login details")
}
}
}
开发者ID:divanvisagie,项目名称:writ-api,代码行数:24,代码来源:AuthenticationController.scala
示例14: Frontend
//设置package包名称以及导入依赖的类
package com.twitter.diffy
import javax.inject.Inject
import com.twitter.diffy.proxy.Settings
import com.twitter.finatra.http.Controller
import com.twitter.finagle.http.Request
class Frontend @Inject()(settings: Settings) extends Controller {
case class Dashboard(
serviceName: String,
serviceClass: String,
apiRoot: String,
excludeNoise: Boolean,
relativeThreshold: Double,
absoluteThreshold: Double)
get("/") { req: Request =>
response.ok.view(
"dashboard.mustache",
Dashboard(
settings.serviceName,
settings.serviceClass,
settings.apiRoot,
req.params.getBooleanOrElse("exclude_noise", false),
settings.relativeThreshold,
settings.absoluteThreshold)
)
}
get("/css/:*") { request: Request =>
response.ok.file(request.path)
}
get("/scripts/:*") { request: Request =>
response.ok.file(request.path)
}
}
开发者ID:sachinmanchanda,项目名称:diffy_unicast,代码行数:40,代码来源:Frontend.scala
示例15: TestsController
//设置package包名称以及导入依赖的类
package fr.quidquid.my_api.controllers
import java.sql.ResultSet
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import org.jooq.{Result, Record}
import fr.quidquid.my_api.DBSupport._
import scala.collection.JavaConversions._
import scala.collection.mutable.ListBuffer
class TestsController extends Controller {
get("/ping") { request: Request =>
"pong"
}
get("/users") { request: Request =>
val sql = "SELECT * FROM users"
val rs: ResultSet = ds.getConnection.createStatement().executeQuery(sql)
val result: Result[Record] = db.fetch(rs)
var list = new ListBuffer[User]()
for (r: Record <- result) {
val id: Int = r.getValue("id").asInstanceOf[Int]
val email: String = r.getValue("email").asInstanceOf[String]
val pass: String = r.getValue("password").asInstanceOf[String]
list += User(id, email, pass)
}
response.ok.json(list)
}
}
开发者ID:jrevault,项目名称:finatra2-startup,代码行数:32,代码来源:TestsController.scala
示例16: PingController
//设置package包名称以及导入依赖的类
package com.example.controllers
import javax.inject._
import com.example.domain.{User, UserContext}
import com.example.domain.http.PingResponse
import com.example.swagger.TodoSwaggerDocument
import com.github.xiaodongw.swagger.finatra.SwaggerSupport
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
class PingController @Inject()(userContext: Provider[UserContext]) extends Controller with SwaggerSupport {
implicit protected val swagger = TodoSwaggerDocument
get("/ping", swagger {
_.summary("Get response for ping")
.tag("Ping")
.headerParam[String]("Authorization","The authorization token",required = true)
.responseWith[PingResponse](200, "The pong message")
}) { request: Request =>
info("ping")
val username = userContext.get.username
PingResponse(s"pong ${username}")
}
}
开发者ID:divanvisagie,项目名称:finatra-todo-app,代码行数:27,代码来源:PingController.scala
示例17: TodoController
//设置package包名称以及导入依赖的类
package com.example.controllers
import javax.inject.{Inject, Provider}
import com.example.domain.{Todo, UserContext}
import com.example.domain.http.{LoginRequest, TodoPostRequest, TodoPostResponse}
import com.example.services.TodoService
import com.example.swagger.TodoSwaggerDocument
import com.github.xiaodongw.swagger.finatra.SwaggerSupport
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
class TodoController @Inject()(userContext: Provider[UserContext],todoService: TodoService) extends Controller with SwaggerSupport {
implicit protected val swagger = TodoSwaggerDocument
get("/todo", swagger {
_.summary("Get list of todos for the logged in user")
.tag("Todo")
.headerParam[String]("Authorization","The authorization token", required = true)
.responseWith[Seq[Todo]](200, "user's list of todos")
}) { request: Request =>
info("todo get")
todoService.list(userContext.get.username)
}
post("/todo", swagger {
_.summary("Create new todo for user")
.tag("Todo")
.bodyParam[TodoPostRequest]("Todo object")
.headerParam[String]("Authorization","The authorization token", required = true)
.responseWith[TodoPostResponse](200, "write was a success")
}) { post: TodoPostRequest =>
info("todo post")
todoService.create(userContext.get.username, post.toDomain)
TodoPostResponse("write successful")
}
}
开发者ID:divanvisagie,项目名称:finatra-todo-app,代码行数:38,代码来源:TodoController.scala
示例18: UserController
//设置package包名称以及导入依赖的类
package com.example.controllers
import javax.inject.Inject
import com.example.domain.http.{LoginRequest, LoginResponse}
import com.example.services.UserService
import com.example.swagger.TodoSwaggerDocument
import com.github.xiaodongw.swagger.finatra.SwaggerSupport
import com.twitter.finatra.http.Controller
class UserController @Inject()(userService: UserService) extends Controller with SwaggerSupport {
implicit protected val swagger = TodoSwaggerDocument
post("/login", swagger {
_.summary("Check login details and return token if successful")
.tag("User")
.bodyParam[LoginRequest]("User details")
.responseWith[LoginResponse](200, "Valid token to use in headers")
.responseWith(401, "Invalid Credentials")
}) { loginRequest: LoginRequest =>
for {
loginResponse <- userService.login(loginRequest)
} yield {
loginResponse match {
case None => response.unauthorized("Invalid credentials")
case _ => response.ok(loginResponse)
}
}
}
}
开发者ID:divanvisagie,项目名称:finatra-todo-app,代码行数:33,代码来源:UserController.scala
示例19: PingController
//设置package包名称以及导入依赖的类
package com.example.http
import java.text.SimpleDateFormat
import java.util.Date
import java.util.concurrent.TimeUnit
import javax.inject.{Inject, Singleton}
import com.example.filter.AddCookieFilter
import com.example.service.ExampleService
import com.twitter.finagle.http.{Cookie, Request}
import com.twitter.finatra.http.Controller
import com.twitter.util
@Singleton
class PingController @Inject() (service: ExampleService) extends Controller {
get("/ping") { request: Request =>
info("ping")
"pong" + System.currentTimeMillis()
}
get("/name") { request: Request =>
service.myDo(request)
response.ok.plain("Bob")
}
get("/cookie") { request: Request =>
val format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
println("Come in /cookie:"+format.format(new Date()))
val c1 = new Cookie("SESSION_ID", System.currentTimeMillis().toString)
c1.maxAge = util.Duration.apply(500, TimeUnit.SECONDS)
val c2 = new Cookie("OPEN_ID", System.currentTimeMillis().toString)
c2.maxAge = util.Duration.apply(500, TimeUnit.SECONDS)
val c3 = new Cookie("USER_ID", System.currentTimeMillis().toString)
c3.maxAge = util.Duration.apply(500, TimeUnit.SECONDS)
response.ok.plain("Add Cookie OK!").cookie(c1).cookie(c2).cookie(c3)
}
filter[AddCookieFilter].get("/trace") { request: Request =>
val buffer = new StringBuffer()
buffer.append(request.params.map { t => t._1+":"+t._2 }.mkString("<br/>"))
buffer.append(request.cookies.map { t => t._1+":"+t._2.value }.mkString("<br/>"))
buffer.append(request.response.cookies.map { t => t._1+":"+t._2.value }.mkString("<br/>"))
response.ok.html(buffer.toString)
}
}
开发者ID:yafengli,项目名称:finatra-freemarker-seed.g8,代码行数:47,代码来源:PingController.scala
示例20: HomeController
//设置package包名称以及导入依赖的类
package com.example.http
import java.io._
import javax.inject.{Inject, Singleton}
import com.example.service.ExampleService
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import com.twitter.finatra.http.request.RequestUtils
import finatra.freemarker.{Freemarker, FreemarkerConfigurationFactory}
@Singleton
class HomeController @Inject()(service: ExampleService, freemarkerConfigurationFactory: FreemarkerConfigurationFactory) extends Controller {
get("/") { _: Request =>
DemoView("YaFengLi", List(Person("test_1", 1), Person("test_2", 2), Person("test_3", 3)))
}
post("/upload") { request: Request =>
RequestUtils.multiParams(request).filter(_._1 == "file").headOption match {
case Some(k) =>
k._2.filename match {
case Some(fn) =>
val file = new File(fn)
val out = new BufferedOutputStream(new FileOutputStream(file))
try out.write(k._2.data)
finally {
out.flush()
out.close()
}
response.ok.header("content-disposition","inline; filename='"+fn+".txt'").file(file)
case None => response.notFound
}
case None => response.notFound
}
}
}
@Freemarker("demo")
case class DemoView(name: String, persons: List[Person])
case class Person(name: String, age: Int)
开发者ID:yafengli,项目名称:finatra-freemarker-seed.g8,代码行数:43,代码来源:HomeController.scala
注:本文中的com.twitter.finatra.http.Controller类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论