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

Scala Router类代码示例

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

本文整理汇总了Scala中play.api.routing.Router的典型用法代码示例。如果您正苦于以下问题:Scala Router类的具体用法?Scala Router怎么用?Scala Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Router类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: ErrorHandler

//设置package包名称以及导入依赖的类
package conf.util

import javax.inject._

import play.api._
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router

import scala.concurrent._


class ErrorHandler @Inject()(
         env: Environment,
         config: Configuration,
         sourceMapper: OptionalSourceMapper,
         router: Provider[Router])
  extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {

  override def onProdServerError(request: RequestHeader, exception: UsefulException) = {
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }

  override protected def onNotFound(request: RequestHeader, message: String): Future[Result] = {
    Future.successful(
      InternalServerError("A server error occurred: " + message)
    )
  }

  override def onForbidden(request: RequestHeader, message: String) = {
    Future.successful(
      Forbidden("You're not allowed to access this resource.")
    )
  }

  override def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    Future.successful(
      Status(statusCode)("A client error occurred: " + message)
    )
  }

  override def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }

  override protected def onBadRequest(request: RequestHeader, message: String): Future[Result] = {
    Future.successful(
      InternalServerError("A server error occurred: " + message)
    )
  }




} 
开发者ID:Masebeni,项目名称:hwork,代码行数:61,代码来源:ErrorHandler.scala


示例2: ErrorHandler

//设置package包名称以及导入依赖的类
package web

import play.api.http.DefaultHttpErrorHandler
import play.api._
import play.api.mvc._
import play.api.mvc.Results._
import play.api.i18n.{ I18nSupport, MessagesApi, Messages }
import play.api.routing.Router
import scala.concurrent._
import javax.inject._

class ErrorHandler @Inject() (
    env: Environment,
    config: Configuration,
    sourceMapper: OptionalSourceMapper,
    router: Provider[Router],
    val messagesApi: MessagesApi) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with I18nSupport {

  // 404 - page not found error
  override def onNotFound(request: RequestHeader, message: String): Future[Result] = Future.successful {
    NotFound(env.mode match {
      case Mode.Prod => views.html.web.errors.notFound(request)(request2Messages(request))
      case _ => views.html.defaultpages.devNotFound(request.method, request.uri, Some(router.get))
    })
  }

  // 500 - internal server error
  override def onProdServerError(request: RequestHeader, exception: UsefulException) = Future.successful {
    InternalServerError(views.html.web.errors.error(request, exception)(request2Messages(request)))
  }
} 
开发者ID:pawank,项目名称:play-silhouette-mongodb-multi-project-sbt,代码行数:32,代码来源:ErrorHandler.scala


示例3: RequestHandler

//设置package包名称以及导入依赖的类
import javax.inject.Inject

import play.api.http._
import play.api.mvc._
import play.api.mvc.request.{RequestFactory, RequestTarget}
import play.api.routing.Router


class RequestHandler @Inject()(router: Router,
                               errorHandler: HttpErrorHandler,
                               configuration: HttpConfiguration,
                               filters: HttpFilters)
    extends DefaultHttpRequestHandler(router,
                                      errorHandler,
                                      configuration,
                                      filters) {

  override def handlerForRequest(request: RequestHeader): (RequestHeader, Handler) = {
    super.handlerForRequest {
      // ensures that REST API does not need a trailing "/"
      if (isREST(request)) {
        addTrailingSlash(request)
      } else {
        request
      }
    }
  }

  private def isREST(request: RequestHeader) = {
    request.uri match {
      case uri: String if uri.contains("post") => true
      case _ => false
    }
  }

  private def addTrailingSlash(origReq: RequestHeader): RequestHeader = {
    if (!origReq.path.endsWith("/")) {
      val path = origReq.path + "/"
      if (origReq.rawQueryString.isEmpty) {
        origReq.withTarget(
          RequestTarget(path = path, uriString = path, queryString = Map())
        )
      } else {
        origReq.withTarget(
          RequestTarget(path = path,
                        uriString = origReq.uri,
                        queryString = origReq.queryString)
        )
      }
    } else {
      origReq
    }
  }
} 
开发者ID:yoo-haemin,项目名称:hufs-classroom,代码行数:55,代码来源:RequestHandler.scala


