jamesnetherton commented on code in PR #8010:
URL: https://github.com/apache/camel-quarkus/pull/8010#discussion_r2568162114


##########
integration-tests/docling/src/test/java/org/apache/camel/quarkus/component/docling/it/DoclingTestResource.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.docling.it;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+public class DoclingTestResource implements 
QuarkusTestResourceLifecycleManager {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(DoclingTestResource.class);
+    private static final String DOCLING_IMAGE = 
"quay.io/docling-project/docling-serve:latest";

Review Comment:
   Please define the container image name as a Maven property in the root 
pom.xml under 
[here](https://github.com/apache/camel-quarkus/blob/main/pom.xml#L229C19-L229C29).
 Then you can use `ConfigProvider` to look it up. See examples in other 
`TestResource` classes.
   
   Also, please pin to a specific tag if possible instead of `latest`.



##########
integration-tests/docling/src/main/java/org/apache/camel/quarkus/component/docling/it/DoclingResource.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.docling.it;
+
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.jboss.logging.Logger;
+
+@Path("/docling")
+@ApplicationScoped
+public class DoclingResource {
+
+    private static final Logger LOG = Logger.getLogger(DoclingResource.class);
+    private static final String COMPONENT_DOCLING = "docling";
+
+    @Inject
+    CamelContext context;
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Path("/load/component/docling")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response loadComponentDocling() throws Exception {
+        if (context.getComponent(COMPONENT_DOCLING) != null) {
+            return Response.ok().build();
+        }
+        LOG.warnf("Could not load [%s] from the Camel context", 
COMPONENT_DOCLING);
+        return Response.status(500, COMPONENT_DOCLING + " could not be loaded 
from the Camel context").build();
+    }
+
+    @Path("/convert/markdown")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response convertToMarkdown(String documentContent) {
+        try {
+            // Create temp file with content
+            java.nio.file.Path tempFile = Files.createTempFile("docling-test", 
".md");
+            Files.write(tempFile, 
documentContent.getBytes(StandardCharsets.UTF_8));
+
+            // Send file path to Camel route
+            String result = 
producerTemplate.requestBody("direct:convertToMarkdown", tempFile.toString(), 
String.class);
+
+            // Clean up temp file
+            Files.deleteIfExists(tempFile);
+
+            return Response.ok(result).build();
+        } catch (Exception e) {
+            LOG.error("Failed to convert to markdown", e);
+            return Response.status(500).entity("Error: " + 
e.getMessage()).build();
+        }
+    }
+
+    @Path("/convert/html")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_HTML)
+    public Response convertToHtml(String documentContent) {
+        try {
+            java.nio.file.Path tempFile = Files.createTempFile("docling-test", 
".md");
+            Files.write(tempFile, 
documentContent.getBytes(StandardCharsets.UTF_8));
+            String result = 
producerTemplate.requestBody("direct:convertToHtml", tempFile.toString(), 
String.class);
+            Files.deleteIfExists(tempFile);
+            return Response.ok(result).build();
+        } catch (Exception e) {
+            LOG.error("Failed to convert to HTML", e);
+            return Response.status(500).entity("Error: " + 
e.getMessage()).build();
+        }
+    }
+
+    @Path("/extract/text")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response extractText(String documentContent) {
+        try {
+            java.nio.file.Path tempFile = Files.createTempFile("docling-test", 
".md");
+            Files.write(tempFile, 
documentContent.getBytes(StandardCharsets.UTF_8));
+            String result = producerTemplate.requestBody("direct:extractText", 
tempFile.toString(), String.class);
+            Files.deleteIfExists(tempFile);
+            return Response.ok(result).build();
+        } catch (Exception e) {
+            LOG.error("Failed to extract text", e);
+            return Response.status(500).entity("Error: " + 
e.getMessage()).build();
+        }
+    }
+
+    @Path("/test/resource")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response testResourceDocument(@QueryParam("name") String 
resourceName) {
+        try {
+            InputStream is = 
getClass().getClassLoader().getResourceAsStream(resourceName);
+            if (is == null) {
+                return Response.status(404).entity("Resource not found: " + 
resourceName).build();
+            }
+            String content = new String(is.readAllBytes(), 
StandardCharsets.UTF_8);
+            return Response.ok(content).build();
+        } catch (Exception e) {
+            LOG.error("Failed to read resource", e);
+            return Response.status(500).entity("Error: " + 
e.getMessage()).build();
+        }

Review Comment:
   ```suggestion
           try (InputStream is = 
getClass().getClassLoader().getResourceAsStream(resourceName)) {
               if (is == null) {
                   return Response.status(404).entity("Resource not found: " + 
resourceName).build();
               }
               String content = new String(is.readAllBytes(), 
StandardCharsets.UTF_8);
               return Response.ok(content).build();
           } catch (Exception e) {
               LOG.error("Failed to read resource", e);
               return Response.status(500).entity("Error: " + 
e.getMessage()).build();
           }
   ```



##########
integration-tests/docling/src/main/java/org/apache/camel/quarkus/component/docling/it/DoclingResource.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.docling.it;
+
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.jboss.logging.Logger;
+
+@Path("/docling")
+@ApplicationScoped
+public class DoclingResource {
+
+    private static final Logger LOG = Logger.getLogger(DoclingResource.class);
+    private static final String COMPONENT_DOCLING = "docling";
+
+    @Inject
+    CamelContext context;
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Path("/load/component/docling")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response loadComponentDocling() throws Exception {
+        if (context.getComponent(COMPONENT_DOCLING) != null) {
+            return Response.ok().build();
+        }
+        LOG.warnf("Could not load [%s] from the Camel context", 
COMPONENT_DOCLING);
+        return Response.status(500, COMPONENT_DOCLING + " could not be loaded 
from the Camel context").build();
+    }
+
+    @Path("/convert/markdown")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response convertToMarkdown(String documentContent) {
+        try {
+            // Create temp file with content
+            java.nio.file.Path tempFile = Files.createTempFile("docling-test", 
".md");
+            Files.write(tempFile, 
documentContent.getBytes(StandardCharsets.UTF_8));
+
+            // Send file path to Camel route
+            String result = 
producerTemplate.requestBody("direct:convertToMarkdown", tempFile.toString(), 
String.class);
+
+            // Clean up temp file
+            Files.deleteIfExists(tempFile);

Review Comment:
   Probably better to move file cleanup into a `finally` block. Same for the 
other JAX-RS methods that do `deleteIfExists `.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to