I implementing the OkHttpClient in my service. When I hit 150+ connections in a connectionPool in the okHttpClient at a time, the below exception has been thrown. Any one aware of this exception. How to fix this issue ? Is that any problem in GZiping ?
Error :
ResponseCode: 500 INTERNAL_SERVER_ERROR, ErrorMessage:ca.uhn.fhir.parser.DataFormatException: Failed to parse JSON encoded API content: Content does not appear to be API JSON, first non-whitespace character was: '<' (must be '{')
Code snippet :
private fun okhttpioConnection(): String {
log.info("Initializing OKHttp-ioConnection")
client = OkHttpClient()
client.setConnectTimeout(600000, TimeUnit.MILLISECONDS)
client.setReadTimeout(600000, TimeUnit.MILLISECONDS)
client.connectionPool = ConnectionPool(300, 20000)
client.retryOnConnectionFailure = true
var request = createRequest(restParams) // GET or POST
var response = client.newCall(request).execute()
var responseCodeString = response.code().toString()
return response.body()!!.string()
}
fun createRequest(restParams: RestParams): Request {
if (restParams.method == "POST") {
return Request.Builder()
.post(RequestBody.create(
MediaType.parse("application/json; charset=utf-8"), restParams.body.toString()))
.header("Authorization", "xxxxxx")
.addHeader("Content-Length",restParams.body.length.toString())
.addHeader("Accept", "application/json, text/json")
.url(restParams.url)
.build()
} else {
return Request.Builder()
.header("Authorization", "xxxxxxx")
.addHeader("Accept", "application/json, text/json")
.url(restParams.url).get()
.build()
}
}```