Skip to content

Commit

Permalink
PATCH call not proxied correctly to active node (#6475) (#6522)
Browse files Browse the repository at this point in the history
Summary: added a workaround for http methods unsupported by java

JIRA issues: MARATHON-8095

(cherry picked from commit deac8cd)
  • Loading branch information
meln1k committed Sep 11, 2018
1 parent a3c1055 commit aabf743
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -105,7 +105,7 @@ class JavaUrlConnectionRequestForwarder(
}

private def copyRequestToConnection(leaderConnection: HttpURLConnection, request: HttpServletRequest): Try[Done] = Try {
leaderConnection.setRequestMethod(request.getMethod)
HttpUrlConnectionWorkaround.setMethod(leaderConnection, request.getMethod)
copyRequestHeadersToConnection(leaderConnection, request)
copyRequestBodyToConnection(leaderConnection, request)
Done
Expand Down Expand Up @@ -214,3 +214,18 @@ object JavaUrlConnectionRequestForwarder extends StrictLogging {
}
}
}

/**
* Workaround to overcome Java restrictions; see https://bugs.openjdk.java.net/browse/JDK-7016595
*/
private[forwarder] object HttpUrlConnectionWorkaround {
private val methodsField = classOf[HttpURLConnection].getDeclaredField("method")
methodsField.setAccessible(true)

def setMethod(connection: HttpURLConnection, method: String): Unit = {
if (method == "PATCH")
methodsField.set(connection, method)
else
connection.setRequestMethod(method)
}
}

0 comments on commit aabf743

Please sign in to comment.