示例4: WebApp

//设置package包名称以及导入依赖的类
import org.culture.OrgId
import play.api.ApplicationLoader.Context
import play.api._
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router
import play.api.routing.sird._
import wiring.Components

class WebApp extends ApplicationLoader {

  private val components = new Components
  import components._

  def load(context: Context) =
    new BuiltInComponentsFromContext(context) {

      val router = Router.from {

        case GET(p"/badge/${long(orgId)}.svg") =>
          Action.async {
            badgeBuilder.get(OrgId(orgId)).map { badge =>
              Ok.chunked(badge.body).as("image/svg+xml;charset=utf-8")
            }
          }

      }
    }.application

} 
开发者ID:lloydmeta,项目名称:reculture-shields,代码行数:31,代码来源:WebApp.scala


示例5: AppLoader

//设置package包名称以及导入依赖的类
import models.{AuthorizeStoreCache, PendingContentStoreCache}
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.api._
import play.filters.gzip.GzipFilter
import router.Routes

class AppLoader extends ApplicationLoader {
  override def load(context: Context): Application = {
    LoggerConfigurator(context.environment.classLoader)
      .foreach(_.configure(context.environment))
    new AppComponents(context).application
  }
}

class AppComponents(context: Context)
    extends BuiltInComponentsFromContext(context)
    with EhCacheComponents {

  implicit val executionContext =
    play.api.libs.concurrent.Execution.Implicits.defaultContext
  implicit lazy val authorizeStoreCache = AuthorizeStoreCache(
    cacheApi("authorizeStore"))
  implicit lazy val pendingConsentStoreCache = PendingContentStoreCache(
    cacheApi("pendingConsentStore"))
  implicit val config = configuration.underlying

  lazy val applicationController = new controllers.Application
  lazy val assets                = new controllers.Assets(httpErrorHandler)

  // Routes is a generated class
  override def router: Router =
    new Routes(httpErrorHandler, applicationController, assets)

  val gzipFilter = new GzipFilter(shouldGzip = (request, response) => {
    val contentType = response.header.headers.get("Content-Type")
    contentType.exists(_.startsWith("text/html")) ||
    request.path.endsWith("jsroutes.js")
  })

  override lazy val httpFilters: Seq[EssentialFilter] = Seq(gzipFilter)
} 
开发者ID:zalando-incubator,项目名称:OAuth2-mock-play,代码行数:45,代码来源:AppLoader.scala


示例6: AppLoader

//设置package包名称以及导入依赖的类
import java.io.Closeable
import javax.sql.DataSource

import controllers.UsersController
import io.getquill._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.db.evolutions.Evolutions
import play.api.db.{DBComponents, HikariCPComponents}
import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector}
import play.api.routing.Router
import play.api.routing.sird._
import models.{Users}

class AppLoader extends ApplicationLoader {
  override def load(context: Context): Application = new BuiltInComponentsFromContext(context) with DBComponents with HikariCPComponents {

    lazy val db = new H2JdbcContext[SnakeCase](dbApi.database("default").dataSource.asInstanceOf[DataSource with Closeable])


    lazy val users = new Users(db)
    lazy val usersController = new UsersController(users)

    val router = Router.from {
      case GET(p"/users/${long(id)}")    => usersController.get(id)
      case POST(p"/users")               => usersController.create
      case DELETE(p"/users/${long(id)}") => usersController.delete(id)
      case PUT(p"/users/${long(id)}")    => usersController.update(id)
    }

    override lazy val injector: Injector =
      new SimpleInjector(NewInstanceInjector) + users + router + cookieSigner + csrfTokenSigner + httpConfiguration + tempFileCreator + global

    Evolutions.applyEvolutions(dbApi.database("default"))

  }.application
} 
开发者ID:getquill,项目名称:play-quill-jdbc,代码行数:38,代码来源:AppLoader.scala


示例7: ErrorHandler

