Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Swagger timeout on HTTPS listener (and workaround) #202

Open
marcus-degruttola opened this issue Apr 23, 2019 · 0 comments
Open

Swagger timeout on HTTPS listener (and workaround) #202

marcus-degruttola opened this issue Apr 23, 2019 · 0 comments

Comments

@marcus-degruttola
Copy link

We changed our site so that Play is listening directly to HTTPS (redirecting HTTP to HTTPS). The call to controllers.ApiHelpController.getResources which worked fine from HTTP was now showing huge latency and timeouts on HTTPS. The swagger validation call in the swagger ui would also timeout and report a red error.

The swagger JSON information would return quickly but play would hold the connection open for long periods of time. The issue (probably not a swagger-play issue) seems to be a bad interaction with the JSON stream parser SSL.

Our workaround was to use this...

class MyApiHelpController @Inject() (components: ControllerComponents, configuration: play.api.Configuration)
extends ApiHelpController(components, configuration) {

def wrappedResources = Action {
request =>
implicit val requestHeader: RequestHeader = request
val host: String = if (configuration.underlying.hasPath("swagger.api.host")) configuration.underlying.getString("swagger.api.host") else requestHeader.host
val resourceListing: io.swagger.models.Swagger = getResourceListing(host)
val response: String = returnXml(request) match {
case true => toXmlString(resourceListing)
case false => toJsonString(resourceListing)
}
myReturnValue(request, response)
}

private def myReturnValue(request: Request[_], obj: Any): Result = {
val response = returnXml(request) match {
case true => XmlResponse(obj)
case false => Ok(obj.toString).as("application/json")
}
response.withHeaders(AccessControlAllowOrigin)
}
}

With this change, the swagger ui and swagger validator call became happy (reported green) and the call to MyApiHelpController.wrappedResources returned quickly. JSON stream parsing becomes JSON blob parsing with this change. Again, the problem only happened on the HTTPS listener.

Versions...
"io.swagger" % "swagger-core" % "1.5.22",
"io.swagger" %% "swagger-play2" % "1.6.1",
"com.typesafe.play" % "sbt-plugin" % "2.6.20"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant