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

Scala MediaType类代码示例

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

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



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

示例1: DataResourceService

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

import com.martinsnyder.api.DataResourceApi.AnyDataResourceApi
import com.martinsnyder.api._
import javax.ws.rs.{ GET, Path, PathParam, Produces }
import javax.ws.rs.core.{ MediaType, Response }

abstract class DataResourceService(api: AnyDataResourceApi) extends Service {
  @GET
  @Produces(Array(MediaType.APPLICATION_JSON))
  def query(): Response =
    toResponseBuilder(api.query()).build()

  @GET
  @Path("/{id}")
  @Produces(Array(MediaType.APPLICATION_JSON))
  def retrieve(@PathParam("id") id: ResourceId): Response =
    toResponseBuilder(api.retrieve(id)).build()

  @GET
  @Path("/{id}/pointer")
  @Produces(Array(MediaType.APPLICATION_JSON))
  def resourcePointer(@PathParam("id") id: ResourceId): Response =
    toResponseBuilder(api.resourcePointer(id)).build()
} 
开发者ID:MartinSnyder,项目名称:mrp,代码行数:26,代码来源:DataResourceService.scala


示例2: CertificateResponse

//设置package包名称以及导入依赖的类
// Copyright (C) 2016 Grier Forensics. All Rights Reserved.
package com.grierforensics.greatdane

import javax.ws.rs._
import javax.ws.rs.core.{MediaType, Response}

case class CertificateResponse(certificates: Seq[CertificateDetails])
case class ZoneLineResponse(zoneLines: Seq[String])

@Path("/")
@Produces(Array(MediaType.APPLICATION_JSON))
class Resource(engine: Engine) {

  val genson = GensonConfig.genson

  
  @POST
  @Path("{email}/dnsZoneLineForCert")
  def dnsZoneLine(@PathParam("email") email: String, pemEncodedCertificate: String): String = {
    val zoneLine = engine.dnsZoneLine(email, pemEncodedCertificate)
    genson.serialize(zoneLine)
  }
} 
开发者ID:grierforensics,项目名称:Great-DANE-Engine,代码行数:24,代码来源:Resource.scala


示例3: InsecureClient

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

import com.sun.jersey.api.client.{Client, ClientResponse}
import org.json4s.jackson.Serialization._
import javax.ws.rs.core.MediaType
import javax.net.ssl.{HostnameVerifier, SSLContext, SSLSession, X509TrustManager}

import com.sun.jersey.api.client.config.DefaultClientConfig
import com.sun.jersey.client.urlconnection.HTTPSProperties
import java.security.cert.X509Certificate

import com.sun.jersey.api.client.filter.GZIPContentEncodingFilter

class InsecureClient {

  implicit val defaultFormats = json.JsonExtraction.formats

  private val jsonContentType = MediaType.APPLICATION_JSON + ";charset=utf-8"

  private val sslContext = SSLContext.getInstance("SSL")
  sslContext.init(null, Array(new InsecureTrustManager), null)

  private val config = new DefaultClientConfig()

  config.getProperties.put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(
    new HostnameVerifier() {
      override def verify(s: String, sslSession: SSLSession): Boolean = true
    },
    sslContext
  ))


  private val client = Client.create(config)
  client.addFilter(new GZIPContentEncodingFilter(false))

  def get[A](url: String)(implicit m: Manifest[A]): A = {
    val response = client.resource(url).accept(jsonContentType).get[ClientResponse](classOf[ClientResponse])
    val responseBody = response.getEntity(classOf[String])
    println(s"TARGET = $url")
    response.getStatus match {
      case 200 => read[A](responseBody)
      case _ => throw new RuntimeException(s"Unexpected response from $url, status code ${response.getStatus} : $responseBody")
    }
  }

  def getRawResponse(url: String, contentType: String = jsonContentType)(implicit m: Manifest[String]): (Int, String) = {
    val response = client.resource(url).accept(contentType).get[ClientResponse](classOf[ClientResponse])
    val responseBody = response.getEntity(classOf[String])
    val status = response.getStatus
    (status, responseBody)
  }
}

class InsecureTrustManager extends X509TrustManager {
  def checkClientTrusted(p1: Array[X509Certificate], p2: String) {}

