Browse Source

/*与ZTE联调ivs接口的修改:cookie:JSESSIONID=token,token多出一对双引号,中兴不兼容。*/

master
htjcAdmin 7 months ago
parent
commit
b0616addf4
2 changed files with 21 additions and 10 deletions
  1. +18
    -8
      inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java
  2. +3
    -2
      inspect-ivs/src/main/java/com/inspect/ivs/service/IvsLoginService.java

+ 18
- 8
inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java View File

@ -16,11 +16,8 @@ import java.net.*;
import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
@ -31,8 +28,6 @@ import org.springframework.web.reactive.function.client.WebClient.RequestBodySpe
import javax.annotation.Resource;
import javax.net.ssl.HttpsURLConnection;
import static cn.hutool.poi.excel.sax.AttributeName.t;
@Component
public class IvsCommonService {
private static final Logger log = LoggerFactory.getLogger(IvsCommonService.class);
@ -50,7 +45,7 @@ public class IvsCommonService {
public String getCookie() {
String cookie = redisService.getCacheObject(IvsConst.IVS_TOKEN);
//log.debug("[GAB] cookie: {}", cookie);
log.info(Color.YELLOW + "[IVS] cookie: {}" + Color.END, cookie);
return cookie;
}
@ -70,13 +65,28 @@ public class IvsCommonService {
public <T> T get(String uri, Class<T> clazz) {
String cookie = this.getCookie();
String res = HttpUtil.createGet(getAddress().concat(uri))
.cookie(new HttpCookie[]{new HttpCookie(IvsConst.HTTP_JSESSIONID_SESSION_NAME, cookie)})
//.cookie(new HttpCookie[]{new HttpCookie(IvsConst.HTTP_JSESSIONID_SESSION_NAME, cookie)})
.cookie(IvsConst.HTTP_JSESSIONID_SESSION_NAME.concat("=").concat(cookie))
.execute()
.body();
//log.info("[IVS] GET URI: {}, RES: {}", uri, res);
log.info("[IVS] GET URI: {}, RES: {}", uri, res);
return checkResultCodeAndConvertResult(JSONObject.parseObject(res), clazz);
}
public <T> T getJson(String uri, Class<T> clazz) {
String cookie = this.getCookie();
String res = HttpUtil.createGet(getAddress().concat(uri))
.cookie(new HttpCookie[]{new HttpCookie(IvsConst.HTTP_JSESSIONID_SESSION_NAME, cookie)})
.execute()
.body();
JSONObject t = http(HttpMethod.GET, uri)
.contentType(MediaType.APPLICATION_JSON)
.cookie("JSESSIONID", cookie).retrieve().bodyToMono(JSONObject.class).block();
log.info("[CALL IVS] getJson POST, Response:{}", t.toJSONString());
return this.checkResultCodeAndConvertResult(t, clazz);
}
public JSONObject getResultJson(String uri) {
String cookie = this.getCookie();
JSONObject result = this.http(HttpMethod.GET, uri)


+ 3
- 2
inspect-ivs/src/main/java/com/inspect/ivs/service/IvsLoginService.java View File

@ -1,5 +1,6 @@
package com.inspect.ivs.service;
import com.inspect.base.core.constant.Color;
import com.inspect.base.core.exception.ServiceException;
import com.inspect.ivs.base.feign.domain.IvsResult;
import com.inspect.ivs.config.IvsUserConfig;
@ -93,7 +94,7 @@ public class IvsLoginService extends IvsCommonService {
}
private IvsResult login() {
logger.info("-------------------------ivs user: " + this.queryUser());
logger.info("-------------------------ivs user: {}", this.queryUser());
return this.http(HttpMethod.POST, IvsConst.URI_LOGIN)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(this.queryUser())
@ -101,7 +102,7 @@ public class IvsLoginService extends IvsCommonService {
List<String> header = res.headers().header(IvsConst.COOKIE_KEY);
System.out.println(header.size());
String token = (res.headers().header(IvsConst.COOKIE_KEY).get(0)).split("=")[1].split(";")[0];
logger.debug("===================token:{}", token);
logger.info(Color.YELLOW + "===================ivs token:{}" + Color.END, token);
this.setCookie(token);
return res.bodyToMono(IvsResult.class);
}).block();


Loading…
Cancel
Save