|
|
|
@ -4,10 +4,14 @@ import jakarta.annotation.PostConstruct;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.http.*;
|
|
|
|
import org.springframework.http.*;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
|
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.*;
|
|
|
|
import javax.net.ssl.*;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
@ -23,6 +27,9 @@ public class ExternalAuthService {
|
|
|
|
@Value("${external.auth.edge-search-url}")
|
|
|
|
@Value("${external.auth.edge-search-url}")
|
|
|
|
private String edgeSearchUrl;
|
|
|
|
private String edgeSearchUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${external.edge.add-url:https://cuuva.com:24443/api/datamanager/edge-pkg/add}")
|
|
|
|
|
|
|
|
private String edgeAddUrl;
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
public void init() {
|
|
|
|
public void init() {
|
|
|
|
this.restTemplate = createUnsafeRestTemplate();
|
|
|
|
this.restTemplate = createUnsafeRestTemplate();
|
|
|
|
@ -102,4 +109,33 @@ public class ExternalAuthService {
|
|
|
|
|
|
|
|
|
|
|
|
throw new RuntimeException("Failed to fetch edge package list");
|
|
|
|
throw new RuntimeException("Failed to fetch edge package list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Object uploadEdgePackage(String bearerToken, String edgePkgInfoJson, MultipartFile file) throws IOException {
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
|
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
|
|
|
|
|
headers.set("Authorization", bearerToken.startsWith("Bearer ") ? bearerToken : "Bearer " + bearerToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
|
|
|
|
|
|
|
body.add("edgePkgInfoVO", edgePkgInfoJson);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (file != null && !file.isEmpty()) {
|
|
|
|
|
|
|
|
body.add("file", new org.springframework.core.io.ByteArrayResource(file.getBytes()) {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getFilename() {
|
|
|
|
|
|
|
|
return file.getOriginalFilename();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(body, headers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResponseEntity<Object> response = restTemplate.exchange(
|
|
|
|
|
|
|
|
edgeAddUrl,
|
|
|
|
|
|
|
|
HttpMethod.POST,
|
|
|
|
|
|
|
|
request,
|
|
|
|
|
|
|
|
Object.class
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response.getBody();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|