forked from loafle/openapi-generator-original
rebuilt client
This commit is contained in:
parent
4bd1b99213
commit
779bdb23eb
@ -165,6 +165,12 @@
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jfarcand</groupId>
|
||||
<artifactId>jersey-ahc-client</artifactId>
|
||||
<version>${jersey-async-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
@ -204,6 +210,7 @@
|
||||
<joda-time-version>2.2</joda-time-version>
|
||||
<jersey-version>1.7</jersey-version>
|
||||
<swagger-core-version>1.5.0-M1</swagger-core-version>
|
||||
<jersey-async-version>1.0.5</jersey-async-version>
|
||||
<maven-plugin.version>1.0.0</maven-plugin.version>
|
||||
<jackson-version>2.4.2</jackson-version>
|
||||
|
||||
|
@ -35,10 +35,14 @@ object ScalaJsonUtil {
|
||||
}
|
||||
}
|
||||
|
||||
object ApiInvoker {
|
||||
val mapper = ScalaJsonUtil.getJsonMapper
|
||||
val defaultHeaders: HashMap[String, String] = HashMap()
|
||||
val hostMap: HashMap[String, Client] = HashMap()
|
||||
class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper,
|
||||
httpHeaders: HashMap[String, String] = HashMap(),
|
||||
hostMap: HashMap[String, Client] = HashMap(),
|
||||
asyncHttpClient: Boolean = false,
|
||||
authScheme: String = "",
|
||||
authPreemptive: Boolean = false) {
|
||||
|
||||
var defaultHeaders: HashMap[String, String] = httpHeaders
|
||||
|
||||
def escape(value: String): String = {
|
||||
URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20")
|
||||
@ -151,14 +155,39 @@ object ApiInvoker {
|
||||
hostMap.contains(host) match {
|
||||
case true => hostMap(host)
|
||||
case false => {
|
||||
val client = Client.create()
|
||||
val client = newClient(host)
|
||||
// client.addFilter(new LoggingFilter())
|
||||
hostMap += host -> client
|
||||
client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def newClient(host: String): Client = asyncHttpClient match {
|
||||
case true => {
|
||||
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig
|
||||
import org.sonatype.spice.jersey.client.ahc.AhcHttpClient
|
||||
import com.ning.http.client.Realm
|
||||
|
||||
val config: DefaultAhcConfig = new DefaultAhcConfig()
|
||||
if (!authScheme.isEmpty) {
|
||||
val authSchemeEnum = Realm.AuthScheme.valueOf(authScheme)
|
||||
config.getAsyncHttpClientConfigBuilder
|
||||
.setRealm(new Realm.RealmBuilder().setScheme(authSchemeEnum)
|
||||
.setUsePreemptiveAuth(authPreemptive).build)
|
||||
}
|
||||
AhcHttpClient.create(config)
|
||||
}
|
||||
case _ => Client.create()
|
||||
}
|
||||
}
|
||||
|
||||
object ApiInvoker extends ApiInvoker(mapper = ScalaJsonUtil.getJsonMapper,
|
||||
httpHeaders = HashMap(),
|
||||
hostMap = HashMap(),
|
||||
asyncHttpClient = false,
|
||||
authScheme = "",
|
||||
authPreemptive = false)
|
||||
|
||||
class ApiException(val code: Int, msg: String) extends RuntimeException(msg)
|
||||
|
||||
|
@ -12,9 +12,10 @@ import java.util.Date
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class AccountApi {
|
||||
var basePath: String = "https://api.wordnik.com/v4"
|
||||
var apiInvoker = ApiInvoker
|
||||
class AccountApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||
var basePath = defBasePath
|
||||
var apiInvoker = defApiInvoker
|
||||
|
||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||
|
||||
|
@ -14,9 +14,10 @@ import java.util.Date
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class WordApi {
|
||||
var basePath: String = "https://api.wordnik.com/v4"
|
||||
var apiInvoker = ApiInvoker
|
||||
class WordApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||
var basePath = defBasePath
|
||||
var apiInvoker = defApiInvoker
|
||||
|
||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||
|
||||
|
@ -10,9 +10,10 @@ import java.util.Date
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class WordListApi {
|
||||
var basePath: String = "https://api.wordnik.com/v4"
|
||||
var apiInvoker = ApiInvoker
|
||||
class WordListApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||
var basePath = defBasePath
|
||||
var apiInvoker = defApiInvoker
|
||||
|
||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||
|
||||
|
@ -9,9 +9,10 @@ import java.util.Date
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class WordListsApi {
|
||||
var basePath: String = "https://api.wordnik.com/v4"
|
||||
var apiInvoker = ApiInvoker
|
||||
class WordListsApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||
var basePath = defBasePath
|
||||
var apiInvoker = defApiInvoker
|
||||
|
||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||
|
||||
|
@ -12,9 +12,10 @@ import java.util.Date
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class WordsApi {
|
||||
var basePath: String = "https://api.wordnik.com/v4"
|
||||
var apiInvoker = ApiInvoker
|
||||
class WordsApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||
var basePath = defBasePath
|
||||
var apiInvoker = defApiInvoker
|
||||
|
||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user