当前位置: 首页>>代码示例>>Scala>>正文


Scala Produces类代码示例

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


在下文中一共展示了Produces类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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")
      }
    }
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:47,代码来源:LeaderResource.scala

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: ScalaObjectMapperProvider

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

import javax.ws.rs.core.MediaType
import javax.ws.rs.ext.{ContextResolver, Provider}
import javax.ws.rs.{Consumes, Produces}

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule

@Provider
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MediaType.APPLICATION_JSON))
class ScalaObjectMapperProvider extends ContextResolver[ObjectMapper] {
  override def getContext(typ: Class[_]): ObjectMapper = {
    val objectMapper = new ObjectMapper
    objectMapper.registerModule(DefaultScalaModule)
    objectMapper
  }
} 
开发者ID:kazuhira-r,项目名称:wildfly-swarm-scala-examples,代码行数:20,代码来源:ScalaObjectMapperProvider.scala

示例11: FrontResource

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

import java.nio.charset.StandardCharsets
import javax.ws.rs.container.{AsyncResponse, Suspended}
import javax.ws.rs.core.MediaType
import javax.ws.rs.{GET, Path, Produces, QueryParam}

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.ribbon.Ribbon
import io.netty.buffer.ByteBufInputStream

@Path("front")
class FrontResource {
  val objectMapper: ObjectMapper = new ObjectMapper

  @GET
  @Path("get-now")
  @Produces(Array(MediaType.APPLICATION_JSON))
  def get: java.util.Map[_, _] = {
    val byteBuf = Ribbon.from(classOf[TimeService]).now.execute()

    objectMapper.readValue(new ByteBufInputStream(byteBuf), classOf[java.util.Map[_, _]])
  }

  @GET
  @Path("get-now-async")
  @Produces(Array(MediaType.APPLICATION_JSON))
  def getAsync(@Suspended asyncResponse: AsyncResponse): Unit = {
    val observable = Ribbon.from(classOf[TimeService]).now.observe

    observable.subscribe { byteBuf =>
      val now = objectMapper.readValue(new ByteBufInputStream(byteBuf), classOf[java.util.Map[_, _]])
      asyncResponse.resume(now)
    }
  }

  @GET
  @Path("message-echo")
  @Produces(Array(MediaType.TEXT_PLAIN))
  def messageEcho(@QueryParam("message") message: String): String = {
    val byteBuf = Ribbon.from(classOf[MessageService]).echo(message).execute()
    val is = new ByteBufInputStream(byteBuf)
    new String(
      Iterator
        .continually(is.read())
        .takeWhile(_ != -1)
        .map(_.asInstanceOf[Byte])
        .toArray,
      StandardCharsets.UTF_8
    )
  }
} 
开发者ID:kazuhira-r,项目名称:wildfly-swarm-scala-examples,代码行数:53,代码来源:FrontResource.scala

示例12: TimeResource

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

import java.net.InetAddress
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.ws.rs.core.MediaType
import javax.ws.rs.{GET, Path, Produces}

import scala.collection.JavaConverters._

@Path("time")
class TimeResource {
  @GET
  @Path("now")
  @Produces(Array(MediaType.APPLICATION_JSON))
  def now: java.util.Map[String, String] =
    Map("now" -> LocalDateTime.now.format(DateTimeFormatter.ISO_DATE_TIME),
      "from" -> InetAddress.getLocalHost.getHostName)
      .asJava
} 
开发者ID:kazuhira-r,项目名称:wildfly-swarm-scala-examples,代码行数:21,代码来源:TimeResource.scala


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