本文整理汇总了Scala中javax.ws.rs.QueryParam类的典型用法代码示例。如果您正苦于以下问题:Scala QueryParam类的具体用法?Scala QueryParam怎么用?Scala QueryParam使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryParam类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: 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
示例2: 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
示例3: PasswordPolicy
//设置package包名称以及导入依赖的类
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.QueryParam
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import io.dropwizard.Application
import io.dropwizard.Configuration
import io.dropwizard.setup.Bootstrap
import io.dropwizard.setup.Environment
class PasswordPolicy {
var rule : String = _
var help : String = _
}
class PasswordValidatorConfiguration extends Configuration {
var policies : Map[String, PasswordPolicy] = _
}
@Path("/validatePassword")
class PasswordValidatorResource(policies : Map[String,PasswordPolicy]) {
@GET def validate(@QueryParam("policy") policy: String,
@QueryParam("password") password: String) : String = {
if(password.matches(policies(policy).rule))
"OK"
else
policies(policy).help
}
}
class PasswordValidatorApplication extends Application[PasswordValidatorConfiguration] {
def run(configuration: PasswordValidatorConfiguration, environment: Environment) : Unit = {
environment.jersey().register(new PasswordValidatorResource(configuration.policies))
}
override def initialize(bootstrap: Bootstrap[PasswordValidatorConfiguration]) : Unit = {
bootstrap.getObjectMapper().registerModule(new DefaultScalaModule)
}
}
object PasswordValidatorApplication {
def main(args: Array[String]) {
new PasswordValidatorApplication().run(args:_*)
}
}
开发者ID:devguerrilla,项目名称:scala-quick-starts,代码行数:48,代码来源:PasswordValidatorApplication.scala
注:本文中的javax.ws.rs.QueryParam类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论