Closed jmrleal closed 3 years ago
I tried to do a bit of research and managed to create a bean for the WebAppListener. Essentially what I did was base my springboot project from the subproject phase4-peppol-server-webapp and add the @ServletComponentScan to the main of the SpringBootApplication, however when I try to register the servlet I get this error:
The code I used to create the Servlet looks something like this:
Have you ever encountered anything like this?
Thanks in advance!
Yes I do :)
Try this class:
@Configuration
public class ServletConfig
{
/** The ServletContext to be used */
@Autowired
private ServletContext m_aSC;
@Bean
public ServletRegistrationBean <AS2ReceiveServlet> servletRegistrationBean ()
{
// Required to be called before the servlet is initialized
WebScopeManager.onGlobalBegin (m_aSC);
return new ServletRegistrationBean <> (new Phase4PeppolServlet (), "/as4");
}
}
and for the application try something like this
@SpringBootApplication
public class As4SandboxApplication
{
public static void main (final String [] args)
{
SpringApplication.run (As4SandboxApplication.class, args);
// Shutdown here
WebScopeManager.onGlobalEnd ();
}
}
That fixed part of the problem, now it says:
I assume the same ServletContext needs to be used both, for the Servlet and the Listener? But it seems that it is trying to register a new one with the same name.
Yes correct. Can you post the full stack trace here?
Have you registered a ServletContectListener as well? If so, which one?
Stacktrace:
2021-02-16 16:13:49.404 INFO 9452 --- [ main] p.o.p.Phase4SpringbootApplication : Starting Phase4SpringbootApplication using Java 1.8.0_271 on OP-203 with PID 9452 (C:\Projects\phase4-phase4-parent-pom-0.14.0\phase4-springboot\target\classes started by Ghostuser in C:\Projects\phase4-phase4-parent-pom-0.14.0\phase4-springboot)
2021-02-16 16:13:49.411 INFO 9452 --- [ main] p.o.p.Phase4SpringbootApplication : No active profile set, falling back to default profiles: default
2021-02-16 16:13:51.765 INFO 9452 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-02-16 16:13:51.779 INFO 9452 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-16 16:13:51.779 INFO 9452 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-16 16:13:52.037 INFO 9452 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-16 16:13:52.037 INFO 9452 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2449 ms
2021-02-16 16:13:52.660 ERROR 9452 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Exception sending context initialized event to listener instance of class [pt.opensoft.phase4springboot.server.servlet.Phase4PeppolWebAppListener]
java.lang.IllegalStateException: Another global scope with ID 'application' is already present. New global scope with ID 'application' is not set!
at com.helger.scope.mgr.ScopeManager.lambda$setGlobalScope$0(ScopeManager.java:102) ~[ph-scopes-9.5.4.jar:9.5.4]
at com.helger.commons.concurrent.SimpleReadWriteLock.writeLocked(SimpleReadWriteLock.java:341) ~[ph-commons-9.5.4.jar:9.5.4]
at com.helger.scope.mgr.ScopeManager.setGlobalScope(ScopeManager.java:97) ~[ph-scopes-9.5.4.jar:9.5.4]
at com.helger.web.scope.mgr.WebScopeManager.onGlobalBegin(WebScopeManager.java:148) ~[ph-web-9.5.2.jar:9.5.2]
at com.helger.web.scope.mgr.WebScopeManager.onGlobalBegin(WebScopeManager.java:140) ~[ph-web-9.5.2.jar:9.5.2]
at com.helger.photon.core.servlet.WebAppListener.contextInitialized(WebAppListener.java:652) ~[ph-oton-core-8.2.9.jar:8.2.9]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4716) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5177) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_271]
at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_271]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_271]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:843) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_271]
at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_271]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_271]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:434) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:451) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:200) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582) [spring-context-5.3.3.jar:5.3.3]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) [spring-boot-2.4.2.jar:2.4.2]
at pt.opensoft.phase4springboot.Phase4SpringbootApplication.main(Phase4SpringbootApplication.java:13) [classes/:na]
2021-02-16 16:13:52.661 ERROR 9452 --- [ main] o.apache.catalina.core.StandardContext : One or more listeners failed to start. Full details will be found in the appropriate container log file
2021-02-16 16:13:52.662 ERROR 9452 --- [ main] o.apache.catalina.core.StandardContext : Context [] startup failed due to previous errors
2021-02-16 16:13:52.666 INFO 9452 --- [ main] c.h.photon.core.servlet.WebAppListener : Servlet context 'application' is being destroyed
2021-02-16 16:13:52.689 ERROR 9452 --- [ main] c.h.photon.core.servlet.WebAppListener : Not writing statistics because WebFileIO was not initialized!
2021-02-16 16:13:52.722 INFO 9452 --- [ main] c.h.photon.core.servlet.WebAppListener : Servlet context 'application' was destroyed in 55 milli seconds
2021-02-16 16:13:53.228 INFO 9452 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-02-16 16:13:53.236 WARN 9452 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2021-02-16 16:13:53.248 INFO 9452 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-02-16 16:13:53.289 ERROR 9452 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) [spring-boot-2.4.2.jar:2.4.2]
at pt.opensoft.phase4springboot.Phase4SpringbootApplication.main(Phase4SpringbootApplication.java:13) [classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:451) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:200) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159) ~[spring-boot-2.4.2.jar:2.4.2]
... 9 common frames omitted
Caused by: java.lang.IllegalStateException: StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[] failed to start
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.rethrowDeferredStartupExceptions(TomcatWebServer.java:187) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) ~[spring-boot-2.4.2.jar:2.4.2]
... 14 common frames omitted
The listener I registered is the Phase4PeppolWebAppListener present in the peppol-server-web-app subproject.
Yes okay, so the other web fragments get loaded as well - than it's a matter of initialization order.
Can you paste the stacktrace that occurs if you don't do WebScopeManager.onGlobalBegin (m_aSC);
in your ServletConfig
?
Stack strace without WebScopeManager.onGlobalBegin (m_aSC);
:
2021-02-16 16:38:21.506 INFO 5604 --- [ main] p.o.p.Phase4SpringbootApplication : Starting Phase4SpringbootApplication using Java 1.8.0_271 on OP-203 with PID 5604 (C:\Projects\phase4-phase4-parent-pom-0.14.0\phase4-springboot\target\classes started by Ghostuser in C:\Projects\phase4-phase4-parent-pom-0.14.0\phase4-springboot)
2021-02-16 16:38:21.511 INFO 5604 --- [ main] p.o.p.Phase4SpringbootApplication : No active profile set, falling back to default profiles: default
2021-02-16 16:38:23.662 INFO 5604 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-02-16 16:38:23.674 INFO 5604 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-16 16:38:23.675 INFO 5604 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-16 16:38:23.958 INFO 5604 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-16 16:38:23.958 INFO 5604 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2336 ms
2021-02-16 16:38:24.026 ERROR 5604 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletRegistrationBean' defined in class path resource [pt/opensoft/phase4springboot/server/servlet/ServletConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method 'servletRegistrationBean' threw exception; nested exception is java.lang.IllegalStateException: No global scope object has been set!
2021-02-16 16:38:24.264 INFO 5604 --- [ main] com.helger.photon.app.io.WebFileIO : Using 'C:\Projects\phase4-phase4-parent-pom-0.14.0\phase4-springboot\phase4-data' as the data path
2021-02-16 16:38:24.270 INFO 5604 --- [ main] com.helger.photon.app.io.WebFileIO : Using 'C:\Users\Ghostuser\AppData\Local\Temp\tomcat-docbase.8080.3763512349173596853' as the servlet context path
2021-02-16 16:38:24.278 INFO 5604 --- [ main] c.helger.web.scope.mgr.WebScopeManager : Session passivation is now disabled
2021-02-16 16:38:24.291 INFO 5604 --- [ main] c.h.p.s.p.h.PasswordHashCreatorManager : Default PasswordHashCreator algorithm set to 'PBKDF2_1000_48'
2021-02-16 16:38:24.293 INFO 5604 --- [ main] c.h.p.s.password.GlobalPasswordSettings : Set global password constraints to [PasswordConstraintList@0x60921b21: constraints=[[PasswordConstraintMinLength@0x0bd2f5a9: minLength=6]]]
2021-02-16 16:38:24.300 INFO 5604 --- [ main] c.h.x.requesttrack.RequestTracker : RequestTrackerMonitor was installed successfully.
MailcapCommandMap: load HOME
new MailcapFile: file C:\Users\Ghostuser\.mailcap
MailcapCommandMap: load SYS
new MailcapFile: file C:\Program Files\Java\jdk1.8.0_271\jre\lib\mailcap
MailcapCommandMap: load JAR
MailcapCommandMap: getResources
MailcapCommandMap: URL jar:file:/C:/Users/Ghostuser/.m2/repository/org/bouncycastle/bcmail-jdk15on/1.67/bcmail-jdk15on-1.67.jar!/META-INF/mailcap
new MailcapFile: InputStream
parse: application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature
Type: application/pkcs7-signature
Command: content-handler, Class: org.bouncycastle.mail.smime.handlers.pkcs7_signature
parse: application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime
Type: application/pkcs7-mime
Command: content-handler, Class: org.bouncycastle.mail.smime.handlers.pkcs7_mime
parse: application/x-pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_signature
Type: application/x-pkcs7-signature
Command: content-handler, Class: org.bouncycastle.mail.smime.handlers.x_pkcs7_signature
parse: application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime
Type: application/x-pkcs7-mime
Command: content-handler, Class: org.bouncycastle.mail.smime.handlers.x_pkcs7_mime
parse: multipart/signed;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.multipart_signed
Type: multipart/signed
Command: content-handler, Class: org.bouncycastle.mail.smime.handlers.multipart_signed
MailcapCommandMap: successfully loaded mailcap file from URL: jar:file:/C:/Users/Ghostuser/.m2/repository/org/bouncycastle/bcmail-jdk15on/1.67/bcmail-jdk15on-1.67.jar!/META-INF/mailcap
MailcapCommandMap: URL jar:file:/C:/Users/Ghostuser/.m2/repository/com/sun/mail/jakarta.mail/1.6.5/jakarta.mail-1.6.5.jar!/META-INF/mailcap
new MailcapFile: InputStream
parse: text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain
Type: text/plain
Command: content-handler, Class: com.sun.mail.handlers.text_plain
parse: text/html;; x-java-content-handler=com.sun.mail.handlers.text_html
Type: text/html
Command: content-handler, Class: com.sun.mail.handlers.text_html
parse: text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml
Type: text/xml
Command: content-handler, Class: com.sun.mail.handlers.text_xml
parse: multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed; x-java-fallback-entry=true
Type: multipart/*
Command: content-handler, Class: com.sun.mail.handlers.multipart_mixed
parse: message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822
Type: message/rfc822
Command: content-handler, Class: com.sun.mail.handlers.message_rfc822
MailcapCommandMap: successfully loaded mailcap file from URL: jar:file:/C:/Users/Ghostuser/.m2/repository/com/sun/mail/jakarta.mail/1.6.5/jakarta.mail-1.6.5.jar!/META-INF/mailcap
MailcapCommandMap: load DEF
new MailcapFile: InputStream
parse: image/gif;; x-java-view=com.sun.activation.viewers.ImageViewer
Type: image/gif
Command: view, Class: com.sun.activation.viewers.ImageViewer
parse: image/jpeg;; x-java-view=com.sun.activation.viewers.ImageViewer
Type: image/jpeg
Command: view, Class: com.sun.activation.viewers.ImageViewer
parse: text/*;; x-java-view=com.sun.activation.viewers.TextViewer
Type: text/*
Command: view, Class: com.sun.activation.viewers.TextViewer
parse: text/*;; x-java-edit=com.sun.activation.viewers.TextEditor
Type: text/*
Command: edit, Class: com.sun.activation.viewers.TextEditor
Merging commands for type text/*
MailcapCommandMap: successfully loaded mailcap file: /META-INF/mailcap.default
MailcapCommandMap: createDataContentHandler for multipart/related
search DB #1
search DB #2
search DB #3
search fallback DB #1
search fallback DB #2
got content-handler
class com.sun.mail.handlers.multipart_mixed
2021-02-16 16:38:24.857 INFO 5604 --- [ main] c.h.p.s.mgr.PhotonSecurityManager : PhotonSecurityManager was initialized
2021-02-16 16:38:24.859 INFO 5604 --- [ main] com.helger.phase4.mgr.MetaAS4Manager : MetaAS4Manager is initialized with in-memory data structures
2021-02-16 16:38:24.883 INFO 5604 --- [ main] c.h.phase4.profile.AS4ProfileManager : 1 AS4 profile is registered
2021-02-16 16:38:24.884 INFO 5604 --- [ main] com.helger.phase4.mgr.MetaAS4Manager : MetaAS4Manager was initialized
2021-02-16 16:38:24.928 INFO 5604 --- [ main] c.h.quartz.impl.StdSchedulerFactory : Using default implementation for ThreadExecutor
2021-02-16 16:38:24.930 INFO 5604 --- [ main] c.helger.quartz.simpl.SimpleThreadPool : Job execution threads will use class loader of thread: main
2021-02-16 16:38:24.932 INFO 5604 --- [ main] c.helger.quartz.simpl.SimpleThreadPool : Initialized 10 worker threads
2021-02-16 16:38:24.942 INFO 5604 --- [ main] c.h.quartz.core.QuartzSchedulerThread : QuartzSchedulerThread Inheriting ContextClassLoader of thread: main
2021-02-16 16:38:24.944 INFO 5604 --- [ main] c.helger.quartz.core.SchedulerSignaler : Initialized Scheduler Signaller of type: class com.helger.quartz.core.SchedulerSignaler
2021-02-16 16:38:24.944 INFO 5604 --- [ main] com.helger.quartz.core.QuartzScheduler : Mini Quartz Scheduler v.4.1.1 created.
2021-02-16 16:38:24.945 INFO 5604 --- [ main] com.helger.quartz.core.QuartzScheduler : JobFactory set to: com.helger.quartz.simpl.SimpleJobFactory@54d901aa
2021-02-16 16:38:24.945 INFO 5604 --- [ main] com.helger.quartz.simpl.RAMJobStore : RAMJobStore initialized.
2021-02-16 16:38:24.946 INFO 5604 --- [ main] com.helger.quartz.core.QuartzScheduler : Scheduler meta-data: Mini Quartz Scheduler (v4.1.1) 'MiniQuartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'com.helger.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'com.helger.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'com.helger.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
2021-02-16 16:38:24.946 INFO 5604 --- [ main] c.h.quartz.impl.StdSchedulerFactory : Quartz scheduler 'MiniQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
2021-02-16 16:38:24.947 INFO 5604 --- [ main] c.h.quartz.impl.StdSchedulerFactory : Quartz scheduler version: 4.1.1
2021-02-16 16:38:24.948 INFO 5604 --- [ main] com.helger.quartz.core.QuartzScheduler : Scheduler MiniQuartzScheduler_$_NON_CLUSTERED started.
2021-02-16 16:38:24.958 INFO 5604 --- [ main] c.h.s.quartz.GlobalQuartzScheduler : Succesfully scheduled job 'AS4DuplicateCleanupJob-10' with TriggerKey DEFAULT.6da64b5bd2ee-2c6db8bb-26fe-4585-852e-84fff0f6fcd7 - starting at 2021-02-16T16:38:24.950
2021-02-16 16:38:24.983 INFO 5604 --- [ main] p.o.p.s.s.Phase4PeppolWebAppListener : Sucessfully checked that the provided Peppol AP certificate is valid.
2021-02-16 16:38:25.812 INFO 5604 --- [ main] p.o.p.s.s.Phase4PeppolWebAppListener : phase4 Peppol receiver checks are enabled
2021-02-16 16:38:25.813 INFO 5604 --- [ main] c.h.photon.core.servlet.WebAppListener : Servlet context 'application' was initialized in 1755 milli seconds
2021-02-16 16:38:25.821 INFO 5604 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-02-16 16:38:25.825 INFO 5604 --- [ main] c.h.photon.core.servlet.WebAppListener : Servlet context 'application' is being destroyed
2021-02-16 16:38:25.826 INFO 5604 --- [ main] c.h.s.quartz.GlobalQuartzScheduler : Succesfully unscheduled job with TriggerKey DEFAULT.6da64b5bd2ee-2c6db8bb-26fe-4585-852e-84fff0f6fcd7
2021-02-16 16:38:25.828 INFO 5604 --- [ main] c.h.photon.audit.AsynchronousAuditor : Stopping auditor queue with 2 items
2021-02-16 16:38:26.566 INFO 5604 --- [ main] c.h.x.requesttrack.RequestTracker : RequestTrackerMonitor is now shutting down
2021-02-16 16:38:26.567 INFO 5604 --- [ main] c.h.x.requesttrack.RequestTracker : RequestTrackerMonitor was uninstalled successfully.
2021-02-16 16:38:26.567 INFO 5604 --- [ main] com.helger.quartz.core.QuartzScheduler : Scheduler MiniQuartzScheduler_$_NON_CLUSTERED shutting down.
2021-02-16 16:38:26.567 INFO 5604 --- [ main] com.helger.quartz.core.QuartzScheduler : Scheduler MiniQuartzScheduler_$_NON_CLUSTERED paused.
2021-02-16 16:38:26.981 INFO 5604 --- [ main] com.helger.quartz.core.QuartzScheduler : Scheduler MiniQuartzScheduler_$_NON_CLUSTERED shutdown complete.
2021-02-16 16:38:26.982 INFO 5604 --- [ main] c.h.s.quartz.GlobalQuartzScheduler : Successfully shutdown GlobalQuartzScheduler
2021-02-16 16:38:27.020 INFO 5604 --- [ main] c.h.photon.core.servlet.WebAppListener : Servlet context 'application' was destroyed in 1195 milli seconds
2021-02-16 16:38:27.024 WARN 5604 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2021-02-16 16:38:27.032 INFO 5604 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-02-16 16:38:27.057 ERROR 5604 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) [spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) [spring-boot-2.4.2.jar:2.4.2]
at pt.opensoft.phase4springboot.Phase4SpringbootApplication.main(Phase4SpringbootApplication.java:13) [classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:451) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:200) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159) ~[spring-boot-2.4.2.jar:2.4.2]
... 9 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletRegistrationBean' defined in class path resource [pt/opensoft/phase4springboot/server/servlet/ServletConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method 'servletRegistrationBean' threw exception; nested exception is java.lang.IllegalStateException: No global scope object has been set!
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:203) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:97) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:86) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:259) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:233) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.4.2.jar:2.4.2]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_271]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_271]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:843) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_271]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_271]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:434) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.4.2.jar:2.4.2]
... 14 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method 'servletRegistrationBean' threw exception; nested exception is java.lang.IllegalStateException: No global scope object has been set!
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.3.jar:5.3.3]
... 54 common frames omitted
Caused by: java.lang.IllegalStateException: No global scope object has been set!
at com.helger.scope.mgr.ScopeManager.getGlobalScope(ScopeManager.java:159) ~[ph-scopes-9.5.4.jar:9.5.4]
at com.helger.scope.singleton.AbstractGlobalSingleton._getStaticScope(AbstractGlobalSingleton.java:48) ~[ph-scopes-9.5.4.jar:9.5.4]
at com.helger.scope.singleton.AbstractGlobalSingleton.getGlobalSingleton(AbstractGlobalSingleton.java:65) ~[ph-scopes-9.5.4.jar:9.5.4]
at com.helger.xservlet.servletstatus.ServletStatusManager.getInstance(ServletStatusManager.java:67) ~[ph-xservlet-9.5.2.jar:9.5.2]
at com.helger.xservlet.AbstractXServlet.<init>(AbstractXServlet.java:179) ~[ph-xservlet-9.5.2.jar:9.5.2]
at com.helger.phase4.peppol.servlet.Phase4PeppolServlet.<init>(Phase4PeppolServlet.java:49) ~[classes/:na]
at pt.opensoft.phase4springboot.server.servlet.ServletConfig.servletRegistrationBean(ServletConfig.java:24) ~[classes/:na]
at pt.opensoft.phase4springboot.server.servlet.ServletConfig$$EnhancerBySpringCGLIB$$9c7d7af6.CGLIB$servletRegistrationBean$0(<generated>) ~[classes/:na]
at pt.opensoft.phase4springboot.server.servlet.ServletConfig$$EnhancerBySpringCGLIB$$9c7d7af6$$FastClassBySpringCGLIB$$3c6c8e51.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.3.jar:5.3.3]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.3.jar:5.3.3]
at pt.opensoft.phase4springboot.server.servlet.ServletConfig$$EnhancerBySpringCGLIB$$9c7d7af6.servletRegistrationBean(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_271]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_271]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_271]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_271]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.3.jar:5.3.3]
... 55 common frames omitted
The problem is the initialization order. Unfortunately I am not a Spring Boot expert.
But I assume that Spring Boot also evaluates the WEB-INF/web.xml
file? Or does it only use what you configure?
Here we have the inconvenient case, that some "nested" WEB-INF/web-fragment.xml
are evaluated but there seems no "main" web.xml.
I hope you get my point ;-)
I might be wrong, but I think it doesn't rely on the web.xml file, when you programatically register the listener and the servlet.
If I manage to fix the problem I'll let you know.
Thanks for your help!
I managed to understand what I was doing wrong!
Spring Boot by default starts a Tomcat server, so we don't need the Web App Listener. Instead we just need to register the servlet as you suggested. The only problem i'm facing now is that it doesn't find the SBDHandlerSPI i'm providing.
The SPI stuff should be easy to resolve.
You need to create a file META-INF/services/com.helger.phase4.peppol.servlet.IPhase4PeppolIncomingSBDHandlerSPI
that contains one line of text with the fully qualified name of the implementing class that implements this interface.
See https://docs.oracle.com/javase/tutorial/ext/basics/spi.html for the Oracle docs on it
Yes I think I managed to solve it. Thank you very much!
Just have one last question, the initialization that was being done in the Web App Listener now needs to be done before creating the servlet right?
Namely: WebScopeManager.onGlobalBegin(ctx); initGlobalSettings(); initAS4(); initPeppolAS4();
Yes, the WebScopeManager.onGlobalBegin needs to be the first. It creates a small environment for "global variables" so that they can be shutdown appropriately in the end (closing files, deleting temp files etc.) without relying on external factors
Sweet! The problem is solved, you may close the issue :) I would like to thank you for your response times and also for the reliable information!
Can you eventually share the stub project here so I can include it in the project? If so, do you agree that the code will be maintained under Apache 2.0 license?
Sure, when I wrap things up i'll send you the full demo.
Hey Philip, I finished setting up the demo stub and I would like to ask you what is the best way for me to share the code with you? Should I send you a zip with the code or leave it in a public repository under my name?
Whatever you prefer - if you have ZIP, feel free to send it by email. If you already have a repository and can make a PR it also works for me. I am trying not to be picky ;-)
Done via e-mail.
Thanks a lot @jmrleal for providing this patch. I've taken it basically "as is", just changed the namespaces and "not used" the InvoiceRegistry as it was too specific. You are mentioned at https://github.com/phax/phase4#news-and-noteworthy and inside the NOTICE file of the submodule - I hope this is fine for you.
Hello Philip, I was wondering if it would be possible do provide a demo with phase4 servlet and spring boot. Thank you in advance!