Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docling-serve/docling-serve-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ description = "Docling Serve Client"

dependencies {
api(project(":docling-serve-api"))
api(libs.slf4j.api)
implementation(platform(libs.jackson.bom))
implementation(libs.jackson.databind)
implementation(libs.jackson2.databind)

testImplementation(platform(libs.testcontainers.bom))
testImplementation(libs.testcontainers.junit.jupiter)
testImplementation(project(":docling-testcontainers"))
testImplementation(libs.slf4j.simple)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Flow.Subscriber;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ai.docling.serve.api.DoclingServeApi;
import ai.docling.serve.api.chunk.request.HierarchicalChunkDocumentRequest;
Expand All @@ -37,7 +38,7 @@
* {@link #writeValueAsString(Object)} for serialization and deserialization behavior.
*/
public abstract class DoclingServeClient implements DoclingServeApi {
private static final Logger LOG = Logger.getLogger(DoclingServeClient.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(DoclingServeClient.class);
protected static final URI DEFAULT_BASE_URL = URI.create("http://localhost:5001");

private final URI baseUrl;
Expand Down Expand Up @@ -82,7 +83,7 @@ protected DoclingServeClient(DoclingServeClientBuilder builder) {
protected abstract <T> String writeValueAsString(T value);

protected void logRequest(HttpRequest request) {
if (LOG.isLoggable(Level.INFO)) {
if (LOG.isInfoEnabled()) {
var stringBuilder = new StringBuilder();
stringBuilder.append("\n→ REQUEST: %s %s\n".formatted(request.method(), request.uri()));
stringBuilder.append(" HEADERS:\n");
Expand All @@ -96,7 +97,7 @@ protected void logRequest(HttpRequest request) {
}

protected void logResponse(HttpResponse<String> response, Optional<String> responseBody) {
if (LOG.isLoggable(Level.INFO)) {
if (LOG.isInfoEnabled()) {
var stringBuilder = new StringBuilder();
stringBuilder.append("\n← RESPONSE: %s\n".formatted(response.statusCode()));
stringBuilder.append(" HEADERS:\n");
Expand Down Expand Up @@ -124,7 +125,7 @@ protected <T> T execute(HttpRequest request, Class<T> expectedValueType) {
}
finally {
long duration = System.currentTimeMillis() - startTime;
LOG.info(() -> "Request [%s %s] took %d ms".formatted(request.method(), request.uri(), duration));
LOG.info("Request [{} {}] took {}ms", request.method(), request.uri(), duration);
}
}

Expand Down Expand Up @@ -198,7 +199,7 @@ public long contentLength() {
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
if (logRequests) {
LOG.info(() -> "→ REQUEST BODY: %s".formatted(this.stringContent));
LOG.info("→ REQUEST BODY: {}", this.stringContent);
}

this.delegate.subscribe(subscriber);
Expand Down
2 changes: 2 additions & 0 deletions docling-testcontainers/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description = "Testcontainers for Docling services"
dependencies {
api(platform(libs.testcontainers.bom))
api("org.testcontainers:testcontainers")
api(libs.slf4j.api)
testImplementation(platform(libs.jackson.bom))
testImplementation(libs.jackson.databind)
testImplementation(libs.testcontainers.junit.jupiter)
testImplementation(libs.slf4j.simple)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ai.docling.testcontainers.serve;

import java.util.logging.Logger;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
Expand All @@ -18,7 +20,7 @@
* health checks for the container.
*/
public class DoclingServeContainer extends GenericContainer<DoclingServeContainer> {
private static final Logger LOG = Logger.getLogger(DoclingServeContainer.class.getName());
private static final Logger LOG = LoggerFactory.getLogger(DoclingServeContainer.class);

/**
* The default container port that docling runs on
Expand Down Expand Up @@ -66,21 +68,20 @@ public int getPort() {
* The URL where to access the Docling Serve API.
*/
public String getApiUrl() {
return "http://" + getHost() + ":" + getPort();
return "http://%s:%d".formatted(getHost(), getPort());
}

/**
* The URL where to access the Docling Serve UI, if enabled.
*/
public String getUiUrl() {
return getApiUrl() + "/ui";
public Optional<String> getUiUrl() {
return this.config.enableUi() ?
Optional.of("%s/ui".formatted(getApiUrl())) :
Optional.empty();
}

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
if (config.enableUi()) {
LOG.info(() -> "Docling Serve UI: %s".formatted(getUiUrl()));
}
getUiUrl().ifPresent(url -> LOG.info("Docling Serve UI: {}", url));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ private record HealthResponse(String status) {}
.build()
);

@Container
private final DoclingServeContainer noUiDoclingContainer = new DoclingServeContainer(
DoclingServeContainerConfig.builder()
.image(DoclingServeContainerConfig.DOCLING_IMAGE)
.enableUi(false)
.build()
);

@Test
void containerAvailable() throws IOException, InterruptedException {
var healthRequest = HttpRequest.newBuilder(
URI.create("%s/health".formatted(this.doclingContainer.getApiUrl()))
)
void containerNoUI() throws IOException, InterruptedException {
var healthRequest = HttpRequest.newBuilder(URI.create("%s/health".formatted(this.noUiDoclingContainer.getApiUrl())))
.header("Accept", "application/json")
.timeout(Duration.ofSeconds(10))
.GET()
Expand All @@ -49,8 +55,31 @@ void containerAvailable() throws IOException, InterruptedException {
.usingRecursiveComparison()
.isEqualTo(new HealthResponse("ok"));

assertThat(this.noUiDoclingContainer.getUiUrl())
.isNotNull()
.isEmpty();
}

@Test
void containerAvailable() throws IOException, InterruptedException {
var healthRequest = HttpRequest.newBuilder(URI.create("%s/health".formatted(this.doclingContainer.getApiUrl())))
.header("Accept", "application/json")
.timeout(Duration.ofSeconds(10))
.GET()
.build();

var response = HttpClient.newHttpClient()
.send(healthRequest, jsonBodyHandler(DoclingServeContainerAvailableTests.HealthResponse.class))
.body();

assertThat(response)
.isNotNull()
.usingRecursiveComparison()
.isEqualTo(new HealthResponse("ok"));

assertThat(this.doclingContainer.getUiUrl())
.isEqualTo(this.doclingContainer.getApiUrl() + "/ui");
.get()
.isEqualTo("%s/ui".formatted(this.doclingContainer.getApiUrl()));
}

private static <T> HttpResponse.BodyHandler<T> jsonBodyHandler(Class<T> type) {
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ junit = "6.0.1"
lombok = "1.18.42"
lombok-gradle = "9.1.0"
semver4j = "6.0.0"
slf4j = "2.0.17"
testcontainers = "2.0.2"
quarkus = "3.30.2"
quarkus-github-api = "1.330.0"
Expand Down Expand Up @@ -35,6 +36,10 @@ junit-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit" }
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter" }
junit-platform = { group = "org.junit.platform", name = "junit-platform-launcher" }

# SLF4j
slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }

# Testcontainers
testcontainers-bom = { group = "org.testcontainers", name = "testcontainers-bom", version.ref = "testcontainers"}
testcontainers-junit-jupiter = { group = "org.testcontainers", name = "testcontainers-junit-jupiter" }
Expand Down