@@ -52,11 +52,8 @@ open class ApacheHttpClient : HttpClient {
52
52
53
53
private val httpClient: org.apache.http.client.HttpClient
54
54
55
- constructor () {
56
- val basicCookieStore = BasicCookieStore ()
57
- this .apacheCookieStore = ApacheCookieStore (basicCookieStore)
58
- this .httpClientContext!! .cookieStore = basicCookieStore
59
- this .httpClient = HttpClients .custom()
55
+ constructor () : this (
56
+ HttpClients .custom()
60
57
.setConnectionManager(PoolingHttpClientConnectionManager ().also {
61
58
it.maxTotal = 50
62
59
it.defaultMaxPerRoute = 20
@@ -73,10 +70,8 @@ open class ApacheHttpClient : HttpClient {
73
70
.setSocketTimeout(30 * 1000 )
74
71
.setCookieSpec(CookieSpecs .STANDARD ).build()
75
72
)
76
- .setSSLHostnameVerifier(NOOP_HOST_NAME_VERIFIER )
77
- .setSSLSocketFactory(SSLSF )
78
73
.build()
79
- }
74
+ )
80
75
81
76
constructor (httpClient: org.apache.http.client.HttpClient ) {
82
77
val basicCookieStore = BasicCookieStore ()
@@ -133,7 +128,7 @@ open class ApacheHttpClient : HttpClient {
133
128
if (param.type() == " file" ) {
134
129
val filePath = param.value()
135
130
if (filePath.isNullOrBlank()) {
136
- continue
131
+ throw FileNotFoundException ( " file not found " )
137
132
}
138
133
val file = File (filePath)
139
134
if (! file.exists() || ! file.isFile) {
@@ -187,13 +182,7 @@ open class ApacheHttpClient : HttpClient {
187
182
}
188
183
189
184
@ScriptTypeName(" request" )
190
- class ApacheHttpRequest : AbstractHttpRequest {
191
-
192
- private val apacheHttpClient: ApacheHttpClient
193
-
194
- constructor (apacheHttpClient: ApacheHttpClient ) : super () {
195
- this .apacheHttpClient = apacheHttpClient
196
- }
185
+ class ApacheHttpRequest (private val apacheHttpClient : ApacheHttpClient ) : AbstractHttpRequest() {
197
186
198
187
/* *
199
188
* Executes HTTP request using the [apacheHttpClient].
@@ -214,13 +203,7 @@ fun HttpRequest.contentType(contentType: ContentType): HttpRequest {
214
203
* The implement of [CookieStore] by [org.apache.http.client.CookieStore].
215
204
*/
216
205
@ScriptTypeName(" cookieStore" )
217
- class ApacheCookieStore : CookieStore {
218
-
219
- private var cookieStore: org.apache.http.client.CookieStore
220
-
221
- constructor (cookieStore: org.apache.http.client.CookieStore ) {
222
- this .cookieStore = cookieStore
223
- }
206
+ class ApacheCookieStore (private var cookieStore : org.apache.http.client.CookieStore ) : CookieStore {
224
207
225
208
/* *
226
209
* Adds an [Cookie], replacing any existing equivalent cookies.
@@ -281,7 +264,7 @@ class ApacheHttpResponse(
281
264
*
282
265
* @return the status of the response, or {@code null} if not yet set
283
266
*/
284
- override fun code (): Int? {
267
+ override fun code (): Int {
285
268
val statusLine = response.statusLine
286
269
return statusLine.statusCode
287
270
}
@@ -314,27 +297,20 @@ class ApacheHttpResponse(
314
297
}
315
298
316
299
/* *
317
- * Cache the bytes message of this response.
300
+ * the bytes message of this response.
318
301
*/
319
- private var bytes: ByteArray? = null
302
+ private val bodyBytes: ByteArray by lazy {
303
+ response.entity.toByteArray()
304
+ }
320
305
321
306
/* *
322
307
* Obtains the bytes message of this response.
323
308
*
324
309
* @return the response bytes, or
325
310
* {@code null} if there is none
326
311
*/
327
- override fun bytes (): ByteArray? {
328
- if (bytes == null ) {
329
- synchronized(this )
330
- {
331
- if (bytes == null ) {
332
- val entity = response.entity
333
- bytes = entity.toByteArray()
334
- }
335
- }
336
- }
337
- return bytes!!
312
+ override fun bytes (): ByteArray {
313
+ return bodyBytes
338
314
}
339
315
340
316
/* *
@@ -353,17 +329,12 @@ class ApacheHttpResponse(
353
329
* The implement of [Cookie] by [org.apache.http.cookie.Cookie].
354
330
*/
355
331
@ScriptTypeName(" cookie" )
356
- class ApacheCookie : Cookie {
357
- private val cookie: org.apache.http.cookie.Cookie
332
+ class ApacheCookie (private val cookie : org.apache.http.cookie.Cookie ) : Cookie {
358
333
359
334
fun getWrapper (): org.apache.http.cookie.Cookie {
360
335
return cookie
361
336
}
362
337
363
- constructor (cookie: org.apache.http.cookie.Cookie ) {
364
- this .cookie = cookie
365
- }
366
-
367
338
override fun getName (): String? {
368
339
return cookie.name
369
340
}
@@ -404,7 +375,7 @@ class ApacheCookie : Cookie {
404
375
return cookie.isSecure
405
376
}
406
377
407
- override fun getVersion (): Int? {
378
+ override fun getVersion (): Int {
408
379
return cookie.version
409
380
}
410
381
0 commit comments