Merge commit 'bd90b34c42bdd5f55ae296f32d978e3224535c17' into HEAD

This commit is contained in:
Jenkins 2024-04-25 12:39:09 +02:00
commit da6d4ee13f

@ -6,9 +6,10 @@ import se.su.dsv.scipro.file.FileDescription;
import se.su.dsv.scipro.file.FileService;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URI;
@ -31,15 +32,13 @@ import java.util.concurrent.Flow;
public class UrkundApiImpl implements UrkundApi {
private final ObjectMapper objectMapper;
private final HttpClient client;
private final UrkundSettingsRepository urkundSettingsRepository;
private final FileService fileService;
@Inject
UrkundApiImpl(final Provider<UrkundSettings> urkundSettings, FileService fileService) {
UrkundApiImpl(final UrkundSettingsRepository urkundSettingsRepository, FileService fileService) {
this.urkundSettingsRepository = urkundSettingsRepository;
this.fileService = fileService;
client = HttpClient.newBuilder()
.authenticator(new UrkundAuthenticator(urkundSettings))
.build();
objectMapper = new ObjectMapper();
objectMapper.findAndRegisterModules();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@ -99,10 +98,16 @@ public class UrkundApiImpl implements UrkundApi {
}
private <A> A sendToUrkund_(final HttpRequest request, final FailingFunction<HttpResponse<InputStream>, A> f) {
UrkundSettings urkundSettings = urkundSettingsRepository.getSettings();
HttpClient client = HttpClient.newBuilder()
.authenticator(new UrkundAuthenticator(urkundSettings))
.build();
try {
final HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
return f.apply(response);
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
@ -129,15 +134,14 @@ public class UrkundApiImpl implements UrkundApi {
}
private static class UrkundAuthenticator extends Authenticator {
private final Provider<UrkundSettings> urkundSettings;
private final UrkundSettings settings;
public UrkundAuthenticator(Provider<UrkundSettings> urkundSettings) {
this.urkundSettings = urkundSettings;
public UrkundAuthenticator(UrkundSettings settings) {
this.settings = settings;
}
@Override
protected PasswordAuthentication getPasswordAuthentication() {
final UrkundSettings settings = urkundSettings.get();
return new PasswordAuthentication(settings.getUsername(), settings.getPassword().toCharArray());
}
}