//设置package包名称以及导入依赖的类
package utils

import javax.inject.{Inject, Provider}

import com.mohiva.play.silhouette.api.actions.SecuredErrorHandler
import play.api.http.DefaultHttpErrorHandler
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.mvc.Results._
import play.api.mvc.{RequestHeader, Result}
import play.api.routing.Router
import play.api.{Configuration, OptionalSourceMapper}

import scala.concurrent.Future
import controllers.{WebJarAssets, routes}

class ErrorHandler @Inject() (
                               val messagesApi: MessagesApi,
                               env: play.api.Environment,
                               config: Configuration,
                               sourceMapper: OptionalSourceMapper,
                               router: javax.inject.Provider[Router],
                               p: Provider[WebJarAssets])
  extends DefaultHttpErrorHandler(env, config, sourceMapper, router)
    with SecuredErrorHandler with I18nSupport {

  // https://www.playframework.com/documentation/2.5.x/Migration25#Handling-legacy-components
  implicit lazy val webJarAssets = p.get()

  override def onNotAuthenticated(implicit request: RequestHeader): Future[Result] =
    Future.successful(Redirect(routes.Auth.signIn()))

  override def onNotAuthorized(implicit request: RequestHeader): Future[Result] =
    Future.successful(Redirect(routes.Auth.signIn()).flashing("error" -> Messages("error.accessDenied")))

  override def onNotFound(request: RequestHeader, message: String): Future[Result] =
    Future.successful(Ok(views.html.errors.notFound(request)))

  override def onServerError(request:RequestHeader, exception:Throwable):Future[Result] =
    Future.successful(Ok(views.html.errors.serverError(request, exception)))
} 
开发者ID:tm-sukehiro,项目名称:play-hands-on,代码行数:41,代码来源:ErrorHandler.scala


示例8: AppLoader

//设置package包名称以及导入依赖的类
package org.andrewconner.spot

import _root_.controllers.Assets
import com.softwaremill.macwire._
import org.andrewconner.spot.core.time.Clock
import org.andrewconner.spot.modules._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSClient
import play.api.routing.Router

import scala.concurrent.ExecutionContext

class AppLoader extends ApplicationLoader {
  def load(context: Context) = {
    (new BuiltInComponentsFromContext(context) with AppComponents).application
  }
}

trait AppComponents
    extends BuiltInComponents
    with PlayAppModule
    with DatabaseModule // Database injection
    with DaoModule
    with ControllerModule // Application controllers
    with CmdrModule
    with CredentialsModule {

  implicit val ec: ExecutionContext = play.api.libs.concurrent.Execution.defaultContext // scala.concurrent.ExecutionContext.Implicits.global
  implicit val clock: Clock = new Clock()

  lazy val assets: Assets = wire[Assets]
  val prefix: String = "/"
  lazy val router: Router = wire[_root_.router.Routes].withPrefix(prefix)

  implicit val wsClient: WSClient = AhcWSClient()
  appShutdown.onStopAsync(wsClient.close())

} 
开发者ID:andrewconner,项目名称:spotsy,代码行数:41,代码来源:AppLoader.scala


示例9: MyApplicationLoader

//设置package包名称以及导入依赖的类
package my.samples.core

import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.{ LazyLogging, StrictLogging }
import controllers.Assets
import play.api.{ Application, BuiltInComponentsFromContext, Configuration, _ }
import play.api.libs.ws.ahc.AhcWSComponents
import my.samples.controllers.MyApplicationController
import play.api.ApplicationLoader.Context
import play.api.routing.Router
import router.Routes
import scala.concurrent.Future

// compile time DI for loading the play application
final class MyApplicationLoader extends ApplicationLoader with LazyLogging {

