mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
Delete ExternalApiService.java
This commit is contained in:
parent
15a4807567
commit
a7a8170cd5
@@ -1,45 +0,0 @@
|
||||
package com.v2d.document.service;
|
||||
|
||||
import com.v2d.document.config.AppProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
@Service
|
||||
public class ExternalApiService {
|
||||
private final Logger log = LoggerFactory.getLogger(ExternalApiService.class);
|
||||
private final AppProperties props;
|
||||
private final HttpClient http = HttpClient.newHttpClient();
|
||||
|
||||
public ExternalApiService(AppProperties props) {
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
public String callProvider(String jsonPayload) {
|
||||
String key = props.getApiKey();
|
||||
if (key == null || key.isBlank()) {
|
||||
log.warn("External API key is not configured.");
|
||||
throw new IllegalStateException("External API key missing");
|
||||
}
|
||||
|
||||
try {
|
||||
HttpRequest req = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.example.com/endpoint")) // replace with real endpoint
|
||||
.header("Authorization", "Bearer " + key)
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> resp = http.send(req, HttpResponse.BodyHandlers.ofString());
|
||||
return resp.body();
|
||||
} catch (Exception e) {
|
||||
log.error("External API call failed: {}", e.getMessage());
|
||||
throw new RuntimeException("External API call failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user