Преглед изворни кода

修改bug:
增加非空校验

jiakai пре 4 месеци
родитељ
комит
3324af10ee

+ 10 - 0
tenant/insurance/quotation-guoren/src/main/java/com/jzg/quotation/guoren/crawler/component/GuoRenCrawlerRequestComponent.java

@@ -10,6 +10,7 @@ import com.jzg.commons.entity.quote.vo.QuoteVo;
 import com.jzg.commons.entity.quote.vo.image.InsuranceImageVo;
 import com.jzg.commons.entity.quote.vo.image.InsuranceImageVo;
 import com.jzg.commons.exception.SystemException;
 import com.jzg.commons.exception.SystemException;
 import com.jzg.commons.exception.TokenExpireException;
 import com.jzg.commons.exception.TokenExpireException;
+import com.jzg.commons.util.AssertionUtils;
 import com.jzg.commons.util.MinioUtils;
 import com.jzg.commons.util.MinioUtils;
 import com.jzg.commons.util.StringUtils;
 import com.jzg.commons.util.StringUtils;
 import com.jzg.quotation.commons.client.PlatformClient;
 import com.jzg.quotation.commons.client.PlatformClient;
@@ -41,6 +42,8 @@ import org.springframework.util.CollectionUtils;
 import java.io.File;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.List;
 import java.util.List;
 import java.util.Optional;
 import java.util.Optional;
 
 