  override def load(context: Context): Application = {
    val configuration = Configuration(ConfigFactory.load())

    val newContext = context.copy(initialConfiguration = configuration)
    LoggerConfigurator(newContext.environment.classLoader)
      .foreach(_.configure(newContext.environment))

    new MyApp(newContext).application
  }
}
class MyApp(context: Context)
    extends BuiltInComponentsFromContext(context) with AhcWSComponents with StrictLogging {

  implicit val s = monix.execution.Scheduler.Implicits.global

  def stop(bindings: AppBindings) = {
    logger.info("stopping application")
    bindings.globalChannel.publishChannel.onComplete()
  }

  def start = {
    logger.info("starting application")
    AppBindings(actorSystem, materializer)
  }

  // 1. create the dependencies that will be injected
  lazy val appBindings = start

  // 2. inject the dependencies into the controllers
  lazy val applicationController = new MyApplicationController(appBindings)
  lazy val assets = new Assets(httpErrorHandler)
  override def router: Router = new Routes(
    httpErrorHandler, applicationController, assets
  )

  // 3. add the shutdown hook to properly dispose all connections
  applicationLifecycle.addStopHook { () => Future(stop(appBindings)) }
} 
开发者ID:joesan,项目名称:monix-samples,代码行数:55,代码来源:MyApplicationLoader.scala


示例10: RequestHandler

//设置package包名称以及导入依赖的类
import javax.inject.Inject

import play.api.http._
import play.api.mvc._
import play.api.routing.Router


class RequestHandler @Inject()(router: Router,
                               errorHandler: HttpErrorHandler,
                               configuration: HttpConfiguration,
                               filters: HttpFilters)
    extends DefaultHttpRequestHandler(router,
                                      errorHandler,
                                      configuration,
                                      filters) {

  override def handlerForRequest(request: RequestHeader): (RequestHeader, Handler) = {
    super.handlerForRequest {
      // ensures that REST API does not need a trailing "/"
      if (isREST(request)) {
        addTrailingSlash(request)
      } else {
        request
      }
    }
  }

  private def isREST(request: RequestHeader) = {
    request.uri match {
      case uri: String if uri.contains("post") => true
      case uri: String if uri.contains("news") => true
      case _ => false
    }
  }

  private def addTrailingSlash(origReq: RequestHeader): RequestHeader = {
    if (!origReq.path.endsWith("/")) {
      val path = origReq.path + "/"
      if (origReq.rawQueryString.isEmpty) {
        origReq.copy(path = path, uri = path)
      } else {
        origReq.copy(path = path, uri = path + s"?${origReq.rawQueryString}")
      }
    } else {
      origReq
    }
  }
} 
开发者ID:kapit4n,项目名称:play-news-api,代码行数:49,代码来源:RequestHandler.scala


示例11: AppLoader

//设置package包名称以及导入依赖的类
import java.io.Closeable
import javax.sql.DataSource

import controllers.MainController
import io.getquill._
import models.Services
import unus.db._
import unus.helpers.Conf
import unus.model.FeatureBuilder
import unus.stage.{BlockerCacher, DatabaseBackup, PatientCacher, PatientDatabase}
import org.flywaydb.play.FlywayPlayComponents
import play.api.ApplicationLoader.Context
import play.api._
import play.api.db.{DBComponents, HikariCPComponents}
import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector}
import play.api.routing.Router
import play.filters.csrf._
import router.Routes

class AppLoader extends ApplicationLoader {
  override def load(context: Context): Application = new BuiltInComponentsFromContext(context)
    with DBComponents with HikariCPComponents  with CSRFComponents
    with FlywayPlayComponents with play.filters.HttpFiltersComponents with _root_.controllers.AssetsComponents {

    lazy val db = new PostgresJdbcContext[PostgresEscape](dbApi.database("default").dataSource.asInstanceOf[DataSource with Closeable])

    lazy val services = new Services(db)
    lazy val patientCacher = new PatientCacher
    lazy val repo = new Repository(db)
    lazy val blockerCachers = Conf.blockers.map(new BlockerCacher(repo, patientCacher.value, _))
    lazy val features =  Conf.features
    lazy val controller = new MainController(services, repo, patientCacher, blockerCachers, features)(controllerComponents)

    lazy val router: Router = new Routes(httpErrorHandler, controller)

    

    override lazy val injector: Injector =
      new SimpleInjector(NewInstanceInjector) + cookieSigner + csrfTokenSigner + httpConfiguration + tempFileCreator + router

    override lazy val httpFilters = Seq(csrfFilter)

    flywayPlayInitializer

    new PatientDatabase(repo, patientCacher).run()

    if(services.getLabelCount == 0) {
      new DatabaseBackup[Label]("Label").load()
    }

    if(services.getBlockedRowCount == 0) {
      new DatabaseBackup[BlockedRow]("BlockedRow").load()
    }

  }.application
} 
开发者ID:mindfulmachines,项目名称:unus,代码行数:57,代码来源:AppLoader.scala