  def checkServerTrusted(p1: Array[X509Certificate], p2: String) {}

  def getAcceptedIssuers: Array[X509Certificate] = Array()
} 
开发者ID:danewatts,项目名称:zap-automation,代码行数:61,代码来源:InsecureClient.scala


示例4: 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)
      }
    }
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:52,代码来源:SystemResource.scala


示例5: 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"
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:52,代码来源:QueueResource.scala


示例6: 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
        )))
      }
    }
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:60,代码来源:DeploymentsResource.scala


示例7: SchemaResource

//设置package包名称以及导入依赖的类
package mesosphere.marathon.api.v2

import java.io.InputStream
import javax.inject.Inject
import javax.ws.rs._
import javax.ws.rs.core.MediaType

import com.codahale.metrics.annotation.Timed
import mesosphere.marathon.MarathonConf
import mesosphere.marathon.api.{ MarathonMediaType, RestResource }

@Path("v2/schemas")
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MarathonMediaType.PREFERRED_APPLICATION_JSON))
class SchemaResource @Inject() (
    val config: MarathonConf) extends RestResource {

  //TODO: schemas are available via /public/api/v2/schema/* anyway
  @GET
  @Timed
  @Path("app")
  def index(): InputStream = {
    getClass.getResourceAsStream("/public/api/v2/schema/AppDefinition.json")
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:26,代码来源:SchemaResource.scala


示例8: 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))
    }
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:53,代码来源:AppVersionsResource.scala


示例9: TestService

//设置package包名称以及导入依赖的类
package info.armado.ausleihe.remote

import javax.enterprise.context.RequestScoped
import javax.transaction.Transactional
import javax.ws.rs.core.MediaType
import javax.ws.rs.{GET, Path, Produces}

import info.armado.ausleihe.model.TestInstance

@Path("/test")
@RequestScoped
class TestService {
  @GET
  @Produces(Array(MediaType.APPLICATION_JSON))
  @Path("/check")
  @Transactional
  def test(): TestInstance = {
    val result = new TestInstance()

    result.name = "Bob!"
    result.attribute = 7

    result
  }
} 
开发者ID:Spielekreis-Darmstadt,项目名称:lending,代码行数:26,代码来源:TestService.scala


示例10: ReturnGames

//设置package包名称以及导入依赖的类
package info.armado.ausleihe.remote

import javax.enterprise.context.RequestScoped
import javax.inject.Inject
import javax.transaction.Transactional
import javax.ws.rs._
import javax.ws.rs.core.MediaType

import info.armado.ausleihe.database.access.{GamesDao, LendGameDao}
import info.armado.ausleihe.database.barcode._
import info.armado.ausleihe.database.entities.{Game, LendGame}
import info.armado.ausleihe.remote.dataobjects.inuse.NotInUse
import info.armado.ausleihe.remote.requests.ReturnGameRequest
import info.armado.ausleihe.remote.results._
import info.armado.ausleihe.util.DOExtensions.{GameExtension, LendGameExtension, barcodeToString}

@Path("/return")
@RequestScoped
class ReturnGames {
  @Inject var gamesDao: GamesDao = _
  @Inject var lendGameDao: LendGameDao = _

  def findGame(gameBarcode: Barcode): Option[Either[LendGame, Game]] =
    lendGameDao.selectLendGameByGameBarcode(gameBarcode) match {
      case Some(lendGame) => Some(Left(lendGame))
      case None => gamesDao.selectActivatedByBarcode(gameBarcode) match {
        case Some(game) => Some(Right(game))
        case None => None
      }
    }

