From 932e924ba4a36b7de07da4489459dcfbe97da479 Mon Sep 17 00:00:00 2001 From: lucio Date: Thu, 22 Feb 2024 11:54:24 +0100 Subject: [PATCH] added the use of smartgears application managers --- gcube/extra-resources/WEB-INF/web.xml | 3 +- src/main/java/manager/HelloWorldManager.java | 37 +++++++++++++++++++ .../helloworld/services/HelloService.java | 5 +++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/main/java/manager/HelloWorldManager.java diff --git a/gcube/extra-resources/WEB-INF/web.xml b/gcube/extra-resources/WEB-INF/web.xml index be928b8..97699db 100644 --- a/gcube/extra-resources/WEB-INF/web.xml +++ b/gcube/extra-resources/WEB-INF/web.xml @@ -3,8 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" - version="4.0" - metadata-complete="true"> + version="4.0"> Hello World A gcube HelloWorld service - smartgears 4 diff --git a/src/main/java/manager/HelloWorldManager.java b/src/main/java/manager/HelloWorldManager.java new file mode 100644 index 0000000..9671e65 --- /dev/null +++ b/src/main/java/manager/HelloWorldManager.java @@ -0,0 +1,37 @@ +package manager; + +import org.gcube.common.security.providers.SecretManagerProvider; +import org.gcube.common.security.secrets.Secret; +import org.gcube.smartgears.ApplicationManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * This class is use to Manage the application initialization and shutdown per context; + * The init and shutdown methods are called one per context in which the app is running + * respectively at init and a shutdown time. + * It is connected to the app declaring it via the @ManagedBy annotation. (@see HelloWorld class) + * + * + * @author lucio + * + */ +public class HelloWorldManager implements ApplicationManager { + + Logger logger = LoggerFactory.getLogger(HelloWorldManager.class); + + @Override + public void onInit() { + Secret secret = SecretManagerProvider.get(); + logger.debug("init called in context {}", secret.getContext()); + + } + + @Override + public void onShutdown() { + Secret secret = SecretManagerProvider.get(); + logger.debug("shutDown called in context {}", secret.getContext()); + } + +} diff --git a/src/main/java/org/gcube/service/helloworld/services/HelloService.java b/src/main/java/org/gcube/service/helloworld/services/HelloService.java index cdea7a4..36ec1f5 100644 --- a/src/main/java/org/gcube/service/helloworld/services/HelloService.java +++ b/src/main/java/org/gcube/service/helloworld/services/HelloService.java @@ -7,10 +7,15 @@ import javax.ws.rs.core.MediaType; import org.gcube.common.security.providers.SecretManagerProvider; import org.gcube.common.security.secrets.Secret; +import org.gcube.smartgears.annotations.ManagedBy; import org.gcube.smartgears.utils.InnerMethodName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import manager.HelloWorldManager; + + +@ManagedBy(HelloWorldManager.class) @Path("hello") public class HelloService {