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


Scala Status类代码示例

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


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

示例1: ResponseFacade

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

import java.net.URI
import javax.ws.rs.core.Response.Status
import javax.ws.rs.core.{ NewCookie, Response }

import mesosphere.marathon.plugin.http.HttpResponse

class ResponseFacade extends HttpResponse {
  private[this] var builder = Response.status(Status.UNAUTHORIZED)
  override def header(name: String, value: String): Unit = builder.header(name, value)
  override def status(code: Int): Unit = builder = builder.status(code)
  override def sendRedirect(location: String): Unit = {
    builder.status(Status.TEMPORARY_REDIRECT).location(new URI(location))
  }
  override def cookie(name: String, value: String, maxAge: Int, secure: Boolean): Unit = {
    builder.cookie(new NewCookie(name, value, null, null, null, maxAge, secure))
  }
  override def body(mediaType: String, bytes: Array[Byte]): Unit = {
    builder.`type`(mediaType)
    builder.entity(bytes)
  }
  def response: Response = builder.build()
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:25,代码来源:ResponseFacade.scala

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


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