diff --git a/packages/java/endpoint/src/main/java/com/vaadin/hilla/startup/EndpointsValidator.java b/packages/java/endpoint/src/main/java/com/vaadin/hilla/startup/EndpointsValidator.java deleted file mode 100644 index d553d043e2..0000000000 --- a/packages/java/endpoint/src/main/java/com/vaadin/hilla/startup/EndpointsValidator.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2000-2022 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.hilla.startup; - -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletException; -import jakarta.servlet.annotation.HandlesTypes; -import java.io.Serializable; -import java.util.Set; -import java.util.stream.Collectors; - -import com.vaadin.flow.server.frontend.scanner.ClassFinder; -import com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder; -import com.vaadin.flow.server.startup.ClassLoaderAwareServletContainerInitializer; - -import com.vaadin.hilla.BrowserCallable; -import com.vaadin.hilla.Endpoint; - -/** - * Validation class that is run during servlet container initialization which - * checks that application is running with the appropriate spring dependencies - * when there are {@link Endpoint} annotations. - * - * @since 3.0 - */ -@HandlesTypes({ Endpoint.class, BrowserCallable.class }) -public class EndpointsValidator - implements ClassLoaderAwareServletContainerInitializer, Serializable { - - private String classToCheck = "org.springframework.boot.autoconfigure.jackson.JacksonProperties"; - - @Override - public void process(Set> classSet, ServletContext servletContext) - throws ServletException { - - if (classSet == null) { - // This case happens when initializing in a CDI environment. - // - // We cannot check anything here to give a message. - // Continue with the initialization, java will throw - // the proper exception if application tries to use - // an endpoint and dependencies are not added to the project. - return; - } - - ClassFinder finder = new DefaultClassFinder(classSet); - Set> endpoints = finder.getAnnotatedClasses(Endpoint.class); - endpoints.addAll(finder.getAnnotatedClasses(BrowserCallable.class)); - if (!endpoints.isEmpty()) { - try { - finder.loadClass(classToCheck); - } catch (ClassNotFoundException e) { - throw new ServletException( - "ERROR: Vaadin endpoints only work for Spring " - + "enabled projects.\n" - + "This is not a spring application but there are Vaadin endpoints in these classes: " - + endpoints.stream().map(Class::getName) - .collect( - Collectors.joining("\n - ")), - e); - } - } - } - - void setClassToCheck(String className) { - classToCheck = className; - } -} diff --git a/packages/java/endpoint/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer b/packages/java/endpoint/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer deleted file mode 100644 index 0e92a7f98c..0000000000 --- a/packages/java/endpoint/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer +++ /dev/null @@ -1,2 +0,0 @@ -com.vaadin.hilla.startup.EndpointsValidator - diff --git a/packages/java/endpoint/src/test/java/com/vaadin/hilla/startup/EndpointsValidatorTest.java b/packages/java/endpoint/src/test/java/com/vaadin/hilla/startup/EndpointsValidatorTest.java deleted file mode 100644 index b28ea4a71f..0000000000 --- a/packages/java/endpoint/src/test/java/com/vaadin/hilla/startup/EndpointsValidatorTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.vaadin.hilla.startup; - -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletException; - -import java.util.HashSet; -import java.util.Set; - -import com.vaadin.hilla.Endpoint; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - -public class EndpointsValidatorTest { - - @Endpoint - public static class WithConnectEndpoint { - } - - public static class WithoutConnectEndpoint { - } - - private Set> classes; - private ServletContext servletContext; - - @Rule - public ExpectedException exception = ExpectedException.none(); - - @Before - public void setup() { - classes = new HashSet>(); - servletContext = Mockito.mock(ServletContext.class); - } - - @Test - public void should_start_when_spring_in_classpath() throws Exception { - EndpointsValidator validator = new EndpointsValidator(); - classes.add(WithConnectEndpoint.class); - validator.process(classes, servletContext); - } - - @Test - public void should_trow_when_spring_not_in_classpath() throws Exception { - exception.expect(ServletException.class); - EndpointsValidator validator = new EndpointsValidator(); - validator.setClassToCheck("foo.bar.Baz"); - classes.add(WithConnectEndpoint.class); - validator.process(classes, servletContext); - - } - - @Test - public void should_start_when_no_endpoints_and_spring_not_in_classpath() - throws Exception { - EndpointsValidator validator = new EndpointsValidator(); - classes.add(WithoutConnectEndpoint.class); - validator.process(classes, servletContext); - } - - @Test - public void should_start_when_CDI_environment() throws Exception { - EndpointsValidator validator = new EndpointsValidator(); - classes = null; - validator.process(classes, servletContext); - } -}