本文整理汇总了Scala中org.apache.http.entity.ContentType类的典型用法代码示例。如果您正苦于以下问题:Scala ContentType类的具体用法?Scala ContentType怎么用?Scala ContentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentType类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Image
//设置package包名称以及导入依赖的类
package tools
import common.Tool._
import org.apache.http.entity.ContentType
import org.apache.http.entity.mime.MultipartEntityBuilder
object Image {
def getImageCode(data:Array[Byte])={
val entity=MultipartEntityBuilder.create()
entity.addTextBody("username","livehl")
entity.addTextBody("password","19890218")
entity.addTextBody("typeid","1040")
entity.addTextBody("softid","67954")
entity.addTextBody("softkey","33a6fb701d3a4607ae930ff4bb67c43d")
entity.addBinaryBody("image",data, ContentType.DEFAULT_BINARY,"image.jpg")
val (_,result)=NetTool.HttpPost("http://api.ruokuai.com/create.json",entity=entity.build())
result.jsonToMap("Result").toString
}
}
开发者ID:livehl,项目名称:paipai,代码行数:22,代码来源:Image.scala
示例2: PositionApiImpl
//设置package包名称以及导入依赖的类
package org.nikosoft.oanda.api.impl
import org.apache.http.client.fluent.Request
import org.apache.http.entity.ContentType
import org.json4s.native.Serialization._
import org.nikosoft.oanda.api.ApiCommons
import org.nikosoft.oanda.api.ApiModel.AccountModel.AccountID
import org.nikosoft.oanda.api.ApiModel.PrimitivesModel.InstrumentName
import org.nikosoft.oanda.api.Errors.Error
import org.nikosoft.oanda.api.`def`.PositionApi
import org.nikosoft.oanda.api.`def`.PositionApi.{ClosePositionRequest, ClosePositionResponse, PositionsResponse}
import scalaz.\/
private[api] object PositionApiImpl extends PositionApi with ApiCommons {
def closePosition(accountId: AccountID, instrument: InstrumentName, closePositionRequest: ClosePositionRequest): \/[Error, ClosePositionResponse] = {
val jsonBody = write(closePositionRequest)
val url = s"$baseUrl/accounts/${accountId.value}/positions/${instrument.value}/close"
val content = Request
.Put(url)
.addHeader("Authorization", token)
.bodyString(jsonBody, ContentType.APPLICATION_JSON)
.execute()
.returnResponse()
handleRequest[ClosePositionResponse](content)
}
}
开发者ID:cnnickolay,项目名称:oanda-scala-api,代码行数:32,代码来源:PositionApiImpl.scala
示例3: ElasticSearchProcessorUtils
//设置package包名称以及导入依赖的类
package lert.elasticsearch
import scala.reflect.ClassTag
import com.fasterxml.jackson.databind.ObjectMapper
import lert.elasticsearch.ElasticSearchProcessor.{DEFAULT_TIMESTAMP_FIELD, PARAM_TIMESTAMP_FIELD}
import org.apache.http.HttpEntity
import org.apache.http.entity.ContentType
import org.apache.http.nio.entity.NStringEntity
object ElasticSearchProcessorUtils {
def getTimestampField(params: Map[String, _]): String =
params.getOrElse(PARAM_TIMESTAMP_FIELD, DEFAULT_TIMESTAMP_FIELD).toString
def httpEntity(data: Map[String, _])(implicit objectMapper: ObjectMapper) =
new NStringEntity(objectMapper.writeValueAsString(data), ContentType.APPLICATION_JSON)
def getIndexName(params: Map[String, _]): String = params(ElasticSearchProcessor.PARAM_INDEX).toString
implicit class HttpEntityMapper(val httpEntity: HttpEntity) extends AnyVal {
def to[T: ClassTag](implicit objectMapper: ObjectMapper): T = {
def ctag = implicitly[reflect.ClassTag[T]]
val content = httpEntity.getContent
try
objectMapper.readValue(content, ctag.runtimeClass.asInstanceOf[Class[T]])
finally
content.close()
}
}
}
开发者ID:l3rt,项目名称:l3rt,代码行数:32,代码来源:ElasticSearchProcessorUtils.scala
示例4: QueryMatcher
//设置package包名称以及导入依赖的类
package lert.elasticsearch.matcher
import java.util.{Collections, Date}
import javax.inject.Inject
import com.fasterxml.jackson.databind.ObjectMapper
import lert.core.processor.AlertMessage
import lert.core.status.Status
import lert.elasticsearch.Response
import org.apache.http.entity.ContentType
import org.apache.http.nio.entity.NStringEntity
import org.elasticsearch.client.RestClient
import lert.elasticsearch.ElasticSearchProcessorUtils._
class QueryMatcher @Inject()(implicit objectMapper: ObjectMapper) extends Matcher {
override def supports(params: Map[String, _]): Boolean =
params.contains("query")
override def query(client: RestClient, params: Map[String, _], status: Option[Status]): Seq[AlertMessage] = {
val lastProcessedTimestamp = status.map(_.lastProcessedTimestamp).getOrElse(new Date(0))
val query = params("query").toString.replace("{lastProcessedTimestamp}", lastProcessedTimestamp.getTime.toString)
val body = new NStringEntity(query, ContentType.APPLICATION_JSON)
client
.performRequest("GET", s"/${getIndexName(params)}/_search", Collections.emptyMap[String, String](), body)
.getEntity
.to[Response]
.hits.hits
.map(hit => AlertMessage(hit._source))
}
}
开发者ID:l3rt,项目名称:l3rt,代码行数:31,代码来源:QueryMatcher.scala
示例5: UrlPart
//设置package包名称以及导入依赖的类
package swag_pact
package swagger
import au.com.dius.pact.model.RequestResponseInteraction
import cats.instances.int._
import cats.syntax.eq._
import org.apache.http.entity.ContentType
import swag_pact.properties.Property
final case class UrlPart(part: String)
final case class SwaggerOperation(
produces: List[ContentType],
consumes: List[ContentType],
defaultResponse: Option[DefaultSwaggerResponse],
responses: List[StatusSwaggerResponse],
interactions: List[RequestResponseInteraction]
) {
def findResponse(statusCode: Int): Option[SwaggerResponse] = {
responses.find(_.statusCode === statusCode).orElse(defaultResponse)
}
}
sealed trait SwaggerResponse extends Product with Serializable {
def headers: Map[String, Property]
def body: Option[Property]
}
final case class DefaultSwaggerResponse(headers: Map[String, Property], body: Option[Property]) extends SwaggerResponse
final case class StatusSwaggerResponse(statusCode: Int, headers: Map[String, Property], body: Option[Property])
extends SwaggerResponse
开发者ID:guymers,项目名称:swag-pact,代码行数:32,代码来源:models.scala
示例6: JavaMapExtensions
//设置package包名称以及导入依赖的类
import cats.Show
import cats.instances.string._
import cats.syntax.semigroup._
import cats.syntax.show._
import org.apache.http.entity.ContentType
package object swag_pact {
import scala.collection.JavaConverters._
// many swagger methods that return maps or lists can return null
final implicit class JavaMapExtensions[K, V](map: => java.util.Map[K, V]) {
def asScalaMap: Map[K, V] = {
Option(map).map(_.asScala.toMap).getOrElse(Map.empty[K, V])
}
}
final implicit class JavaListExtensions[E](list: => java.util.List[E]) {
def asScalaList: List[E] = {
Option(list).map(_.asScala.toList).getOrElse(List.empty[E])
}
}
implicit val showOptionalThrowable: Show[Option[Throwable]] = Show.show {
case Some(t) => ": " |+| t.show
case None => ""
}
implicit val showThrowable: Show[Throwable] = Show.fromToString
implicit val showContentType: Show[ContentType] = Show.show { _.toString }
}
开发者ID:guymers,项目名称:swag-pact,代码行数:33,代码来源:package.scala
示例7: PactResponseError
//设置package包名称以及导入依赖的类
package swag_pact
package validation
import cats.Show
import cats.instances.string._
import cats.syntax.semigroup._
import cats.syntax.show._
import org.apache.http.entity.ContentType
import swag_pact.properties.Property
sealed abstract class PactResponseError extends Product with Serializable
object PactResponseError {
final case class MissingSwaggerResponse(statusCode: Int, availableStatusCodes: List[Int]) extends PactResponseError
final case class InvalidContentType(contentType: String) extends PactResponseError
final case class MissingContentType(contentType: ContentType, availableContentTypes: List[ContentType])
extends PactResponseError
case object MissingBody extends PactResponseError
final case class UnexpectedBody(body: String) extends PactResponseError
final case class InvalidBody(contentType: ContentType, e: Option[Throwable]) extends PactResponseError
final case class UnsupportedContentType(contentType: ContentType) extends PactResponseError
case object MissingSchema extends PactResponseError
final case class UnexpectedSchema(schema: Property) extends PactResponseError
def missingBody: PactResponseError = MissingBody
def unexpectedBody(body: String): PactResponseError = UnexpectedBody(body)
def unexpectedSchema(schema: Property): PactResponseError = UnexpectedSchema(schema)
implicit val show: Show[PactResponseError] = Show.show {
case MissingSwaggerResponse(statusCode, availableStatusCodes) =>
"No Swagger response with status code " |+| statusCode.toString |+| " available status codes: " |+| availableStatusCodes
.mkString(", ")
case InvalidContentType(contentType) =>
"Invalid content type " |+| contentType
case MissingContentType(contentType, availableContentTypes) =>
"No content type " |+| contentType.show |+| " in Swagger response available status codes: " |+| availableContentTypes
.map(_.show)
.mkString(", ")
case MissingBody =>
"Swagger response has body but Pact does not"
case UnexpectedBody(body) =>
"Swagger response has no body but Pact does: " |+| body
case InvalidBody(contentType, e) =>
"Pact response with content type " |+| contentType.show |+| " could not be parsed" |+| e.show
case UnsupportedContentType(contentType) =>
"Content type " |+| contentType.show |+| " is not supported"
case MissingSchema =>
"Could not find schema in Swagger response"
case UnexpectedSchema(schema) =>
"Swagger response has schema " |+| schema.show |+| " when it should have had none"
}
}
开发者ID:guymers,项目名称:swag-pact,代码行数:56,代码来源:PactResponseError.scala
示例8: ToutiaoCrawler
//设置package包名称以及导入依赖的类
package org.webant.plugin.test.toutiao
import java.io.IOException
import java.nio.charset.Charset
import org.apache.http.client.fluent.Response
import org.apache.http.entity.ContentType
object ToutiaoCrawler {
def main(args: Array[String]) {
getCrawl
}
@throws[IOException]
private def crawl(start: Int, size: Int) {
val url: String = "http://chuanbo.weiboyi.com/hworder/weixin/filterlist/source/all"
val body: String = "web_csrf_token=58f07eaf60fa7&price_list=top%2Csecond%2Cother%2Csingle&start=" + start + "&limit=" + size
val referer: String = "http://chuanbo.weiboyi.com/hworder/weixin/index?price_list=top%2Csecond%2Cother%2Csingle&start=" + start + "&limit=" + size
val resp: Response = org.apache.http.client.fluent.Request.Post(url)
.bodyString(body, ContentType.APPLICATION_FORM_URLENCODED)
.addHeader("Proxy-Connection", "keep-alive")
.addHeader("Pragma", "no-cache").addHeader("Cache-Control", "no-cache")
.addHeader("Accept", "**;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate, sdch")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36")
.addHeader("Upgrade-Insecure-Requests", "1")
.addHeader("Proxy-Connection", "keep-alive")
.addHeader("Referer", referer)
.addHeader("DNT", "1")
.addHeader("Cookie", cookie)
.execute
val result = resp.returnContent.asString(Charset.forName("UTF-8"))
val fileName: String = "D:/cache/weiboyi/pages/data"
}
}
开发者ID:sutine,项目名称:webant-workbench,代码行数:38,代码来源:ToutiaoCrawler.scala
注:本文中的org.apache.http.entity.ContentType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论