You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/09/15 08:30:48 UTC
[isis] 02/02: ISIS-2429: Demo: use Spring configured port (instead
of hardwired 8080)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 1878553b15bde2f7020a5f808e940a0656503d14
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Sep 15 10:30:21 2020 +0200
ISIS-2429: Demo: use Spring configured port (instead of hardwired 8080)
---
.../java/demoapp/webapp/vaadin/DemoAppVaadin.java | 4 ++--
.../demoapp/web/_infra/utils/ThereCanBeOnlyOne.java | 19 ++++++++++++++-----
.../java/demoapp/webapp/wicket/DemoAppWicket.java | 4 ++--
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java b/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java
index 5997e15..b614c3e 100644
--- a/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java
+++ b/examples/demo/vaadin/src/main/java/demoapp/webapp/vaadin/DemoAppVaadin.java
@@ -42,6 +42,8 @@ import demoapp.web._infra.utils.ThereCanBeOnlyOne;
@Import({
DemoAppManifest.class,
+ ThereCanBeOnlyOne.class, // shutdown demo instance if any already running (specific to the demo only)
+
// INCUBATING
IsisModuleIncViewerVaadinViewer.class, // vaadin viewer
IsisModuleValAsciidocUiVaa.class, // ascii-doc rendering support (for Vaadin)
@@ -67,8 +69,6 @@ public class DemoAppVaadin extends SpringBootServletInitializer {
// IsisPresets.logging(IsisServletForVaadin.class, "debug");
IsisPresets.logging(_Probe.class, "debug"); // enable debug entry logging
- ThereCanBeOnlyOne.remoteShutdownOthersIfAny();
-
SpringApplication.run(new Class[] { DemoAppVaadin.class }, args);
}
diff --git a/examples/demo/web/src/main/java/demoapp/web/_infra/utils/ThereCanBeOnlyOne.java b/examples/demo/web/src/main/java/demoapp/web/_infra/utils/ThereCanBeOnlyOne.java
index 15e251b..c3a1440 100644
--- a/examples/demo/web/src/main/java/demoapp/web/_infra/utils/ThereCanBeOnlyOne.java
+++ b/examples/demo/web/src/main/java/demoapp/web/_infra/utils/ThereCanBeOnlyOne.java
@@ -33,19 +33,26 @@ import org.apache.http.impl.client.HttpClientBuilder;
import lombok.val;
-public class ThereCanBeOnlyOne {
+@Component
+public class ThereCanBeOnlyOne implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
- public static void remoteShutdownOthersIfAny() {
+ @Override
+ public void onApplicationEvent(final EmbeddedServletContainerInitializedEvent event) {
+ final int port = event.getEmbeddedServletContainer().getPort();
+
try {
- invokeRemoteShutdown();
+ invokeRemoteShutdown(port);
} catch (Exception e) {
// ignore them all
}
+
}
- private static void invokeRemoteShutdown() throws IOException {
+ // -- HELPER
+
+ private static void invokeRemoteShutdown(int port) throws IOException {
- val targetHost = new HttpHost("localhost", 8080, "http");
+ val targetHost = new HttpHost("localhost", port, "http");
val credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
@@ -73,3 +80,5 @@ public class ThereCanBeOnlyOne {
}
}
+
+
diff --git a/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/DemoAppWicket.java b/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/DemoAppWicket.java
index 8e172b4..e17c629 100644
--- a/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/DemoAppWicket.java
+++ b/examples/demo/wicket/src/main/java/demoapp/webapp/wicket/DemoAppWicket.java
@@ -42,6 +42,8 @@ import demoapp.web._infra.utils.ThereCanBeOnlyOne;
@Import({
DemoAppManifest.class,
+ ThereCanBeOnlyOne.class, // shutdown demo instance if any already running (specific to the demo only)
+
// Metamodel
IsisModuleValAsciidocMetaModel.class,
@@ -71,8 +73,6 @@ public class DemoAppWicket extends SpringBootServletInitializer {
//DebugLoggingPreset.PERSISTENCE.apply();
//DebugLoggingPreset.ISIS_SESSION.apply();
- ThereCanBeOnlyOne.remoteShutdownOthersIfAny();
-
SpringApplication.run(new Class[] { DemoAppWicket.class }, args);
}