fix: 调整 pcap webshark 接口

This commit is contained in:
zhangshuai
2024-08-27 10:59:59 +08:00
parent bbbe71ae33
commit 5bae5dfdd3
3 changed files with 12 additions and 11 deletions

View File

@@ -71,7 +71,6 @@ public class FeignClientConfiguration {
log.info("[webSharkClient] [url: {}]", url);
return Feign.builder()
.encoder(new FormEncoder())
.decoder(new Fastjson2Decoder())
.client(new Http2Client())
.target(WebSharkClient.class, url);
}

View File

@@ -1,9 +1,9 @@
package net.geedge.asw.module.feign.client;
import cn.hutool.json.JSONObject;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
import feign.Response;
import org.springframework.cloud.openfeign.FeignClient;
import java.io.File;
@@ -14,5 +14,5 @@ public interface WebSharkClient {
@RequestLine("POST /webshark/upload")
@Headers("Content-Type: multipart/form-data")
JSONObject upload(@Param("fileKey") File file);
Response upload(@Param("fileKey") File file);
}

View File

@@ -4,10 +4,10 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.json.JSONObject;
import cn.hutool.log.Log;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import feign.Response;
import jakarta.servlet.http.HttpServletResponse;
import net.geedge.asw.common.config.SpringContextUtils;
import net.geedge.asw.common.util.*;
@@ -16,6 +16,7 @@ import net.geedge.asw.module.runner.entity.PcapEntity;
import net.geedge.asw.module.runner.service.IPcapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@@ -145,13 +146,14 @@ public class PcapController {
File newFile = FileUtil.copy(pcapFile, FileUtil.file(Constants.TEMP_PATH, uploadFileName), false);
try {
WebSharkClient webSharkClient = (WebSharkClient) SpringContextUtils.getBean("webSharkClient");
JSONObject obj = webSharkClient.upload(newFile);
String baseUrl = UrlBuilder.ofHttp(websharkurl)
.addPath("/webshark")
.toString();
result.put("fileName", uploadFileName);
result.put("url", baseUrl);
Response obj = webSharkClient.upload(newFile);
if (T.ObjectUtil.isNotEmpty(obj) && HttpStatus.resolve(obj.status()).is2xxSuccessful()){
String baseUrl = UrlBuilder.ofHttp(websharkurl)
.addPath("/webshark")
.toString();
result.put("fileName", uploadFileName);
result.put("url", baseUrl);
}
}catch (Exception e){
log.error(e, "webshark upload pcap error, id: {}", pcap.getId());
throw new ASWException(RCode.PCAP_UPLOAD_WEB_SHARK_ERROR);