added the use of smartgears application managers

This commit is contained in:
lucio 2024-02-22 11:54:24 +01:00
parent ff70a6a400
commit 932e924ba4
3 changed files with 43 additions and 2 deletions

View File

@ -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">
<display-name>Hello World</display-name>
<description>
A gcube HelloWorld service - smartgears 4

View File

@ -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());
}
}

View File

@ -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 {