@@ -118,6 +121,12 @@ public class GuoRenCrawlerRequestComponent {
      */
      */
     public <Response> Response request(RequestUrl requestUrl, Object body, Class<Response> responseClass, HttpHeaders httpHeaders) {
     public <Response> Response request(RequestUrl requestUrl, Object body, Class<Response> responseClass, HttpHeaders httpHeaders) {
         String url = guoRenCrawlerProperties.getBaseUrl() + requestUrl.getUri();
         String url = guoRenCrawlerProperties.getBaseUrl() + requestUrl.getUri();
+        // 校验是否为合法 URL
+        try {
+            new URL(url);
+        } catch (MalformedURLException e) {
+            return null;
+        }
         ResponseEntity<Response> responseResponseEntity = requestComponent.objectPost(url, body, responseClass, httpHeaders);
         ResponseEntity<Response> responseResponseEntity = requestComponent.objectPost(url, body, responseClass, httpHeaders);
         return responseResponseEntity.getBody();
         return responseResponseEntity.getBody();
     }
     }
@@ -132,6 +141,7 @@ public class GuoRenCrawlerRequestComponent {
     public IdentifyCodeDataResponse identifyCode(String username) {
     public IdentifyCodeDataResponse identifyCode(String username) {
         GuoRenCrawlerIdentifyCodeRequest identifyCodeRequest = new GuoRenCrawlerIdentifyCodeRequest(username);
         GuoRenCrawlerIdentifyCodeRequest identifyCodeRequest = new GuoRenCrawlerIdentifyCodeRequest(username);
         IdentifyCodeDataResponse request = request(RequestUrl.IDENTIFY_CODE, identifyCodeRequest, IdentifyCodeDataResponse.class, new HttpHeaders());
         IdentifyCodeDataResponse request = request(RequestUrl.IDENTIFY_CODE, identifyCodeRequest, IdentifyCodeDataResponse.class, new HttpHeaders());
+        AssertionUtils.isEmpty(request, "验证码请求失败,未获取到验证码编号");
         if (request.getResultCode() != 0) {
         if (request.getResultCode() != 0) {
             throw new SystemException(request.getResultMsg());
             throw new SystemException(request.getResultMsg());
         }
         }

+ 6 - 0
tenant/insurance/quotation-zhongan/src/main/java/com/jzg/quotation/zhongan/crawler/component/ZhongAnCrawlerCacheComponent.java

@@ -2,6 +2,7 @@ package com.jzg.quotation.zhongan.crawler.component;
 
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.JSONObject;
+import com.jzg.commons.util.AssertionUtils;
 import com.jzg.quotation.zhongan.crawler.client.LoginResult;
 import com.jzg.quotation.zhongan.crawler.client.LoginResult;
 import com.jzg.quotation.zhongan.crawler.entity.request.ZhongAnCrawlerQueryInitInfoRequest;
 import com.jzg.quotation.zhongan.crawler.entity.request.ZhongAnCrawlerQueryInitInfoRequest;
 import com.jzg.quotation.zhongan.crawler.entity.response.ZhongAnCrawlerPaymentResponse;
 import com.jzg.quotation.zhongan.crawler.entity.response.ZhongAnCrawlerPaymentResponse;
@@ -145,26 +146,31 @@ public class ZhongAnCrawlerCacheComponent {
             // 发送第一个请求,不跟随重定向
             // 发送第一个请求,不跟随重定向
             HttpGet get1 = buildGet(uri1);
             HttpGet get1 = buildGet(uri1);
             CloseableHttpResponse resp1 = HTTP_CLIENT.execute(get1, context);
             CloseableHttpResponse resp1 = HTTP_CLIENT.execute(get1, context);
+            AssertionUtils.isEmpty(resp1, "第一次请求失败,请联系管理员");
             String location1 = resp1.getFirstHeader("Location").getValue();
             String location1 = resp1.getFirstHeader("Location").getValue();
             resp1.close();
             resp1.close();
             // 发送第二个请求
             // 发送第二个请求
             HttpGet get2 = buildGet(new URI(location1));
             HttpGet get2 = buildGet(new URI(location1));
             CloseableHttpResponse resp2 = HTTP_CLIENT.execute(get2, context);
             CloseableHttpResponse resp2 = HTTP_CLIENT.execute(get2, context);
+            AssertionUtils.isEmpty(resp2, "第二次请求失败,请联系管理员");
             String location2 = getLocationHeader(resp2);
             String location2 = getLocationHeader(resp2);
             resp2.close();
             resp2.close();
             // 发送第三个请求
             // 发送第三个请求
             HttpGet get3 = buildGet(new URI(location2));
             HttpGet get3 = buildGet(new URI(location2));
             CloseableHttpResponse resp3 = HTTP_CLIENT.execute(get3, context);
             CloseableHttpResponse resp3 = HTTP_CLIENT.execute(get3, context);
+            AssertionUtils.isEmpty(resp3, "第三次请求失败,请联系管理员");
             String location3 = resp3.getFirstHeader("Location").getValue();
             String location3 = resp3.getFirstHeader("Location").getValue();
             resp3.close();
             resp3.close();
             // 发送第四个请求
             // 发送第四个请求
             HttpGet get4 = buildGet(new URI(location3));
             HttpGet get4 = buildGet(new URI(location3));
             CloseableHttpResponse resp4 = HTTP_CLIENT.execute(get4, context);
             CloseableHttpResponse resp4 = HTTP_CLIENT.execute(get4, context);
+            AssertionUtils.isEmpty(resp4, "第四次请求失败,请联系管理员");
             String location4 = resp4.getFirstHeader("Location").getValue();
             String location4 = resp4.getFirstHeader("Location").getValue();
             resp4.close();
             resp4.close();
             // 第五次请求,拿cookie
             // 第五次请求,拿cookie
             HttpGet get5 = buildGet(new URI(location4));
             HttpGet get5 = buildGet(new URI(location4));
             CloseableHttpResponse resp5 = HTTP_CLIENT.execute(get5, context);
             CloseableHttpResponse resp5 = HTTP_CLIENT.execute(get5, context);
+            AssertionUtils.isEmpty(resp5, "第五次请求失败,请联系管理员");
             String location5 = resp5.getFirstHeader("Location").getValue();
             String location5 = resp5.getFirstHeader("Location").getValue();
             // 提取 zaLoginCookieKey
             // 提取 zaLoginCookieKey
             String cookieKey = null;
             String cookieKey = null;