示例12: ErrorHandler

//设置package包名称以及导入依赖的类
import play.api.http.DefaultHttpErrorHandler
import play.api._
import play.api.mvc._
import play.api.mvc.Results._
import play.api.routing.Router
import scala.concurrent.Future
import javax.inject._

class ErrorHandler @Inject() (
    env: Environment,
    config: Configuration,
    sourceMapper: OptionalSourceMapper,
    router: Provider[Router],
    webErrorHandler: web.ErrorHandler,
    adminErrorHandler: admin.ErrorHandler) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {

  
  private def getSubdomain(request: RequestHeader) = request.domain.replaceFirst("[\\.]?[^\\.]+[\\.][^\\.]+$", "")

  // 404 - page not found error
  override def onNotFound(request: RequestHeader, message: String): Future[Result] = getSubdomain(request) match {
    case "admin" => adminErrorHandler.onNotFound(request, message)
    case _ => webErrorHandler.onNotFound(request, message)
  }

  // 500 - internal server error
  override def onProdServerError(request: RequestHeader, exception: UsefulException) = getSubdomain(request) match {
    case "admin" => adminErrorHandler.onProdServerError(request, exception)
    case _ => webErrorHandler.onProdServerError(request, exception)
  }

} 
开发者ID:pawank,项目名称:play-silhouette-mongodb-multi-project-sbt,代码行数:33,代码来源:ErrorHandler.scala


示例13: ErrorHandler

//设置package包名称以及导入依赖的类
package admin

import play.api.http.DefaultHttpErrorHandler
import play.api._
import play.api.mvc._
import play.api.mvc.Results._
import play.api.i18n.{ I18nSupport, MessagesApi, Messages }
import play.api.routing.Router
import scala.concurrent._
import javax.inject._

class ErrorHandler @Inject() (
    env: Environment,
    config: Configuration,
    sourceMapper: OptionalSourceMapper,
    router: Provider[Router],
    val messagesApi: MessagesApi) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with I18nSupport {

  // 404 - page not found error
  override def onNotFound(request: RequestHeader, message: String): Future[Result] = Future.successful {
    NotFound(env.mode match {
      case Mode.Prod => views.html.admin.errors.notFound(request)(request2Messages(request))
      case _ => views.html.defaultpages.devNotFound(request.method, request.uri, Some(router.get))
    })
  }

  // 500 - internal server error
  override def onProdServerError(request: RequestHeader, exception: UsefulException) = Future.successful {
    InternalServerError(views.html.admin.errors.error(request, exception)(request2Messages(request)))
  }
} 
开发者ID:pawank,项目名称:play-silhouette-mongodb-multi-project-sbt,代码行数:32,代码来源:ErrorHandler.scala


示例14: ErrorHandler

//设置package包名称以及导入依赖的类
import javax.inject._

import play.api._
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router

import scala.concurrent.Future

@Singleton
class ErrorHandler @Inject()(
  env: Environment,
  config: Configuration,
  sourceMapper: OptionalSourceMapper,
  router: Provider[Router]
) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {

  override def onProdServerError(request: RequestHeader, exception: UsefulException): Future[Result] = Future.successful {
    InternalServerError("A server error occurred: " + exception.getMessage)
  }

  override def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result] = env.mode match {
    case Mode.Prod => Future.successful(Results.Status(statusCode)(message))
    case _ => super.onClientError(request, statusCode, message)
  }
} 
开发者ID:stonexx,项目名称:utils,代码行数:28,代码来源:ErrorHandler.scala


