fix: 调整 pcap webshark 接口
This commit is contained in:
@@ -71,7 +71,6 @@ public class FeignClientConfiguration {
|
|||||||
log.info("[webSharkClient] [url: {}]", url);
|
log.info("[webSharkClient] [url: {}]", url);
|
||||||
return Feign.builder()
|
return Feign.builder()
|
||||||
.encoder(new FormEncoder())
|
.encoder(new FormEncoder())
|
||||||
.decoder(new Fastjson2Decoder())
|
|
||||||
.client(new Http2Client())
|
.client(new Http2Client())
|
||||||
.target(WebSharkClient.class, url);
|
.target(WebSharkClient.class, url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package net.geedge.asw.module.feign.client;
|
package net.geedge.asw.module.feign.client;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import feign.Headers;
|
import feign.Headers;
|
||||||
import feign.Param;
|
import feign.Param;
|
||||||
import feign.RequestLine;
|
import feign.RequestLine;
|
||||||
|
import feign.Response;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -14,5 +14,5 @@ public interface WebSharkClient {
|
|||||||
|
|
||||||
@RequestLine("POST /webshark/upload")
|
@RequestLine("POST /webshark/upload")
|
||||||
@Headers("Content-Type: multipart/form-data")
|
@Headers("Content-Type: multipart/form-data")
|
||||||
JSONObject upload(@Param("fileKey") File file);
|
Response upload(@Param("fileKey") File file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import cn.hutool.core.date.DatePattern;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.net.url.UrlBuilder;
|
import cn.hutool.core.net.url.UrlBuilder;
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import feign.Response;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import net.geedge.asw.common.config.SpringContextUtils;
|
import net.geedge.asw.common.config.SpringContextUtils;
|
||||||
import net.geedge.asw.common.util.*;
|
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 net.geedge.asw.module.runner.service.IPcapService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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);
|
File newFile = FileUtil.copy(pcapFile, FileUtil.file(Constants.TEMP_PATH, uploadFileName), false);
|
||||||
try {
|
try {
|
||||||
WebSharkClient webSharkClient = (WebSharkClient) SpringContextUtils.getBean("webSharkClient");
|
WebSharkClient webSharkClient = (WebSharkClient) SpringContextUtils.getBean("webSharkClient");
|
||||||
JSONObject obj = webSharkClient.upload(newFile);
|
Response obj = webSharkClient.upload(newFile);
|
||||||
|
if (T.ObjectUtil.isNotEmpty(obj) && HttpStatus.resolve(obj.status()).is2xxSuccessful()){
|
||||||
String baseUrl = UrlBuilder.ofHttp(websharkurl)
|
String baseUrl = UrlBuilder.ofHttp(websharkurl)
|
||||||
.addPath("/webshark")
|
.addPath("/webshark")
|
||||||
.toString();
|
.toString();
|
||||||
result.put("fileName", uploadFileName);
|
result.put("fileName", uploadFileName);
|
||||||
result.put("url", baseUrl);
|
result.put("url", baseUrl);
|
||||||
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error(e, "webshark upload pcap error, id: {}", pcap.getId());
|
log.error(e, "webshark upload pcap error, id: {}", pcap.getId());
|
||||||
throw new ASWException(RCode.PCAP_UPLOAD_WEB_SHARK_ERROR);
|
throw new ASWException(RCode.PCAP_UPLOAD_WEB_SHARK_ERROR);
|
||||||
|
|||||||
Reference in New Issue
Block a user