You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@streampark.apache.org by "wolfboys (via GitHub)" <gi...@apache.org> on 2023/05/08 02:41:55 UTC

[GitHub] [incubator-streampark] wolfboys commented on a diff in pull request #2733: [improve] Upgrade httpclient version to 5.1

wolfboys commented on code in PR #2733:
URL: https://github.com/apache/incubator-streampark/pull/2733#discussion_r1186977379


##########
streampark-common/src/main/scala/org/apache/streampark/common/util/HttpClientUtils.scala:
##########
@@ -97,83 +98,47 @@ object HttpClientUtils {
     getHttpResult(httpPost)
   }
 
-  def httpPatchRequest(url: String): String = {
-    val httpPatch = new HttpPatch(url)
-    getHttpResult(httpPatch)
-  }
-
-  def httpPostRequest(url: String, params: util.Map[String, AnyRef]): String = {
+  def httpPostRequest(url: String, params: JavaMap[String, AnyRef]): String = {
     val httpPost = new HttpPost(url)
     httpPost.setEntity(new UrlEncodedFormEntity(paramsToNameValuePairs(params), defaultChart))
     getHttpResult(httpPost)
   }
 
-  def httpPatchRequest(url: String, params: util.Map[String, AnyRef]): String = {
-    val httpPatch = new HttpPatch(url)
-    httpPatch.setEntity(new UrlEncodedFormEntity(paramsToNameValuePairs(params), defaultChart))
-    getHttpResult(httpPatch)
-  }
-
-  def httpPostRequest(url: String, params: String): String = httpRequest(new HttpPost(url), params)
-
-  def httpPatchRequest(url: String, params: String): String =
-    httpRequest(new HttpPatch(url), params)
-
   def httpPostRequest(
       url: String,
-      params: util.Map[String, AnyRef],
-      headers: util.Map[String, AnyRef] = Map.empty[String, AnyRef]): String = {
+      params: JavaMap[String, AnyRef],
+      headers: JavaMap[String, AnyRef] = Map.empty[String, AnyRef]): String = {
     httpRequest(new HttpPost(url), headers, params)
   }
 
-  def httpPatchRequest(
-      url: String,
-      params: util.Map[String, AnyRef],
-      headers: util.Map[String, AnyRef] = Map.empty[String, AnyRef]): String = {
-    httpRequest(new HttpPatch(url), headers, params)
-  }
-
   private[this] def httpRequest(
-      httpEntity: HttpEntityEnclosingRequestBase,
-      params: String): String = {
-    val entity = new StringEntity(params, defaultChart)
-    entity.setContentEncoding("UTF-8")
-    entity.setContentType("application/json")
-    httpEntity.setEntity(entity)
-    getHttpResult(httpEntity)
-  }
-
-  private[this] def httpRequest(
-      httpPatch: HttpEntityEnclosingRequestBase,
-      headers: util.Map[String, AnyRef],
-      params: util.Map[String, AnyRef]) = {
-    headers.entrySet.foreach(p => httpPatch.addHeader(p.getKey, String.valueOf(p.getValue)))
-    httpPatch.setEntity(new UrlEncodedFormEntity(paramsToNameValuePairs(params), defaultChart))
-    getHttpResult(httpPatch)
+      httpUri: HttpUriRequestBase,
+      headers: JavaMap[String, AnyRef],
+      params: JavaMap[String, AnyRef]) = {
+    headers.entrySet.foreach(p => httpUri.addHeader(p.getKey, String.valueOf(p.getValue)))
+    httpUri.setEntity(new UrlEncodedFormEntity(paramsToNameValuePairs(params), defaultChart))
+    getHttpResult(httpUri)
   }
 
   private[this] def paramsToNameValuePairs(
-      params: util.Map[String, AnyRef]): util.List[NameValuePair] = {
-    val pairs = new util.ArrayList[NameValuePair]
-    params.entrySet.foreach(
-      p => pairs.add(new BasicNameValuePair(p.getKey, String.valueOf(p.getValue))))
-    pairs
+      params: JavaMap[String, AnyRef]): JavaList[NameValuePair] = {
+    params.entrySet.map(p => new BasicNameValuePair(p.getKey, p.getValue.toString)).toList
   }
 
   def httpAuthGetRequest(url: String, config: RequestConfig): String = {
     def getHttpAuthClient: CloseableHttpClient = {
       val credentialsProvider = new BasicCredentialsProvider
-      credentialsProvider.setCredentials(
-        new AuthScope(null, -1, null),
-        new Credentials {
-          override def getUserPrincipal: Principal = null
 
-          override def getPassword: String = null
-        })
+      val credentials = new Credentials() {
+        def getPassword: Array[Char] = null
+        def getUserPrincipal: Principal = null
+      }
+
+      credentialsProvider.setCredentials(new AuthScope(null, -1), credentials)
 
       val authSchemeRegistry = RegistryBuilder
-        .create[AuthSchemeProvider]
-        .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true))
+        .create[AuthSchemeFactory]
+        .register(AuthSchemes.SPNEGO, SPNegoSchemeFactory.DEFAULT)

Review Comment:
   > `AuthSchemes` is removed in 5.1, we can use `StandardAuthScheme` instead.
   
   Thanks for your review, I'll update it later



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@streampark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org