示例15: GriffinApiLoader

//设置package包名称以及导入依赖的类
import com.softwaremill.macwire._
import controllers.Assets
import filters.LoggingFilter
import play.api.ApplicationLoader.Context
import play.api._
import play.api.i18n._
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.filters.cors.{CORSConfig, CORSFilter}
import router.Routes
import services.ServicesModule



class GriffinApiLoader extends ApplicationLoader {
  def load(context: Context): Application = new GriffinComponents(context).application
}


class GriffinComponents(context: Context)
  extends BuiltInComponentsFromContext(context)
    with ServicesModule
    with I18nComponents
    with AhcWSComponents
{
  // set up logger
  LoggerConfigurator(context.environment.classLoader).foreach {
    _.configure(context.environment)
  }

  lazy val assets: Assets = wire[Assets]
  lazy val router: Router = {
    // add the prefix string in local scope for the Routes constructor
    val prefix: String = "/"
    wire[Routes]
  }

  lazy val corsFilter = CORSFilter(CORSConfig.fromConfiguration(configuration))

  lazy val loggingFilter = new LoggingFilter
  lazy val filters = wire[Filters]

  override lazy val httpFilters: Seq[EssentialFilter] =
    Seq(loggingFilter,corsFilter)

} 
开发者ID:yarshad,项目名称:griffin-api,代码行数:48,代码来源:GriffinApiLoader.scala


示例16: AcceptanceTest

//设置package包名称以及导入依赖的类
package com.primedesem.home

import org.scalatest._
import org.scalatestplus.play._

import play.api.test._
//import play.api.test.Helpers.{GET => GET_REQUEST, _}
//import play.api.test.Helpers.{POST => POST_REQUEST, _}
import play.api.inject.guice.GuiceApplicationBuilder

import controllers._
import play.api.routing.Router

import play.api.routing.sird._
import play.api.routing._
import play.api.mvc._
import play.api.mvc.Results._

import scala.concurrent.ExecutionContext.Implicits

class AcceptanceTest extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite with HtmlUnitFactory{
  
  
  implicit val ec = Implicits.global
  
  val homeController = new HomeController()
  
  implicit override lazy val app = 
    new GuiceApplicationBuilder()
      .router(Router.from{
        case GET(p"/") => homeController.index
//        case GET(p"/about") => homeController.about
        case GET(p"/login") => homeController.getLogin
//        case POST(p"/login") => homeController.postLogin
        case GET(p"/register") => homeController.getRegister
        //case POST(p"/register") => homeController.postRegister
        case GET(p"/assets/*") => Action(Ok("assets"))
      })
      .build()
      
  
  "Person visits site" must {
    
    val url = s"http://localhost:$port"
    
    "visit home and see Home in the title" in {
      go to url
      pageTitle mustBe "Home"
      click on find(name("register")).value
      eventually { pageTitle mustBe "Register"}
    }
    
    "visit home and be able to go to login page" in {
      go to url
      click on find(name("login")).value
      eventually {pageTitle mustBe "Login"}
    }
  }
      
      
} 
开发者ID:eric416283,项目名称:primdesem-demo-home-front-end,代码行数:62,代码来源:AcceptanceTest.scala


示例17: ErrorHandler

//设置package包名称以及导入依赖的类
import javax.inject._

import play.api._
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router

import scala.concurrent._

@Singleton
class ErrorHandler @Inject()(
    env: Environment,
    config: Configuration,
    sourceMapper: OptionalSourceMapper,
    router: Provider[Router]
) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {

  override def onProdServerError(request: RequestHeader, exception: UsefulException) =
    Future.successful(InternalServerError("A server error occurred: " + exception.getMessage))

  override def onForbidden(request: RequestHeader, message: String) =
    Future.successful(Forbidden("You're not allowed to access this resource."))

  override protected def onNotFound(request: RequestHeader, message: String) =
    Future.successful(NotFound("Resource not found"))

  override protected def onBadRequest(request: RequestHeader, message: String) =
    Future.successful(BadRequest("Bad request"))

} 
开发者ID:scalafiddle,项目名称:scalafiddle-editor,代码行数:32,代码来源:ErrorHandler.scala