  @POST
  @Consumes(Array(MediaType.APPLICATION_XML))
  @Produces(Array(MediaType.APPLICATION_XML))
  @Path("/games")
  @Transactional
  def returnGame(returnGameRequest: ReturnGameRequest): AbstractResult = returnGameRequest match {
    case ReturnGameRequest(Some(gameBarcode)) => ValidateBarcode(gameBarcode) match {
      // the given barcode is a valid barcode
      case ValidBarcode(gameBarcode) => findGame(gameBarcode) match {
        // the game is currently borrowed by someone
        case Some(Left(lendGame)) => {
          lendGameDao.returnGame(lendGame)
          ReturnGameSuccess(lendGame.toGameData)
        }

        // the game is currently not borrowed
        case Some(Right(game)) => LendingEntityInUse(game.toGameData, NotInUse())

        // a game with the given barcode doesn't exist
        case None => LendingEntityNotExists(gameBarcode)
      }

      case InvalidBarcode(gameBarcode) => IncorrectBarcode(gameBarcode)
    }

    // wrong input
    case _ => throw new BadRequestException()
  }
} 
开发者ID:Spielekreis-Darmstadt,项目名称:lending,代码行数:61,代码来源:ReturnGames.scala


示例11: InsReq

//设置package包名称以及导入依赖的类
package org.cddb.server.http.serve

import javax.ws.rs._
import javax.ws.rs.container.{AsyncResponse, Suspended}
import javax.ws.rs.core.MediaType

import akka.actor.ActorRef
import io.circe.generic.semiauto._
import io.circe.{Decoder, Encoder}
import org.cddb.store.{InsertRequest, RetrieveRequest}

case class InsReq(key: String, value: String)

@Path("/api/storage")
@Produces(Array(MediaType.APPLICATION_JSON))
class StorageResource(receiver: ActorRef) {

  import io.circe._
  import io.circe.generic.auto._

  @GET
  @Path("/{key}")
  def tryFind(@PathParam("key") key: String, @Suspended response: AsyncResponse): Unit = {
    receiver ! RetrieveRequest(key, response)
  }

  @POST
  def tryInsert(request: String, @Suspended response: AsyncResponse): Unit = {
    val decodeClipsParam = Decoder[InsReq]
    val insReq = io.circe.parser.decode(request)(decodeClipsParam).right.get
    receiver ! InsertRequest(insReq.key, insReq.value, response)
  }
}


object StorageResource {
  implicit val fooDecoder: Decoder[InsReq] = deriveDecoder[InsReq]
  implicit val fooEncoder: Encoder[InsReq] = deriveEncoder[InsReq]
} 
开发者ID:tierex,项目名称:cddb,代码行数:40,代码来源:StorageResource.scala


示例12: DeputadosResource

//设置package包名称以及导入依赖的类
package com.nakamura.camara.deputados

import javax.ws.rs.container.{AsyncResponse, Suspended}
import javax.ws.rs._
import javax.ws.rs.core.MediaType

import com.codahale.metrics.annotation.{ExceptionMetered, Timed}
import com.nakamura.camara.deputados.deputado.Deputado
import org.json4s.Extraction
import org.json4s.jackson.JsonMethods._
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}


@Path("/deputados/")
class DeputadosResource(service: DeputadosService,
                        implicit val executionContext: ExecutionContext) {
  implicit val formats = org.json4s.DefaultFormats
  @GET
  @Timed
  @ExceptionMetered
  @Path("/fetch")
  @Produces(Array(MediaType.APPLICATION_JSON))
  def fetchDeputados(@Suspended asyncResponse: AsyncResponse): Unit = {
    val future: Future[Seq[Deputado]] = service.getDeputados() match {
      case Success(deputados) => Future(deputados)
      case Failure(err) => Future(throw new Error("Failed."))
    }
    future onSuccess { case response: Seq[Deputado] =>
      asyncResponse.resume(compact(render(Extraction.decompose(response))))
    }
    future onFailure { case t: Throwable =>
      asyncResponse.resume(t)
    }
  }
} 
开发者ID:akionakamura,项目名称:camara,代码行数:37,代码来源:DeputadosResource.scala


示例13: lookupHex

//设置package包名称以及导入依赖的类
// Copyright (C) 2016 Grier Forensics. All Rights Reserved.
package com.grierforensics.danesmimeatoolset.rest

import java.security.cert.X509Certificate
import javax.ws.rs._
import javax.ws.rs.core.{MediaType, Response}

