From f6415d06e54b4eda3190167b49258b9f1ade6fc7 Mon Sep 17 00:00:00 2001 From: greysonfang Date: Mon, 13 Nov 2023 15:15:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=94=AF=E6=8C=81=E5=85=B3?= =?UTF-8?q?=E8=81=94=E8=BF=90=E8=90=A5=E4=BA=A7=E5=93=81=E5=92=8C=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E8=BF=90=E8=90=A5=E4=BA=A7=E5=93=81=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=20#9636?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/auth/service/ItsmService.kt | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/backend/ci/core/auth/biz-auth-rbac/src/main/kotlin/com/tencent/devops/auth/service/ItsmService.kt b/src/backend/ci/core/auth/biz-auth-rbac/src/main/kotlin/com/tencent/devops/auth/service/ItsmService.kt index c9e716ae5a6..bce8773043e 100644 --- a/src/backend/ci/core/auth/biz-auth-rbac/src/main/kotlin/com/tencent/devops/auth/service/ItsmService.kt +++ b/src/backend/ci/core/auth/biz-auth-rbac/src/main/kotlin/com/tencent/devops/auth/service/ItsmService.kt @@ -1,6 +1,6 @@ package com.tencent.devops.auth.service -import com.fasterxml.jackson.databind.JavaType +import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.bk.sdk.iam.dto.itsm.ItsmAttrs import com.tencent.bk.sdk.iam.dto.itsm.ItsmColumn @@ -39,14 +39,9 @@ class ItsmService @Autowired constructor( private val itsmUrlPrefix: String = "" fun cancelItsmApplication(itsmCancelApplicationInfo: ItsmCancelApplicationInfo): Boolean { - val responseType = objectMapper.typeFactory.constructParametricType( - ResponseDTO::class.java, - objectMapper.typeFactory.constructParametricType(List::class.java, Any::class.java) - ) val itsmResponseDTO: ResponseDTO> = executeHttpPost( urlSuffix = ITSM_APPLICATION_CANCEL_URL_SUFFIX, - body = itsmCancelApplicationInfo, - responseType = responseType + body = itsmCancelApplicationInfo ) if (itsmResponseDTO.message != "success") { logger.warn("cancel itsm application failed!$itsmCancelApplicationInfo") @@ -61,11 +56,7 @@ class ItsmService @Autowired constructor( fun verifyItsmToken(token: String) { val param = mapOf("token" to token) - val responseType = objectMapper.typeFactory.constructParametricType( - ResponseDTO::class.java, - objectMapper.typeFactory.constructParametricType(Map::class.java, Any::class.java, Any::class.java) - ) - val itsmResponseDTO: ResponseDTO> = executeHttpPost(ITSM_TOKEN_VERITY_URL_SUFFIX, param, responseType) + val itsmResponseDTO: ResponseDTO> = executeHttpPost(ITSM_TOKEN_VERITY_URL_SUFFIX, param) val itsmApiResData = itsmResponseDTO.data logger.info("itsmApiResData:$itsmApiResData") @@ -79,16 +70,12 @@ class ItsmService @Autowired constructor( } fun getItsmTicketStatus(sn: String): String { - val responseType = objectMapper.typeFactory.constructParametricType( - ResponseDTO::class.java, - objectMapper.typeFactory.constructParametricType(Map::class.java, Any::class.java, Any::class.java) - ) val itsmResponseDTO: ResponseDTO> = - executeHttpGet(String.format(ITSM_TICKET_STATUS_URL_SUFFIX, sn), responseType) + executeHttpGet(String.format(ITSM_TICKET_STATUS_URL_SUFFIX, sn)) return itsmResponseDTO.data?.get("current_status").toString() } - private fun executeHttpPost(urlSuffix: String, body: Any, responseType: JavaType): ResponseDTO { + private fun executeHttpPost(urlSuffix: String, body: Any): ResponseDTO { val headerStr = objectMapper.writeValueAsString(mapOf("bk_app_code" to appCode, "bk_app_secret" to appSecret)) .replace("\\s".toRegex(), "") val requestBody = objectMapper.writeValueAsString(body) @@ -100,10 +87,10 @@ class ItsmService @Autowired constructor( .post(requestBody) .addHeader("x-bkapi-authorization", headerStr) .build() - return executeHttpRequest(url, request, responseType) + return executeHttpRequest(url, request) } - private fun executeHttpGet(urlSuffix: String, responseType: JavaType): ResponseDTO { + private fun executeHttpGet(urlSuffix: String): ResponseDTO { val headerStr = objectMapper.writeValueAsString(mapOf("bk_app_code" to appCode, "bk_app_secret" to appSecret)) .replace("\\s".toRegex(), "") val url = itsmUrlPrefix + urlSuffix @@ -112,17 +99,18 @@ class ItsmService @Autowired constructor( .addHeader("x-bkapi-authorization", headerStr) .get() .build() - return executeHttpRequest(url, request, responseType) + return executeHttpRequest(url, request) } - private fun executeHttpRequest(url: String, request: Request, responseType: JavaType): ResponseDTO { + private fun executeHttpRequest(url: String, request: Request): ResponseDTO { OkhttpUtils.doHttp(request).use { if (!it.isSuccessful) { logger.warn("request failed, uri:($url)|response: ($it)") throw RemoteServiceException("request failed, response:($it)") } val responseStr = it.body!!.string() - val responseDTO: ResponseDTO = objectMapper.readValue(responseStr, responseType) + val responseDTO: ResponseDTO = + objectMapper.readValue(responseStr, object : TypeReference>() {}) if (responseDTO.code != 0L || !responseDTO.result) { // 请求错误 logger.warn("request failed, url:($url)|response:($it)")