本文整理汇总了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()
}
示例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();
}
}