Skip to content

Commit 67c4a96

Browse files
committed
chore: Correct some deprecation warnigs
1 parent 25ca860 commit 67c4a96

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

core/support/src/main/kotlin/au/com/dius/pact/core/support/SimpleHttp.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.apache.hc.client5.http.impl.classic.HttpClients
1111
import org.apache.hc.core5.http.ClassicHttpResponse
1212
import org.apache.hc.core5.http.ContentType
1313
import org.apache.hc.core5.http.io.entity.StringEntity
14+
import java.io.ByteArrayInputStream
1415
import java.io.InputStream
1516
import java.io.InputStreamReader
1617
import java.io.Reader
@@ -32,7 +33,7 @@ class SimpleHttp(private val baseUrl: String) {
3233
for ((key, value) in headers) {
3334
httpGet.addHeader(key, value)
3435
}
35-
return Response(client.execute(httpGet))
36+
return client.execute(httpGet) { response -> Response(response) }
3637
}
3738

3839
@JvmOverloads
@@ -47,7 +48,7 @@ class SimpleHttp(private val baseUrl: String) {
4748
httpPost.addHeader(key, value)
4849
}
4950
httpPost.entity = StringEntity(body, ContentType.parse(contentType))
50-
return Response(client.execute(httpPost))
51+
return client.execute(httpPost) { response -> Response(response) }
5152
}
5253

5354
@JvmOverloads
@@ -62,12 +63,12 @@ class SimpleHttp(private val baseUrl: String) {
6263
httpPut.addHeader(key, value)
6364
}
6465
httpPut.entity = StringEntity(body, ContentType.parse(contentType))
65-
return Response(client.execute(httpPut))
66+
return client.execute(httpPut) { response -> Response(response) }
6667
}
6768

6869
fun delete(path: String): Response {
6970
val httpDelete = HttpDelete(buildUrl(baseUrl, path, emptyMap()))
70-
return Response(client.execute(httpDelete))
71+
return client.execute(httpDelete) { response -> Response(response) }
7172
}
7273

7374
companion object {
@@ -87,13 +88,14 @@ class Response(val response: ClassicHttpResponse) {
8788
val contentType: String = if (response.entity != null && response.entity.contentType != null) {
8889
response.entity.contentType
8990
} else "text/plain"
91+
val body = response.entity?.content?.readBytes()
9092

9193
fun getReader(): Reader {
92-
return InputStreamReader(response.entity.content)
94+
return InputStreamReader(ByteArrayInputStream(body))
9395
}
9496

9597
fun getInputStream(): InputStream {
96-
return response.entity.content
98+
return ByteArrayInputStream(body)
9799
}
98100

99101
fun getHeaders(): Map<String, List<String>> {
@@ -110,15 +112,15 @@ class Response(val response: ClassicHttpResponse) {
110112
}
111113

112114
fun bodyToMap(): Map<String, Any?> {
113-
return when (response.entity.contentType) {
115+
return when (contentType) {
114116
"application/x-www-form-urlencoded" -> {
115-
response.entity.content.reader().readText().split('&').map {
117+
getReader().readText().split('&').map {
116118
val values = it.split('=', limit = 2)
117119
values[0] to values[1]
118120
}.associate { it }
119121
}
120122
"application/json" -> {
121-
toMap(JsonParser.parseStream(response.entity.content))
123+
toMap(JsonParser.parseStream(getInputStream()))
122124
}
123125
else -> emptyMap()
124126
}

core/support/src/main/kotlin/au/com/dius/pact/core/support/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ object Utils {
6060
var port: Int? = null
6161
var count = 0
6262
while (port == null && count < 20) {
63-
val randomPort = RandomUtils.nextInt(lower, upper)
63+
val randomPort = RandomUtils.insecure().randomInt(lower, upper)
6464
if (portAvailable(randomPort)) {
6565
port = randomPort
6666
}

0 commit comments

Comments
 (0)