From 94aba370e09c522fef965d85c74dd0e954e2d872 Mon Sep 17 00:00:00 2001 From: sbplat <71648843+sbplat@users.noreply.github.com> Date: Fri, 29 Dec 2023 13:05:01 -0500 Subject: [PATCH 1/2] refactor: expose local application server port --- .../software/SPDF/SPdfApplication.java | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index 5dd7fed3..73142f3e 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -16,7 +16,7 @@ import stirling.software.SPDF.utils.GeneralUtils; //@EnableScheduling public class SPdfApplication { - + @Autowired private Environment env; @@ -28,11 +28,7 @@ public class SPdfApplication { if (browserOpen) { try { - String port = env.getProperty("local.server.port"); - if(port == null || port.length() == 0) { - port="8080"; - } - String url = "http://localhost:" + port; + String url = "http://localhost:" + getPort(); String os = System.getProperty("os.name").toLowerCase(); Runtime rt = Runtime.getRuntime(); @@ -45,7 +41,7 @@ public class SPdfApplication { } } } - + public static void main(String[] args) { SpringApplication app = new SpringApplication(SPdfApplication.class); app.addInitializers(new ConfigInitializer()); @@ -55,28 +51,28 @@ public class SPdfApplication { System.out.println("External configuration file 'configs/settings.yml' does not exist. Using default configuration and environment configuration instead."); } app.run(args); - + try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } - + GeneralUtils.createDir("customFiles/static/"); GeneralUtils.createDir("customFiles/templates/"); - - - + System.out.println("Stirling-PDF Started."); - - String port = System.getProperty("local.server.port"); - if(port == null || port.length() == 0) { - port="8080"; - } - String url = "http://localhost:" + port; + + String url = "http://localhost:" + getPort(); System.out.println("Navigate to " + url); } - - -} \ No newline at end of file + + public static String getPort() { + String port = System.getProperty("local.server.port"); + if (port == null || port.isEmpty()) { + port = "8080"; + } + return port; + } +} From 34b4ae0e0387826ea6a2dd7299e738f0031d5cb6 Mon Sep 17 00:00:00 2001 From: sbplat <71648843+sbplat@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:13:36 -0500 Subject: [PATCH 2/2] refactor: reflect changes to pipeline release --- .../SPDF/controller/api/pipeline/ApiDocService.java | 10 +++++----- .../controller/api/pipeline/PipelineProcessor.java | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java index 43448f89..3eda502b 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java @@ -16,8 +16,11 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.ServletContext; + +import stirling.software.SPDF.SPdfApplication; import stirling.software.SPDF.model.ApiEndpoint; import stirling.software.SPDF.model.Role; + @Service public class ApiDocService { @@ -28,11 +31,8 @@ public class ApiDocService { private String getApiDocsUrl() { String contextPath = servletContext.getContextPath(); - String port = System.getProperty("local.server.port"); - if(port == null || port.length() == 0) { - port="8080"; - } - + String port = SPdfApplication.getPort(); + return "http://localhost:"+ port + contextPath + "/v1/api-docs"; } diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java index 1ac7eef9..2fad339b 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java @@ -34,6 +34,8 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; import jakarta.servlet.ServletContext; + +import stirling.software.SPDF.SPdfApplication; import stirling.software.SPDF.model.PipelineConfig; import stirling.software.SPDF.model.PipelineOperation; import stirling.software.SPDF.model.Role; @@ -65,7 +67,9 @@ public class PipelineProcessor { private String getBaseUrl() { String contextPath = servletContext.getContextPath(); - return "http://localhost:8080" + contextPath + "/"; + String port = SPdfApplication.getPort(); + + return "http://localhost:" + port + contextPath + "/"; }