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/07 15:19:36 UTC

[GitHub] [incubator-streampark] wolfboys opened a new pull request, #2733: [improve] Upgrade httpclient version to 5.1

wolfboys opened a new pull request, #2733:
URL: https://github.com/apache/incubator-streampark/pull/2733

   [improve] Upgrade httpclient version to 5.1


-- 
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


[GitHub] [incubator-streampark] zhoulii commented on pull request #2733: [improve] Upgrade httpclient version to 5.1

Posted by "zhoulii (via GitHub)" <gi...@apache.org>.
zhoulii commented on PR #2733:
URL: https://github.com/apache/incubator-streampark/pull/2733#issuecomment-1537660839

   Deployed and tested with yarn `application/session/perjob` execution mode, no bug was found, so LGTM.


-- 
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


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

Posted by "wolfboys (via GitHub)" <gi...@apache.org>.
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


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

Posted by "wolfboys (via GitHub)" <gi...@apache.org>.
wolfboys commented on PR #2733:
URL: https://github.com/apache/incubator-streampark/pull/2733#issuecomment-1537743873

   > Deployed and tested with yarn `application/session/perjob` execution mode, no bug was found, so LGTM.
   
   thanks for your review and test.


-- 
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


[GitHub] [incubator-streampark] wangsizhu0504 merged pull request #2733: [improve] Upgrade httpclient version to 5.1

Posted by "wangsizhu0504 (via GitHub)" <gi...@apache.org>.
wangsizhu0504 merged PR #2733:
URL: https://github.com/apache/incubator-streampark/pull/2733


-- 
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


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

Posted by "zhoulii (via GitHub)" <gi...@apache.org>.
zhoulii commented on code in PR #2733:
URL: https://github.com/apache/incubator-streampark/pull/2733#discussion_r1186957209


##########
streampark-common/src/main/scala/org/apache/streampark/common/util/HttpClientUtils.scala:
##########
@@ -16,23 +16,23 @@
  */
 package org.apache.streampark.common.util
 
-import org.apache.http.NameValuePair
-import org.apache.http.auth.{AuthSchemeProvider, AuthScope, Credentials}
-import org.apache.http.client.config.{AuthSchemes, RequestConfig}
-import org.apache.http.client.entity.UrlEncodedFormEntity
-import org.apache.http.client.methods._
-import org.apache.http.client.utils.URIBuilder
-import org.apache.http.config.RegistryBuilder
-import org.apache.http.entity.StringEntity
-import org.apache.http.impl.auth.SPNegoSchemeFactory
-import org.apache.http.impl.client.{BasicCredentialsProvider, CloseableHttpClient, HttpClientBuilder, HttpClients}
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager
-import org.apache.http.message.BasicNameValuePair
-import org.apache.http.util.EntityUtils
+import org.apache.hadoop.shaded.org.apache.http.client.config.AuthSchemes

Review Comment:
   We'd better not use reference from `hadoop.shaded` package.



##########
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.



-- 
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