import com.grierforensics.danesmimeatoolset.service.{BadCertificateException, Context, GensonConfig}
import org.bouncycastle.cert.dane.DANEEntry
import org.bouncycastle.util.encoders.{DecoderException, Hex}


  @GET
  @Path("{email}/hex/{index}")
  def lookupHex(@PathParam("email") email: String, @PathParam("index") index: Int): String = {
    val result = lookupHex(email) match {
      case results if results.isDefinedAt(index) => results(index)
      case otherwise => throw new WebApplicationException(Response.status(404).entity("DANE not found for email address").build())
    }
    GensonConfig.genson.serialize(result)
  }

  // // // lookupDnsZoneLine

  @GET
  @Path("{email}/dnsZoneLine")
  def lookupDnsZoneLine(@PathParam("email") email: String): Seq[String] = {
    daneSmimeaService.fetchDaneEntries(email).map(daneSmimeaService.getDnsZoneLineForDaneEntry(_)) match {
      case Nil => throw new WebApplicationException(Response.status(404).build())
      case nonempty => nonempty
    }
  }

  @GET
  @Path("{email}/dnsZoneLine/{index}")
  def lookupDnsZoneLine(@PathParam("email") email: String, @PathParam("index") index: Int): String = {
    val result = lookupDnsZoneLine(email) match {
      case results if results.isDefinedAt(index) => results(index)
      case otherwise => throw new WebApplicationException(Response.status(404).entity("DANE not found for email address").build())
    }
    GensonConfig.genson.serialize(result)
  }

  // // // createDnsZoneLineAsText

  @POST
  @Path("{email}/dnsZoneLineForCert")
  @Consumes(Array(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN))
  def createDnsZoneLineAsText(@PathParam("email") email: String, certPem: String): String = {
    try {
      val cert: X509Certificate = daneSmimeaService.fromPem(certPem)
      val de2: DANEEntry = daneSmimeaService.createDANEEntry(email, cert)
      val result = daneSmimeaService.getDnsZoneLineForDaneEntry(de2)
      GensonConfig.genson.serialize(result)
    }
    catch {
      case [email protected](_: BadCertificateException | _: DecoderException) => throw new WebApplicationException(Response.status(400).entity(e.getMessage).build())
    }
  }
} 
开发者ID:grierforensics,项目名称:Great-DANE-Toolset,代码行数:61,代码来源:ToolsetResource.scala


示例14: IllegalArgumentExceptionMapper

//设置package包名称以及导入依赖的类
package pl.scalare.main.exceptionmapper

import javax.ws.rs.core.Response.Status
import javax.ws.rs.core.{MediaType, Response}
import javax.ws.rs.ext.ExceptionMapper

import com.codahale.metrics.{Meter, MetricRegistry}
import io.dropwizard.jersey.errors.ErrorMessage

class IllegalArgumentExceptionMapper(val exceptions: Meter) extends ExceptionMapper[IllegalArgumentException] {

  def this(metrics: MetricRegistry) = this(metrics.meter(getClass() + "exceptions"))

  override def toResponse(exception: IllegalArgumentException): Response = {
    exceptions.mark();
    return Response.status(Status.BAD_REQUEST)
      .header("X-YOU-SILLY", "true")
      .`type`(MediaType.APPLICATION_JSON_TYPE)
      .entity(new ErrorMessage(Status.BAD_REQUEST.getStatusCode(),
        "You passed an illegal argument!"))
      .build();
  }
} 
开发者ID:writeonly,项目名称:scalare,代码行数:24,代码来源:IllegalArgumentExceptionMapper.scala


示例15: HealthCheckResource

//设置package包名称以及导入依赖的类
package pl.scalare.rest.resources

import javax.inject.Inject
import javax.ws.rs.{GET, Path, Produces}
import javax.ws.rs.core.MediaType

import com.codahale.metrics.annotation.Timed
import pl.scalare.core.repo.HealthCheckRepo
import pl.scalare.rest.ViewConfiguration
import pl.scalare.rest.views.{HealthCheckView}
import org.javatuples.Pair

@Path("/hcs")
@Produces(Array(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML))
class HealthCheckResource @Inject()(@Inject val repo: HealthCheckRepo, @Inject val view: ViewConfiguration) {
  @GET
  @Path("/")
  @Timed
  def checks = repo.runHealthCheckList.map(t => new Pair(t._1, t._2)).toArray


