本文整理汇总了Scala中play.api.mvc.AnyContent类的典型用法代码示例。如果您正苦于以下问题:Scala AnyContent类的具体用法?Scala AnyContent怎么用?Scala AnyContent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnyContent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CoinController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import forms.CoinAddForm
import models.User
import models.coin.{Person, WorkEntry}
import models.common.Pagination
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent}
import scala.concurrent.Future
class CoinController @Inject()(
val messagesApi: MessagesApi,
val env: Environment[User, CookieAuthenticator]
) extends Silhouette[User, CookieAuthenticator] {
val itemsPerPage = 9
def remove(id: Long): Action[AnyContent] = SecuredAction.async { implicit request =>
WorkEntry.remove(id)
Future.successful(Redirect(routes.CoinController.landing()))
}
}
示例2: MenuController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import com.github.nscala_time.time.Imports._
import domain.MenuRepo.menuFormat
import domain._
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, Controller}
import services.{MenuNotFound, MenuService, NoNewMenuContentFound}
class MenuController @Inject()(menuService: MenuService) extends Controller {
def menu(fechaUltimaModificacionRef: Option[String]): Action[AnyContent] = Action {
menuService.getLatestMenu(fechaUltimaModificacionRef) match {
case Right(menu: Menu) => Ok(Json.toJson(menu))
case Left(MenuNotFound()) => NotFound
case Left(NoNewMenuContentFound()) => NoContent
case _ => InternalServerError
}
}
}
示例3: ApplicationController
//设置package包名称以及导入依赖的类
package controllers
import domain.{Categoria, EstadoItemDePedido, EstadoPedido, EstadoSugerencia}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, Controller}
class ApplicationController extends Controller {
def categorias() : Action[AnyContent] = Action {
Ok(Json.arr(Categoria.values))
}
def estadosDePedido() : Action[AnyContent] = Action {
Ok(Json.arr(EstadoPedido.values))
}
def estadosDeItemDePedido() : Action[AnyContent] = Action {
Ok(Json.arr(EstadoItemDePedido.values))
}
def estadosDeSugerencia() : Action[AnyContent] = Action {
Ok(Json.arr(EstadoSugerencia.values))
}
}
示例4: Status2Controller
//设置package包名称以及导入依赖的类
package xyz.mattclifton.play.stringent.test
import play.api.mvc.{Request, AnyContent, Action, Controller}
import xyz.mattclifton.play.stringent.StringentActions
import xyz.mattclifton.play.stringent.test.helpers.FakeParsers._
import xyz.mattclifton.play.stringent.test.models.{TestResponse, TestContent}
import scala.concurrent.{ExecutionContext, Future}
class Status2Controller(implicit executionContext: ExecutionContext) extends Controller with StringentActions {
def withBodyParser = Action.stringent.withContent[TestContent, OkResult, BadRequestResult](parse.json[TestContent]){ request =>
Ok
}
def anyContent = Action.stringent.anyContent[OkResult, BadRequestResult]{ request =>
Ok
}
def block = Action.stringent[OkResult, BadRequestResult]{
Ok
}
def asyncBlock = Action.stringent.async[OkResult, BadRequestResult]{
Future(Ok)
}
def asyncAnyContent = Action.stringent.anyContentAsync[OkResult, BadRequestResult]{ request =>
Future(Ok)
}
def asyncBodyContent = Action.stringent.withContentAsync[TestContent, OkResult, BadRequestResult](parse.json[TestContent]){ request =>
Future(Ok)
}
}
示例5: Route
//设置package包名称以及导入依赖的类
package com.viajobien.busy.models.routing
import com.viajobien.busy.dsl.condition.Condition
import com.viajobien.busy.models.Persistable
import play.api.mvc.{ AnyContent, Request }
abstract class Route(val path: String, endpoint: String,
condition: Condition) extends Persistable with PathUtil {
def satisfy(request: Request[AnyContent]): Boolean = {
this.condition.eval(request)
}
def generateEndpoint(pathParameter: String): String = {
val splittedPath = this.splitPath(this.path)
val splittedPathParameter = this.splitPath(pathParameter, splittedPath.size)
val zippedPath = splittedPath zip splittedPathParameter
val wildcardsPath = zippedPath filter (z => z._1 == PATH_PART_WILDCARD || z._1 == PATH_WILDCARD)
this.splittedEndpoint(wildcardsPath)
}
private def splittedEndpoint(wildcardsPath: List[(String, String)]): String = {
def splitted(splittedEndpoint: List[String], wildcardsPath: List[(String, String)]): List[String] =
splittedEndpoint match {
case Nil => Nil
case (PATH_PART_WILDCARD | PATH_WILDCARD) :: es => wildcardsPath.head._2 :: splitted(es, wildcardsPath.tail)
case e :: es => e :: splitted(es, wildcardsPath)
}
splitted(this.splitPath(this.endpoint, dropChars = 0), wildcardsPath) mkString "/"
}
}
示例6: MainController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import scala.concurrent.ExecutionContext
import domain.Id
import domain.wordcount.Model._
import parser.WordsBodyParsers
import play.api.Configuration
import play.api.libs.json._
import play.api.mvc.{Action, AnyContent, Controller}
import services.WordCountService
import services.WordCountService._
@Singleton
class MainController @Inject()(
wordCountService: WordCountService,
val configuration: Configuration,
implicit val executionContext: ExecutionContext
) extends Controller with WordsBodyParsers {
import json.WordCountJson._
def index = Action {
Ok("")
}
def countWords: Action[Map[String, Long]] = Action.async(parseWords.wordcount) { request =>
wordCountService
.createWordCount(CreateWordCountRequest(request.body))
.map(res => Ok(Json.toJson(res.wordCount)))
}
def getWordCounts: Action[AnyContent] = Action.async { request =>
wordCountService
.findWordCounts(FindWordCountsRequest())
.map(res => Ok(Json.toJson(res.wordCounts)))
}
def getWordCount(id: String): Action[AnyContent] = Action.async { request =>
wordCountService
.findWordCount(FindWordCountRequest(Id[WordCount](id)))
.map(res =>
if (res.wordCount.isDefined)
Ok(Json.toJson(res.wordCount))
else NotFound
)
}
}
示例7: DbPopulationController
//设置package包名称以及导入依赖的类
package au.id.tmm.senatedb.api.controllers
import au.id.tmm.senatedb.api.services.DbPopulationService
import au.id.tmm.senatedb.api.services.exceptions.NoSuchElectionException
import com.google.inject.{Inject, Singleton}
import play.api.mvc.{Action, AnyContent, Controller}
import scala.concurrent.ExecutionContext
@Singleton
class DbPopulationController @Inject()(dbPopulationService: DbPopulationService)
(implicit ec: ExecutionContext) extends Controller {
def populateFor(electionId: String): Action[AnyContent] = Action.async {
dbPopulationService.beginPopulationFor(electionId)
.map(_ => Ok(s"Begun populating for $electionId"))
.recover {
case _: NoSuchElectionException => NotFound(electionId) // TODO handle this with an application level error handler
case e: DbPopulationService.Exceptions.AnotherElectionCurrentlyPopulatingException => Ok(s"Already populating ${e.election}")
}
}
def checkPopulationStatusFor(electionId: String): Action[AnyContent] = Action.async {
dbPopulationService.isElectionPopulated(electionId)
.map(electionIsPopulated => Ok(electionIsPopulated.toString))
.recover {
case _: NoSuchElectionException => NotFound(electionId) // TODO handle this with an application level error handler
}
}
}
示例8: JSONCtrl
//设置package包名称以及导入依赖的类
package controllers.io
import javax.inject.Inject
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import controllers.{ResultFormat, ViewContext}
import models.{PCMAPIUtils, User}
import org.opencompare.api.java.impl.io.KMFJSONExporter
import org.opencompare.formalizer.extractor.CellContentInterpreter
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.MessagesApi
import play.api.libs.json.Json
import play.api.mvc.{AnyContent, Request, Result}
class JSONCtrl @Inject() (
val messagesApi: MessagesApi,
val env: Environment[User, CookieAuthenticator],
val pcmAPIUtils : PCMAPIUtils) extends IOCtrl("json") {
val jsonExporter = new KMFJSONExporter()
val formalizer = new CellContentInterpreter
val outputParametersForm = Form(
mapping(
"file" -> text
)(JSONExportParameters.apply)(JSONExportParameters.unapply)
)
override def importPCMs(format: ResultFormat)(implicit request: Request[AnyContent], viewContext: ViewContext): Result = {
NotFound("JSON import is not implemented yet")
}
override def exportPCM(implicit request: Request[AnyContent]): Result = {
val parameters = outputParametersForm.bindFromRequest.get
val pcmJSON = Json.parse(parameters.pcm)
val container = pcmAPIUtils.parsePCMContainers(pcmJSON).head
formalizer.interpretCells(container.getPcm)
val json = jsonExporter.export(container)
Ok(json)
}
case class JSONExportParameters(pcm : String)
}
示例9: index
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc.{Action, Controller, AnyContent}
def index: Action[AnyContent] = Action { request =>
if (request.session.get("customer").isDefined) {
Redirect(routes.LoginController.loginUser())
} else if (request.session.get("staff").isDefined) {
Redirect(routes.LoginController.loginStaff())
} else {
Ok(views.html.index(controllers.LoginController.loginForm))
}
}
}
示例10: searchUser
//设置package包名称以及导入依赖的类
package controllers
import forms.LoginUserForm
import models.User
import play.api.mvc.{Action, AnyContent, Controller}
import play.api.data.Form
import play.api.data.Forms._
import services.{ExtrasService, ItemService, UserService}
def searchUser: Action[AnyContent] = Action {
implicit request =>
loginForm.bindFromRequest.fold(
formWithErrors => {
BadRequest(views.html.index(formWithErrors))
},
userData => {
val exists = UserService.registeredUsers.exists(_.name == userData.name)
if (exists) {
val user = UserService.registeredUsers.find {
_.name == userData.name
}.head
if (user.password == userData.password && user.active) {
if (!user.admin) {
Redirect(routes.LoginController.loginUser()) withSession("id" -> user.id.toString, "user" -> user.name, "distance" -> user.distance.toString, "customer" -> "yes")
} else {
Redirect(routes.LoginController.loginStaff()) withSession("id" -> user.id.toString, "user" -> user.name, "staff" -> "yes")
}
} else Redirect(routes.Application.index())
} else Redirect(routes.Application.index())
}
)
}
}
示例11: changeGott
//设置package包名称以及导入依赖的类
package controllers
import forms.GottForm
import models.Gott
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, AnyContent, Controller}
def changeGott: Action[AnyContent] = Action { implicit request =>
gottForm.bindFromRequest.fold(
formWithErrors => {
BadRequest(views.html.error("Fehler Gott"))
},
userData => {
val gott = new Gott(userData.gottId, userData.userId, userData.gott, userData.passiv, userData.erweckt, userData.skill, userData.skillE,
0)
gott.getGesamt()
services.GottService.changeGott(gott)
Redirect(routes.DefController.showMemberDef(userData.userId.toString))
})
}
}
示例12: Images
//设置package包名称以及导入依赖的类
package controllers
import java.io.File
import javax.inject.Inject
import com.smule.smg.SMGLogger
import play.Play
import play.api.mvc.{Action, AnyContent, Controller}
class Images @Inject() () extends Controller {
val log = SMGLogger
def at(rootPath: String, file: String): Action[AnyContent] = Action { request =>
if (file.contains(File.pathSeparator)) {
log.error("Refusing to serve files outside my root: " + file)
NotFound
} else {
val fileToServe = new File(Play.application.getFile(rootPath), file)
if (fileToServe.exists) {
Ok.sendFile(fileToServe, inline = true).withHeaders(CACHE_CONTROL -> "max-age=30")
} else {
NotFound
}
}
}
}
示例13: ServiceHealthCheck
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.{Inject, _}
import com.sharecare.lib.play.healthcheck.HealthCheckCriticality.High
import com.sharecare.lib.play.healthcheck.HealthCheckStatus.{Error, Healthy}
import com.sharecare.lib.play.healthcheck.controllers.HealthCheckController
import com.sharecare.lib.play.healthcheck.mongoDB.MongoReporterFactory
import com.sharecare.lib.play.healthcheck.{HealthCheck, HealthReporter}
import play.api.Configuration
import play.api.libs.ws.WSClient
import play.api.mvc.{Action, AnyContent, Controller}
import scala.concurrent.Await
import scala.concurrent.duration._
@Singleton
class ServiceHealthCheck @Inject() (mongoReporterFactory: MongoReporterFactory,
careTeamReporter: CareTeamServiceReporter,
config: Configuration,
healthCheckController: HealthCheckController) extends Controller {
lazy val mainCollection = "collections.main"
lazy val mongoReporters = mongoReporterFactory.report(mainCollection)
val check: (Option[Boolean], Option[Boolean]) => Action[AnyContent] = healthCheckController.check (
healthChecks = mongoReporters ++ Set(careTeamReporter),
parentLabel = config.getString("application.name" ).getOrElse("<Specify name in conf>" ),
version = config.getString("application.version").getOrElse("<Specify version in conf>")
)
}
class CareTeamServiceReporter @Inject() (config: Configuration, ws: WSClient) extends HealthReporter {
val isInternal: Boolean = false
def report: HealthCheck = {
val careTeam = config.getConfig("application.healthchecks.careTeam")
val url = careTeam.flatMap(c => c.getString("url"))
val timeout = careTeam.flatMap(c => c.getInt("timeoutSeconds")).getOrElse(10)
url match {
case Some(u) => val response = Await.result(ws.url(u).get(), timeout.seconds)
response.status match {
case 200 => HealthCheck("CareTeamService", Healthy, High, "Ok")
case _ => HealthCheck("CareTeamService", Error, High, response.body)
}
case None => HealthCheck("CareTeamService", Error, High, "careteam url has not been defined")
}
}
}
示例14: MispCtrl
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import models.InvalidRequestError
import play.api.Logger
import play.api.libs.json.{ JsObject, JsValue }
import play.api.mvc.{ Action, AnyContent, Controller }
import services.MispSrv
import scala.concurrent.ExecutionContext
class MispCtrl @Inject() (mispSrv: MispSrv, implicit val ec: ExecutionContext) extends Controller {
private[MispCtrl] lazy val logger = Logger(getClass)
def modules: Action[AnyContent] = Action { _ ?
Ok(mispSrv.moduleList)
}
def query: Action[JsValue] = Action.async(parse.json) { request ?
val module = (request.body \ "module").asOpt[String].getOrElse(throw InvalidRequestError("Module parameter is not present in request"))
val (mispType, dataJson) = request.body.as[JsObject].fields
.collectFirst {
case kv @ (k, _) if k != "module" ? kv
}
.getOrElse(throw InvalidRequestError("Request doesn't contain data to analyze"))
val data = dataJson.asOpt[String].getOrElse(throw InvalidRequestError("Data has invalid type (expected string)"))
mispSrv.query(module, mispType, data)
.map(Ok(_))
}
}
示例15: get
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.{ Inject, Singleton }
import play.api.Environment
import play.api.http.HttpErrorHandler
import play.api.mvc.{ Action, AnyContent }
trait AssetCtrl {
def get(file: String): Action[AnyContent]
}
@Singleton
class AssetCtrlProd @Inject() (errorHandler: HttpErrorHandler) extends Assets(errorHandler) with AssetCtrl {
def get(file: String): Action[AnyContent] = at("/ui", file)
}
@Singleton
class AssetCtrlDev @Inject() (environment: Environment) extends ExternalAssets(environment) with AssetCtrl {
def get(file: String): Action[AnyContent] = {
if (file.startsWith("bower_components/")) {
at("ui", file)
}
else {
at("ui/app", file)
}
}
}