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>
|
<artifactId>jersey-multipart</artifactId>
|
||||||
<version>${jersey-version}</version>
|
<version>${jersey-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jfarcand</groupId>
|
||||||
|
<artifactId>jersey-ahc-client</artifactId>
|
||||||
|
<version>${jersey-async-version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.scala-lang</groupId>
|
<groupId>org.scala-lang</groupId>
|
||||||
<artifactId>scala-library</artifactId>
|
<artifactId>scala-library</artifactId>
|
||||||
@ -204,6 +210,7 @@
|
|||||||
<joda-time-version>2.2</joda-time-version>
|
<joda-time-version>2.2</joda-time-version>
|
||||||
<jersey-version>1.7</jersey-version>
|
<jersey-version>1.7</jersey-version>
|
||||||
<swagger-core-version>1.5.0-M1</swagger-core-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>
|
<maven-plugin.version>1.0.0</maven-plugin.version>
|
||||||
<jackson-version>2.4.2</jackson-version>
|
<jackson-version>2.4.2</jackson-version>
|
||||||
|
|
||||||
|
@ -35,10 +35,14 @@ object ScalaJsonUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ApiInvoker {
|
class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper,
|
||||||
val mapper = ScalaJsonUtil.getJsonMapper
|
httpHeaders: HashMap[String, String] = HashMap(),
|
||||||
val defaultHeaders: HashMap[String, String] = HashMap()
|
hostMap: HashMap[String, Client] = HashMap(),
|
||||||
val hostMap: HashMap[String, Client] = HashMap()
|
asyncHttpClient: Boolean = false,
|
||||||
|
authScheme: String = "",
|
||||||
|
authPreemptive: Boolean = false) {
|
||||||
|
|
||||||
|
var defaultHeaders: HashMap[String, String] = httpHeaders
|
||||||
|
|
||||||
def escape(value: String): String = {
|
def escape(value: String): String = {
|
||||||
URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20")
|
URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20")
|
||||||
@ -151,14 +155,39 @@ object ApiInvoker {
|
|||||||
hostMap.contains(host) match {
|
hostMap.contains(host) match {
|
||||||
case true => hostMap(host)
|
case true => hostMap(host)
|
||||||
case false => {
|
case false => {
|
||||||
val client = Client.create()
|
val client = newClient(host)
|
||||||
// client.addFilter(new LoggingFilter())
|
// client.addFilter(new LoggingFilter())
|
||||||
hostMap += host -> client
|
hostMap += host -> client
|
||||||
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)
|
class ApiException(val code: Int, msg: String) extends RuntimeException(msg)
|
||||||
|
|
||||||
|
@ -12,9 +12,10 @@ import java.util.Date
|
|||||||
|
|
||||||
import scala.collection.mutable.HashMap
|
import scala.collection.mutable.HashMap
|
||||||
|
|
||||||
class AccountApi {
|
class AccountApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||||
var basePath: String = "https://api.wordnik.com/v4"
|
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||||
var apiInvoker = ApiInvoker
|
var basePath = defBasePath
|
||||||
|
var apiInvoker = defApiInvoker
|
||||||
|
|
||||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||||
|
|
||||||
|
@ -14,9 +14,10 @@ import java.util.Date
|
|||||||
|
|
||||||
import scala.collection.mutable.HashMap
|
import scala.collection.mutable.HashMap
|
||||||
|
|
||||||
class WordApi {
|
class WordApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||||
var basePath: String = "https://api.wordnik.com/v4"
|
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||||
var apiInvoker = ApiInvoker
|
var basePath = defBasePath
|
||||||
|
var apiInvoker = defApiInvoker
|
||||||
|
|
||||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||||
|
|
||||||
|
@ -10,9 +10,10 @@ import java.util.Date
|
|||||||
|
|
||||||
import scala.collection.mutable.HashMap
|
import scala.collection.mutable.HashMap
|
||||||
|
|
||||||
class WordListApi {
|
class WordListApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||||
var basePath: String = "https://api.wordnik.com/v4"
|
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||||
var apiInvoker = ApiInvoker
|
var basePath = defBasePath
|
||||||
|
var apiInvoker = defApiInvoker
|
||||||
|
|
||||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||||
|
|
||||||
|
@ -9,9 +9,10 @@ import java.util.Date
|
|||||||
|
|
||||||
import scala.collection.mutable.HashMap
|
import scala.collection.mutable.HashMap
|
||||||
|
|
||||||
class WordListsApi {
|
class WordListsApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||||
var basePath: String = "https://api.wordnik.com/v4"
|
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||||
var apiInvoker = ApiInvoker
|
var basePath = defBasePath
|
||||||
|
var apiInvoker = defApiInvoker
|
||||||
|
|
||||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||||
|
|
||||||
|
@ -12,9 +12,10 @@ import java.util.Date
|
|||||||
|
|
||||||
import scala.collection.mutable.HashMap
|
import scala.collection.mutable.HashMap
|
||||||
|
|
||||||
class WordsApi {
|
class WordsApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||||
var basePath: String = "https://api.wordnik.com/v4"
|
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||||
var apiInvoker = ApiInvoker
|
var basePath = defBasePath
|
||||||
|
var apiInvoker = defApiInvoker
|
||||||
|
|
||||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user