added ApplicationManager

This commit is contained in:
Lucio Lelii 2022-05-30 18:32:00 +02:00
parent 47436a8a8d
commit 875c08919d
5 changed files with 56 additions and 10 deletions

View File

@ -27,13 +27,12 @@ location = rome
;port = 80 ;port = 80
[authorization] [authorization]
; mandatory
; optional fields: provider factory (=org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory)
factory = org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory factory = org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory
endpoint = https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token
credentials.class = org.gcube.smartgears.security.SimpleCredentials credentials.class = org.gcube.smartgears.security.SimpleCredentials
credentials.clientID = node-whn-test-uno-d-d4s.d4science.org credentials.clientID = node-whn-test-uno-d-d4s.d4science.org
credentials.secret = 979bd3bc-5cc4-11ec-bf63-0242ac130002 credentials.secret = 979bd3bc-5cc4-11ec-bf63-0242ac130002
credentials.endpoint = https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token
;[persistence] ;[persistence]
; not mandatory (default is LocalPersistence writing in the ghn home) ; not mandatory (default is LocalPersistence writing in the ghn home)

View File

@ -58,12 +58,13 @@
</logger> </logger>
<logger name="org.gcube" level="INFO" /> <logger name="org.gcube" level="INFO" />
<logger name="org.gcube.smartgears" level="INFO" /> <logger name="org.gcube.smartgears" level="TRACE" />
<logger name="org.gcube.common.events" level="WARN" /> <logger name="org.gcube.common.events" level="WARN" />
<logger name="org.gcube.data.publishing" level="ERROR" /> <logger name="org.gcube.data.publishing" level="ERROR" />
<logger name="org.gcube.documentstore" level="ERROR" /> <logger name="org.gcube.documentstore" level="ERROR" />
<logger name="org.gcube.test.app" level="INFO" />
<root level="WARN"> <root level="WARN">
<appender-ref ref="FILE" /> <appender-ref ref="FILE" />
</root> </root>

View File

@ -0,0 +1,35 @@
package org.gcube.test.app;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.smartgears.ApplicationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyAppManager implements ApplicationManager {
Logger logger = LoggerFactory.getLogger(MyAppManager.class);
private boolean init = false;
@Override
public void onInit() {
try {
init = true;
logger.info("init called in {}: {}",SecretManagerProvider.instance.get().getContext(), this.init);
}catch (Exception e) {
logger.error("error on init ",e);
}
}
@Override
public void onShutdown() {
logger.info("shutdown called");
logger.info("shutdown called in {}: {}",SecretManagerProvider.instance.get().getContext(), this.init);
}
public boolean isInit() {
return init;
}
}

View File

@ -7,10 +7,17 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret;
import org.gcube.smartgears.ApplicationManagerProvider;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.annotations.ManagedBy;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@WebServlet(urlPatterns = "/*", name = "testAppServlet") @WebServlet(urlPatterns = "/*", name = "testAppServlet")
@ManagedBy(MyAppManager.class)
public class TestAppServlet extends HttpServlet { public class TestAppServlet extends HttpServlet {
/** /**
@ -18,15 +25,20 @@ public class TestAppServlet extends HttpServlet {
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// log on behalf of extension // log on behalf of extension
private static final Logger log = LoggerFactory.getLogger(TestAppServlet.class); private static final Logger log = LoggerFactory.getLogger(TestAppServlet.class);
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException { throws IOException {
log.info("testApp call received"); log.info("testApp call received");
response.getWriter().write("test app started"); Secret secret = SecretManagerProvider.instance.get();
String context = secret !=null? secret.getContext():null;
log.info("secret si {} and context {}",secret, context);
MyAppManager appManager = (MyAppManager)ApplicationManagerProvider.get(MyAppManager.class);
response.getWriter().write("test app started with initialization "+appManager.isInit() );
} }
} }

View File

@ -4,5 +4,4 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<description>Test webapp</description> <description>Test webapp</description>
<local-persistence location='target' /> <local-persistence location='target' />
<exclude handlers='request-validation,context-retriever'>/*</exclude>
</application> </application>