diff --git a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java index 004c6fb044c..e12ab500cb4 100644 --- a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java +++ b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java @@ -19,7 +19,9 @@ import io.smallrye.opentracing.SmallRyeTracingDynamicFeature; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletRegistration; +import org.apache.openejb.assembler.classic.AppInfo; import org.apache.openejb.assembler.classic.WebAppInfo; +import org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed; import org.apache.openejb.config.NewLoaderLogic; import org.apache.openejb.config.event.EnhanceScannableUrlsEvent; import org.apache.openejb.loader.Files; @@ -40,6 +42,7 @@ import java.io.FileFilter; import java.io.FileInputStream; import java.io.IOException; +import java.io.UncheckedIOException; import java.io.InputStream; import java.net.URL; import java.security.CodeSource; @@ -47,6 +50,8 @@ import java.util.Enumeration; import java.util.List; import java.util.Set; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.stream.Collectors; @@ -66,6 +71,8 @@ public class TomEEMicroProfileListener { "io.smallrye.faulttolerance.FaultToleranceExtension", }; + private final Map indexCache = new ConcurrentHashMap<>(); + @SuppressWarnings("Duplicates") public void enhanceScannableUrls(@Observes final EnhanceScannableUrlsEvent enhanceScannableUrlsEvent) { @@ -98,6 +105,11 @@ public void enhanceScannableUrls(@Observes final EnhanceScannableUrlsEvent enhan SystemInstance.get().setProperty("openejb.cxf-rs.cache-application", "false"); } + public void afterApplicationDeployed(@Observes final BeforeEvent event) { + //Just in case, remove the index from the cache if it still exits + indexCache.remove(event.getEvent().getApp()); + } + public void processApplication(@Observes final BeforeEvent afterApplicationCreated) { final ServletContext context = afterApplicationCreated.getEvent().getContext(); final WebAppInfo webApp = afterApplicationCreated.getEvent().getWeb(); @@ -122,10 +134,22 @@ public void processApplication(@Observes final BeforeEvent { + try { + return of(app.libs); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + }); MicroProfileOpenApiRegistration.registerOpenApiServlet(context, index); - } catch (final IOException e) { + //Check if this was the last webapp to be processed and if so, remove it from the cache + int lastIndex = app.webApps.size() - 1; + if(app.webApps.indexOf(afterApplicationCreated.getEvent().getWeb()) == lastIndex) { + indexCache.remove(app); + } + } catch (final UncheckedIOException e) { throw new IllegalStateException("Can't build Jandex index for application " + webApp.contextRoot, e); }