本文整理汇总了Scala中javax.ws.rs.core.Context类的典型用法代码示例。如果您正苦于以下问题:Scala Context类的具体用法?Scala Context怎么用?Scala Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SystemResource
//设置package包名称以及导入依赖的类
package mesosphere.marathon.api
import java.io.StringWriter
import java.util.concurrent.TimeUnit
import javax.servlet.http.HttpServletRequest
import javax.ws.rs._
import javax.ws.rs.core.{ Context, MediaType, Response }
import com.codahale.metrics.{ MetricFilter, MetricRegistry }
import com.codahale.metrics.annotation.Timed
import com.codahale.metrics.json.MetricsModule
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.inject.Inject
import mesosphere.marathon.MarathonConf
import mesosphere.marathon.io.IO
import mesosphere.marathon.plugin.auth.AuthorizedResource.SystemConfig
import mesosphere.marathon.plugin.auth.{ Authenticator, Authorizer, ViewResource }
@Path("")
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
class SystemResource @Inject() (metrics: MetricRegistry, val config: MarathonConf)(implicit
val authenticator: Authenticator,
val authorizer: Authorizer) extends RestResource with AuthResource {
private[this] lazy val mapper = new ObjectMapper().registerModule(
new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false, MetricFilter.ALL)
)
@GET
@Path("ping")
@Timed
def ping(@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
withAuthorization(ViewResource, SystemConfig){
ok("pong")
}
}
@GET
@Path("metrics")
@Timed
def metrics(@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
withAuthorization(ViewResource, SystemConfig){
IO.using(new StringWriter()) { writer =>
mapper.writer().writeValue(writer, metrics)
ok(writer.toString)
}
}
}
}
示例2: QueueResource
//设置package包名称以及导入依赖的类
package mesosphere.marathon.api.v2
import javax.inject.Inject
import javax.servlet.http.HttpServletRequest
import javax.ws.rs._
import javax.ws.rs.core.{ Context, MediaType, Response }
import com.codahale.metrics.annotation.Timed
import mesosphere.marathon.MarathonConf
import mesosphere.marathon.api.{ AuthResource, MarathonMediaType }
import mesosphere.marathon.core.base.Clock
import mesosphere.marathon.core.launchqueue.LaunchQueue
import mesosphere.marathon.plugin.auth.{ Authenticator, Authorizer, UpdateRunSpec, ViewRunSpec }
import mesosphere.marathon.state.PathId._
import mesosphere.marathon.raml.Raml
@Path("v2/queue")
@Consumes(Array(MediaType.APPLICATION_JSON))
class QueueResource @Inject() (
clock: Clock,
launchQueue: LaunchQueue,
val authenticator: Authenticator,
val authorizer: Authorizer,
val config: MarathonConf) extends AuthResource {
@GET
@Timed
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
def index(@Context req: HttpServletRequest, @QueryParam("embed") embed: java.util.Set[String]): Response = authenticated(req) { implicit identity =>
val embedLastUnusedOffers = embed.contains(QueueResource.EmbedLastUnusedOffers)
val infos = launchQueue.listWithStatistics.filter(t => t.inProgress && isAuthorized(ViewRunSpec, t.runSpec))
ok(Raml.toRaml((infos, embedLastUnusedOffers, clock)))
}
@DELETE
@Path("""{appId:.+}/delay""")
def resetDelay(
@PathParam("appId") id: String,
@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
val appId = id.toRootPath
val maybeApp = launchQueue.list.find(_.runSpec.id == appId).map(_.runSpec)
withAuthorization(UpdateRunSpec, maybeApp, notFound(s"Application $appId not found in tasks queue.")) { app =>
launchQueue.resetDelay(app)
noContent
}
}
}
object QueueResource {
val EmbedLastUnusedOffers = "lastUnusedOffers"
}
示例3: LeaderResource
//设置package包名称以及导入依赖的类
package mesosphere.marathon.api.v2
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.{ Context, Response }
import javax.ws.rs.{ DELETE, GET, Path, Produces }
import com.google.inject.Inject
import mesosphere.chaos.http.HttpConf
import mesosphere.marathon.MarathonConf
import mesosphere.marathon.api.{ AuthResource, MarathonMediaType, RestResource }
import mesosphere.marathon.core.election.ElectionService
import mesosphere.marathon.plugin.auth._
@Path("v2/leader")
class LeaderResource @Inject() (
electionService: ElectionService,
val config: MarathonConf with HttpConf,
val authenticator: Authenticator,
val authorizer: Authorizer)
extends RestResource with AuthResource {
@GET
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
def index(@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
withAuthorization(ViewResource, AuthorizedResource.Leader) {
electionService.leaderHostPort match {
case None => notFound("There is no leader")
case Some(leader) =>
ok(jsonObjString("leader" -> leader))
}
}
}
@DELETE
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
def delete(@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
withAuthorization(UpdateResource, AuthorizedResource.Leader) {
if (electionService.isLeader) {
electionService.abdicateLeadership()
ok(jsonObjString("message" -> "Leadership abdicated"))
} else {
notFound("There is no leader")
}
}
}
}
示例4: DeploymentsResource
//设置package包名称以及导入依赖的类
package mesosphere.marathon.api.v2
import javax.inject.Inject
import javax.servlet.http.HttpServletRequest
import javax.ws.rs._
import javax.ws.rs.core.Response.Status._
import javax.ws.rs.core.{ Context, MediaType, Response }
import mesosphere.marathon.api.v2.json.Formats._
import mesosphere.marathon.api.{ AuthResource, MarathonMediaType }
import mesosphere.marathon.core.group.GroupManager
import mesosphere.marathon.plugin.auth._
import mesosphere.marathon.{ MarathonConf, MarathonSchedulerService }
import mesosphere.util.Logging
@Path("v2/deployments")
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
class DeploymentsResource @Inject() (
service: MarathonSchedulerService,
groupManager: GroupManager,
val authenticator: Authenticator,
val authorizer: Authorizer,
val config: MarathonConf)
extends AuthResource
with Logging {
@GET
def running(@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
val infos = result(service.listRunningDeployments())
.filter(_.plan.affectedRunSpecs.exists(isAuthorized(ViewRunSpec, _)))
ok(infos)
}
@DELETE
@Path("{id}")
def cancel(
@PathParam("id") id: String,
@DefaultValue("false")@QueryParam("force") force: Boolean,
@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
val plan = result(service.listRunningDeployments()).find(_.plan.id == id).map(_.plan)
plan.fold(notFound(s"DeploymentPlan $id does not exist")) { deployment =>
deployment.affectedRunSpecs.foreach(checkAuthorization(UpdateRunSpec, _))
if (force) {
// do not create a new deployment to return to the previous state
log.info(s"Canceling deployment [$id]")
service.cancelDeployment(id)
status(ACCEPTED) // 202: Accepted
} else {
// create a new deployment to return to the previous state
deploymentResult(result(groupManager.updateRoot(
deployment.revert,
force = true
)))
}
}
}
}
示例5: AppVersionsResource
//设置package包名称以及导入依赖的类
package mesosphere.marathon.api.v2
import javax.servlet.http.HttpServletRequest
import javax.ws.rs._
import javax.ws.rs.core.{ Context, MediaType, Response }
import com.codahale.metrics.annotation.Timed
import mesosphere.marathon.api.v2.json.Formats._
import mesosphere.marathon.api.{ AuthResource, MarathonMediaType }
import mesosphere.marathon.core.group.GroupManager
import mesosphere.marathon.plugin.auth.{ Authenticator, Authorizer, ViewRunSpec }
import mesosphere.marathon.state.PathId._
import mesosphere.marathon.state.Timestamp
import mesosphere.marathon.{ MarathonConf, MarathonSchedulerService }
import org.slf4j.LoggerFactory
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
@Consumes(Array(MediaType.APPLICATION_JSON))
class AppVersionsResource(
service: MarathonSchedulerService,
groupManager: GroupManager,
val authenticator: Authenticator,
val authorizer: Authorizer,
val config: MarathonConf) extends AuthResource {
val log = LoggerFactory.getLogger(getClass.getName)
@GET
@Timed
def index(
@PathParam("appId") appId: String,
@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
val id = appId.toRootPath
withAuthorization(ViewRunSpec, result(groupManager.app(id)), unknownApp(id)) { _ =>
ok(jsonObjString("versions" -> service.listAppVersions(id)))
}
}
@GET
@Timed
@Path("{version}")
def show(
@PathParam("appId") appId: String,
@PathParam("version") version: String,
@Context req: HttpServletRequest): Response = authenticated(req) { implicit identity =>
val id = appId.toRootPath
val timestamp = Timestamp(version)
withAuthorization(ViewRunSpec, service.getApp(id, timestamp), unknownApp(id, Some(timestamp))) { app =>
ok(jsonString(app))
}
}
}
示例6: Customers
//设置package包名称以及导入依赖的类
package com.github.fcristovao.resources
import java.time.OffsetDateTime
import javax.ws.rs.core.{Context, UriInfo}
import javax.ws.rs._
import com.codahale.metrics.annotation.Timed
import com.github.fcristovao.api.JsonCustomerV1
import com.github.fcristovao.dao.CustomerDao
import com.github.fcristovao.domain.{Customer, CustomerId}
@Path("/customers")
class Customers(dao: CustomerDao, customerName: String) {
@GET
@Path("/{id}")
@Produces(Array(JsonCustomerV1.MEDIA_TYPE))
@Timed
def sayHello(@PathParam("id") customerId: CustomerId, @Context uriInfo: UriInfo) : JsonCustomerV1 = {
val customer: Customer = dao.findCustomerById(customerId)
JsonCustomerV1(customer.id.toString, customerName, OffsetDateTime.now())
}
}
示例7: CalcResource
//设置package包名称以及导入依赖的类
package org.littlewings.wildflyswarm.logstash
import javax.enterprise.context.ApplicationScoped
import javax.inject.Inject
import javax.ws.rs.core.{Context, MediaType, UriInfo}
import javax.ws.rs.{GET, Path, Produces, QueryParam}
import org.jboss.logging.Logger
@Path("calc")
@ApplicationScoped
class CalcResource {
private[logstash] val logger: Logger = Logger.getLogger(getClass)
@Inject
private[logstash] var calcService: CalcService = _
@GET
@Path("add")
@Produces(Array(MediaType.TEXT_PLAIN))
def add(@QueryParam("a") a: Int, @QueryParam("b") b: Int, @Context uriInfo: UriInfo): Int = {
// logger.debugf("url = %s, parameter a = %d, b = %d", uriInfo.getRequestUri, a, b)
logger.infof("url = %s, parameter a = %d, b = %d", uriInfo.getRequestUri, a, b)
calcService.add(a, b)
}
}
示例8: BookResource
//设置package包名称以及导入依赖的类
package org.littlewings.wildflyswarm.datasource
import javax.enterprise.context.ApplicationScoped
import javax.persistence.{EntityManager, PersistenceContext}
import javax.transaction.Transactional
import javax.ws.rs._
import javax.ws.rs.core.{Context, MediaType, Response, UriInfo}
@Path("book")
@ApplicationScoped
@Transactional
class BookResource {
@PersistenceContext
private[datasource] var entityManager: EntityManager = _
@GET
@Path("{isbn}")
@Produces(Array(MediaType.APPLICATION_JSON))
def find(@PathParam("isbn") isbn: String): Book =
entityManager.find(classOf[Book], isbn)
@PUT
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MediaType.APPLICATION_JSON))
def register(book: Book, @Context uriInfo: UriInfo): Response = {
entityManager.persist(book)
Response.created(uriInfo.getRequestUriBuilder.path(book.isbn).build()).build
}
}
示例9: EntityEndpoint
//设置package包名称以及导入依赖的类
package quizleague.rest.endpoint
import javax.ws.rs.Path
import javax.ws.rs.core.Context
import javax.ws.rs.core.Request
import javax.ws.rs.core.UriInfo
import quizleague.rest.EtagSupport
import quizleague.rest.GetEndpoints
import quizleague.rest.MaintainPostEndpoints
import quizleague.rest.PutEndpoints
import javax.ws.rs.POST
import quizleague.domain.container.DomainContainer
import scala.reflect.ClassTag
import quizleague.data.Storage
import quizleague.domain.Entity
@Path("/entity")
class EntityEndpoint(
@Context override val request:Request,
@Context override val uriInfo:UriInfo
) extends GetEndpoints with PutEndpoints with MaintainPostEndpoints with EtagSupport{
override val defaultCacheAge = 0
override val shortCacheAge = 0
preChecks()
@POST
@Path("/dbupload")
def dbload(json:String) = {
import io.circe._, io.circe.generic.auto._, io.circe.syntax._, io.circe.parser._
import quizleague.util.json.codecs.DomainCodecs._
import quizleague.util.json.codecs.ScalaTimeCodecs._
def saveAll[T <: Entity](list:List[T])(implicit tag:ClassTag[T], encoder:Encoder[T]) = {
list.foreach(a => Storage.save[T](a)(tag,encoder))
}
val container = decode[DomainContainer](json).merge.asInstanceOf[DomainContainer]
saveAll(container.applicationcontext)
saveAll(container.competition)
saveAll(container.fixture)
saveAll(container.fixtures)
saveAll(container.globaltext)
saveAll(container.leaguetable)
saveAll(container.result)
saveAll(container.results)
saveAll(container.season)
saveAll(container.team)
saveAll(container.text)
saveAll(container.user)
saveAll(container.venue)
}
}
示例10: LookupResource
//设置package包名称以及导入依赖的类
package org.dbpedia.lookup.server
import javax.ws.rs._
import javax.ws.rs.core.Context
import core.Response
import org.dbpedia.lookup.entities._
import org.dbpedia.lookup.lucene.Searcher
import org.dbpedia.lookup.util.Logging
@Path("/api/search{ext:(.asmx)?}")
@Produces(Array("application/xml", "application/json"))
class LookupResource extends Logging {
@Context
var searcher : Searcher = _
@DefaultValue("") @HeaderParam("accept")
var accept : String = _
@DefaultValue("") @QueryParam("QueryString")
var query : String = _
@DefaultValue("") @QueryParam("QueryClass")
var ontologyClass : String = _
@DefaultValue("5") @QueryParam("MaxHits")
var maxHits : Int = _
@GET
@Path("/KeywordSearch")
def keywordSearch : Response = {
val results = searcher.keywordSearch(query, ontologyClass, maxHits)
logger.info("KeywordSearch found "+results.length+": MaxHits="+maxHits.toString+" QueryClass="+ontologyClass+" QueryString="+query)
ok(results)
}
@GET
@Path("/PrefixSearch")
def prefixSearch : Response = {
val results = searcher.prefixSearch(query, ontologyClass, maxHits)
logger.info("PrefixSearch found "+results.length+": MaxHits="+maxHits.toString+" QueryClass="+ontologyClass+" QueryString="+query)
ok(results)
}
// Sets the necessary headers in order to enable CORS
private def ok(results: List[Result]): Response = {
Response.ok().entity(serialize(results)).header("Access-Control-Allow-Origin", "*").build()
}
private def serialize(results: List[Result]): String = {
val serializer = (accept contains "application/json") match {
case true => new ResultJsonSerializer
case _ => new ResultXmlSerializer
}
serializer.prettyPrint(results)
}
}