Skip to content

Commit

Permalink
http (feature): Fallback to Java8 compatible URLConnectionChannel if …
Browse files Browse the repository at this point in the history
…Java's HttpClient is unavailable (#3478)
  • Loading branch information
xerial authored Apr 8, 2024
1 parent 6c783a4 commit 1f70229
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ package wvlet.airframe.http.client
import wvlet.airframe.http.{ServerAddress}

object JavaHttpClientBackend extends HttpClientBackend {
private val isJava8: Boolean = sys.props.get("java.version").exists(_.startsWith("1.8"))

override def newHttpChannel(serverAddress: ServerAddress, config: HttpClientConfig): HttpChannel = {
new JavaHttpClientChannel(serverAddress, config)
// For JDK8, use URLConnectionChannel
if (isJava8)
new URLConnectionChannel(serverAddress, config)
else
new JavaHttpClientChannel(serverAddress, config)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import java.util.zip.{GZIPInputStream, InflaterInputStream}
import scala.concurrent.duration.Duration
import scala.jdk.CollectionConverters.*

/**
* Java8-compatible HTTP channel implementation based on {{URL.openConnection}}
* @param serverAddress
* @param config
*/
class URLConnectionChannel(serverAddress: ServerAddress, config: HttpClientConfig) extends HttpChannel {
override def send(request: Request, channelConfig: HttpChannelConfig): Response = {
val url = s"${serverAddress.uri}${if (request.uri.startsWith("/")) request.uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import wvlet.airframe.http.{ServerAddress}

/**
*/
@deprecated("This backend will be used automatically for Java8. No need to explicitly set this backend", "24.4.0")
object URLConnectionClientBackend extends HttpClientBackend {
override def newHttpChannel(serverAddress: ServerAddress, config: HttpClientConfig): HttpChannel = {
new URLConnectionChannel(serverAddress, config)
Expand Down

0 comments on commit 1f70229

Please sign in to comment.