  @GET
  @Path("/view")
  @Timed
  def checksView = new HealthCheckView(view, checks)
} 
开发者ID:writeonly,项目名称:scalare,代码行数:27,代码来源:HealthCheckResource.scala


示例16: TaskResource

//设置package包名称以及导入依赖的类
package pl.scalare.rest.resources

import javax.inject.Inject
import javax.ws.rs.core.MediaType
import javax.ws.rs.{GET, Path, Produces}

import com.codahale.metrics.annotation.Timed
import pl.scalare.core.repo.TaskRepo
import pl.scalare.rest.ViewConfiguration
import pl.scalare.rest.views.TasksView

@Path("/tasks")
@Produces(Array(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML))
class TaskResource @Inject()(@Inject val repo: TaskRepo, @Inject val view: ViewConfiguration) {

  @GET
  @Path("/")
  @Timed
  def tasks = repo.tasks.toArray

  @GET
  @Path("/view")
  @Timed
  def tasksView = new TasksView(view, tasks)
} 
开发者ID:writeonly,项目名称:scalare,代码行数:26,代码来源:TaskResource.scala


示例17: EventResource

//设置package包名称以及导入依赖的类
package pl.scalare.rest.resources

import javax.inject.Inject
import javax.ws.rs.core.MediaType
import javax.ws.rs.{GET, Path, Produces}

import com.codahale.metrics.annotation.Timed
import pl.scalare.core.repo.EventRepo
import pl.scalare.rest.views.EventsView

@Path("/event")
@Produces(Array(MediaType.APPLICATION_JSON))
class EventResource @Inject()(@Inject val repo: EventRepo) {
  @GET()
  @Path("/view")
  @Timed
  def eventsView = new EventsView(events)

  @GET()
  @Path("/")
  @Timed
  def events = repo.getAll.toArray

} 
开发者ID:writeonly,项目名称:scalare,代码行数:25,代码来源:EventResource.scala


示例18: MappingProvider

//设置package包名称以及导入依赖的类
package works.weave.socks.aws.orders.presentation

import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import javax.ws.rs.ext.Provider
import works.weave.socks.aws.orders.ProjectDefaultJacksonMapper

@Provider
@Produces(Array(MediaType.APPLICATION_JSON))
class MappingProvider extends JacksonJaxbJsonProvider {
  setMapper(MappingProvider.mapper)
}
object MappingProvider {
  val mapper = {
    val presentationMapper = ProjectDefaultJacksonMapper.build()
    // modify as necessary for presentation purpose
    presentationMapper
  }

} 
开发者ID:Compositional,项目名称:orders-aws,代码行数:22,代码来源:MappingProvider.scala


示例19: MessageResource

//设置package包名称以及导入依赖的类
package org.littlewings.wildflyswarm.hystrix

import javax.ws.rs.core.MediaType
import javax.ws.rs.{GET, Path, Produces}

import org.jboss.logging.Logger

@Path("message")
class MessageResource {
  val logger: Logger = Logger.getLogger(classOf[MessageResource])

  @GET
  @Path("fail-fast")
  @Produces(Array(MediaType.TEXT_PLAIN))
  def failFast: String = {
    logger.infof("start resource")

    val command = new FailFastMessageCommand
    val message = command.execute()

    logger.infof("end resource")

    message + System.lineSeparator
  }

  @GET
  @Path("fail-silent")
  @Produces(Array(MediaType.TEXT_PLAIN))
  def failSilent: String = {
    logger.infof("start resource")

    val command = new FailSilentCommand
    val message = command.execute()

    logger.infof("end resource")

    message + System.lineSeparator
  }

  @GET
  @Path("configured")
  @Produces(Array(MediaType.TEXT_PLAIN))
  def configured: String = {
    logger.infof("start configured-message resource")

    val command = new ConfiguredMessageCommand
    val message = command.execute()

    logger.infof("end configured-message resource")

    message + System.lineSeparator
  }
} 
开发者ID:kazuhira-r,项目名称:wildfly-swarm-scala-examples,代码行数:54,代码来源:MessageResource.scala


示例20: 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)
  }
} 
开发者ID:kazuhira-r,项目名称:wildfly-swarm-scala-examples,代码行数:27,代码来源:CalcResource.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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