示例18: AppApplicationLoader

//设置package包名称以及导入依赖的类
import com.softwaremill.macwire._
import controllers._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.i18n._
import play.api.routing.Router
import router.Routes
import modules._

import scala.concurrent.ExecutionContext


class AppApplicationLoader extends ApplicationLoader {
  def load(context: Context): Application = {
    (new BuiltInComponentsFromContext(context) with AppComponents).application
  }
}

trait AppComponents extends BuiltInComponents
    with I18nComponents
    with DatabaseModule
    with ControllerModule
    with DaoModule
{

  implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
  lazy val assets: Assets = wire[Assets]
  lazy val router: Router = {
    lazy val prefix = "/"
    wire[Routes]
  }

  lazy val mainController = wire[MainController]

//  def userDao: UserDao
} 
开发者ID:greven77,项目名称:PlaySlickTest,代码行数:37,代码来源:AppApplicationLoader.scala


示例19: ErrorHandler

//设置package包名称以及导入依赖的类
import javax.inject._

import play.api.http.DefaultHttpErrorHandler
import play.api._
import play.api.libs.json.JsString
import play.api.mvc._
import play.api.mvc.Results._
import play.api.routing.Router
import services.ApiSecurity

import scala.concurrent._

@Singleton
class ErrorHandler @Inject() (
                               env: Environment,
                               config: Configuration,
                               sourceMapper: OptionalSourceMapper,
                               router: Provider[Router]
                             ) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with ApiSecurity {

  override def onBadRequest(request: RequestHeader, message: String): Future[Result] = {
    Future.successful(
      JsonAnswer(400,JsString("Bad Request Error: " + message))(request)
    )
  }

  override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
    Future.successful(
      JsonAnswer(500,JsString("Internal Server Error: " + exception.getMessage))(request)
    )
  }

  override def onNotFound(request: RequestHeader, message: String): Future[Result] = {
    Future.successful(
      JsonAnswer(404,JsString("Not Found Error: " + message))(request)
    )
  }

  override def onForbidden(request: RequestHeader, message: String) = {
    Future.successful(
      Forbidden("You're not allowed to access this resource.")
    )
  }
} 
开发者ID:kormoglaz,项目名称:TestTask,代码行数:45,代码来源:ErrorHandler.scala


示例20: ErrorHandler

//设置package包名称以及导入依赖的类
package utils

import javax.inject.Inject

import com.mohiva.play.silhouette.api.SecuredErrorHandler

import play.api.http.DefaultHttpErrorHandler
import play.api.i18n.{I18nSupport,Messages,MessagesApi}
import play.api.mvc.Results._
import play.api.mvc.{Result,RequestHeader}
import play.api.routing.Router
import play.api.{OptionalSourceMapper,Configuration}

import scala.concurrent.Future

class ErrorHandler @Inject() (
  val messagesApi: MessagesApi,
  env: play.api.Environment,
  config: Configuration,
  sourceMapper: OptionalSourceMapper,
  router: javax.inject.Provider[Router])
  extends DefaultHttpErrorHandler(env, config, sourceMapper, router)
  with SecuredErrorHandler with I18nSupport {

  override def onNotAuthenticated(request: RequestHeader, messages: Messages): Option[Future[Result]] =
    Some(Future.successful(Ok("please sign in")))

  override def onNotAuthorized(request: RequestHeader, messages: Messages): Option[Future[Result]] =
    Some(Future.successful(Ok(Messages("error.accessDenied")(messages))))

  override def onNotFound(request: RequestHeader, message: String): Future[Result] = 
    Future.successful(Ok("not found"))

  override def onServerError(request:RequestHeader, exception:Throwable):Future[Result] = 
    Future.successful(Ok("server error"))
} 
开发者ID:k19862217,项目名称:book-shoes-api,代码行数:37,代码来源:ErrorHandler.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Results类代码示例发布时间:2022-05-23
下一篇:
Scala HashMap类代码示例发布时间: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