This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch spring6
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/spring6 by this push:
     new d7f8026178 ISIS-3275: resteasy provisioning fixes
d7f8026178 is described below

commit d7f80261782c91395a6d33d2436ac8071899e50d
Author: Andi Huber <[email protected]>
AuthorDate: Mon Nov 28 07:59:26 2022 +0100

    ISIS-3275: resteasy provisioning fixes
---
 .../conf/Configuration_usingSpring6.java           | 108 +--------------------
 .../viewer/resources/ResourceAbstract.java         |  11 ++-
 2 files changed, 11 insertions(+), 108 deletions(-)

diff --git 
a/regressiontests/stable/src/main/java/org/apache/causeway/testdomain/conf/Configuration_usingSpring6.java
 
b/regressiontests/stable/src/main/java/org/apache/causeway/testdomain/conf/Configuration_usingSpring6.java
index c159817845..61a35e3539 100644
--- 
a/regressiontests/stable/src/main/java/org/apache/causeway/testdomain/conf/Configuration_usingSpring6.java
+++ 
b/regressiontests/stable/src/main/java/org/apache/causeway/testdomain/conf/Configuration_usingSpring6.java
@@ -18,17 +18,6 @@
  */
 package org.apache.causeway.testdomain.conf;
 
-import java.util.Set;
-
-import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletContainerInitializer;
-
-import org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher;
-import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
-import org.jboss.resteasy.plugins.servlet.ResteasyServletInitializer;
-import org.jboss.resteasy.springboot.ResteasyEmbeddedServletInitializer;
-import org.springframework.boot.web.servlet.ServletRegistrationBean;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 
@@ -44,107 +33,12 @@ import lombok.extern.log4j.Log4j2;
 @Deprecated(forRemoval = true)
 @Configuration
 @Import({
-    ResteasyEmbeddedServletInitializer.class, //FIXME[ISIS-3275] move up the 
hierarchy?
+    org.jboss.resteasy.springboot.ResteasyAutoConfiguration.class, 
//FIXME[ISIS-3275] move up the hierarchy?
     FixtureScriptsSpecificationProviderAutoConfiguration.class, // because 
something? disables autoconfiguration
     ExecutionParametersServiceAutoConfiguration.class           // because 
something? disables autoconfiguration
 })
 @Log4j2
 public class Configuration_usingSpring6 {
 
-    /**
-     * This class is the Spring Boot equivalent of {@link 
ResteasyServletInitializer},
-     * which implements the Servlet API {@link ServletContainerInitializer} 
interface
-     * to find all JAX-RS Application, Provider and Path classes in the 
classpath.
-     * <p>
-     * As we all know, in Spring Boot we use an embedded servlet container. 
However,
-     * the Servlet spec does not support embedded containers, and many 
portions of it
-     * do not apply to embedded containers, and ServletContainerInitializer is 
one of them.
-     * <p>
-     * This class fills in this gap.
-     * <p>
-     * Notice that the JAX-RS Application classes are found in this RESTEasy 
starter by class
-     * ResteasyEmbeddedServletInitializer, and that is done by scanning the 
classpath.
-     * <p>
-     * The Path and Provider annotated classes are found by using Spring 
framework (instead of
-     * scanning the classpath), since it is assumed those classes are ALWAYS 
necessarily
-     * Spring beans (this starter is meant for Spring Boot applications that 
use RESTEasy
-     * as the JAX-RS implementation)
-     *
-     * @see 
"https://github.com/paypal/resteasy-spring-boot/blob/master/resteasy-spring-boot-starter/src/main/java/com/paypal/springboot/resteasy/ResteasyApplicationBuilder.java";
-     */
-    public static class ResteasyApplicationBuilder {
-
-        public static final String BEAN_NAME = 
"JaxrsApplicationServletBuilder";
-
-        public ServletRegistrationBean<Servlet> build(
-                final String applicationClassName,
-                final String path,
-                final Set<Class<?>> resources,
-                final Set<Class<?>> providers) {
-            Servlet servlet = new HttpServlet30Dispatcher();
-
-            ServletRegistrationBean<Servlet> servletRegistrationBean = new 
ServletRegistrationBean<Servlet>(servlet);
-
-            servletRegistrationBean.setName(applicationClassName);
-            servletRegistrationBean.setLoadOnStartup(1);
-            servletRegistrationBean.setAsyncSupported(true);
-            
servletRegistrationBean.addInitParameter("javax.ws.rs.Application", 
applicationClassName);
-
-            if (path != null) {
-                String mapping = path;
-                if (!mapping.startsWith("/"))
-                    mapping = "/" + mapping;
-                String prefix = mapping;
-                if (!"/".equals(prefix) && prefix.endsWith("/"))
-                    prefix = prefix.substring(0, prefix.length() - 1);
-                if (mapping.endsWith("/"))
-                    mapping += "*";
-                else
-                    mapping += "/*";
-                // resteasy.servlet.mapping.prefix
-                
servletRegistrationBean.addInitParameter("resteasy.servlet.mapping.prefix", 
prefix);
-                servletRegistrationBean.addUrlMappings(mapping);
-            }
-
-            if (resources.size() > 0) {
-                StringBuilder builder = new StringBuilder();
-                boolean first = true;
-                for (Class<?> resource : resources) {
-                    if (first) {
-                        first = false;
-                    } else {
-                        builder.append(",");
-                    }
-
-                    builder.append(resource.getName());
-                }
-                
servletRegistrationBean.addInitParameter(ResteasyContextParameters.RESTEASY_SCANNED_RESOURCES,
 builder.toString());
-            }
-            if (providers.size() > 0) {
-                StringBuilder builder = new StringBuilder();
-                boolean first = true;
-                for (Class<?> provider : providers) {
-                    if (first) {
-                        first = false;
-                    } else {
-                        builder.append(",");
-                    }
-                    builder.append(provider.getName());
-                }
-                
servletRegistrationBean.addInitParameter(ResteasyContextParameters.RESTEASY_SCANNED_PROVIDERS,
 builder.toString());
-            }
-
-            log.debug("ServletRegistrationBean has just bean created for 
JAX-RS class " + applicationClassName);
-
-            return servletRegistrationBean;
-        }
-
-    }
-
-
-    @Bean(name = "JaxrsApplicationServletBuilder")
-    public ResteasyApplicationBuilder resteasyApplicationBuilder() {
-        return new ResteasyApplicationBuilder();
-    }
 
 }
diff --git 
a/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/ResourceAbstract.java
 
b/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/ResourceAbstract.java
index 0d04776bd9..70c890be46 100644
--- 
a/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/ResourceAbstract.java
+++ 
b/viewers/restfulobjects/viewer/src/main/java/org/apache/causeway/viewer/restfulobjects/viewer/resources/ResourceAbstract.java
@@ -20,6 +20,7 @@ package 
org.apache.causeway.viewer.restfulobjects.viewer.resources;
 
 import java.io.InputStream;
 import java.util.Map;
+import java.util.Set;
 import java.util.function.UnaryOperator;
 
 import jakarta.servlet.http.HttpServletRequest;
@@ -39,6 +40,8 @@ import 
org.apache.causeway.commons.internal.assertions._Assert;
 import org.apache.causeway.commons.internal.base._Refs;
 import org.apache.causeway.commons.internal.base._Strings;
 import org.apache.causeway.commons.internal.codec._UrlDecoderUtil;
+import org.apache.causeway.commons.internal.collections._Sets;
+import org.apache.causeway.commons.internal.exceptions._Exceptions;
 import org.apache.causeway.core.config.viewer.web.WebAppContextPath;
 import org.apache.causeway.core.metamodel.consent.InteractionInitiatedBy;
 import org.apache.causeway.core.metamodel.context.HasMetaModelContext;
@@ -71,8 +74,14 @@ implements HasMetaModelContext {
     @Context SecurityContext securityContext;
     @Context Providers providers;
 
+    //TODO[ISIS-3275] remove eventually
+    private static final Set<Class<?>> initialized = _Sets.newHashSet();
+
     protected ResourceAbstract() {
-        System.err.printf("before inject %s%n", this.getClass());
+        if(!initialized.add(this.getClass())) {
+            throw _Exceptions.illegalState("framework bug: %s already 
instantiated, "
+                    + "check resteasy-spring-boot configuration", 
this.getClass().getName());
+        }
     }
 
     // -- FACTORIES

Reply via email to