From c0d35bb14441fb1c7a6ea94ae9482a141074f938 Mon Sep 17 00:00:00 2001 From: Krunoslav Magazin Date: Sun, 28 Apr 2019 21:35:29 +0200 Subject: [PATCH 1/4] Fix eventBus test configuration. --- addons/eventbus/pom.xml | 27 ++++++++++++++----- .../events/internal/ScopedEventBusTest.java | 6 +++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/addons/eventbus/pom.xml b/addons/eventbus/pom.xml index c40fd71b..95c36bb6 100644 --- a/addons/eventbus/pom.xml +++ b/addons/eventbus/pom.xml @@ -54,15 +54,14 @@ test - org.junit.jupiter - junit-jupiter-api - 5.4.0 - test - + org.junit.jupiter + junit-jupiter-engine + 5.4.0 + test + org.springframework spring-test - 5.1.5.RELEASE test @@ -71,4 +70,20 @@ test + + + + + maven-surefire-plugin + 2.19.1 + + + org.junit.platform + junit-platform-surefire-provider + 1.1.0 + + + + + diff --git a/addons/eventbus/src/test/java/org/vaadin/spring/events/internal/ScopedEventBusTest.java b/addons/eventbus/src/test/java/org/vaadin/spring/events/internal/ScopedEventBusTest.java index 4c5a52a0..7cfbc971 100644 --- a/addons/eventbus/src/test/java/org/vaadin/spring/events/internal/ScopedEventBusTest.java +++ b/addons/eventbus/src/test/java/org/vaadin/spring/events/internal/ScopedEventBusTest.java @@ -18,13 +18,17 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.vaadin.spring.events.Event; import org.vaadin.spring.events.EventBusListener; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.HierachyTopicFilter; import org.vaadin.spring.events.annotation.EventBusListenerMethod; import org.vaadin.spring.events.annotation.EventBusListenerTopic; +import org.vaadin.spring.events.config.EventBusConfiguration; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -34,6 +38,8 @@ * * @author Petter Holmström (petter@vaadin.com) */ +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { EventBusConfiguration.class }) public class ScopedEventBusTest { ScopedEventBus.DefaultApplicationEventBus applicationEventBus; From 55cd1bef3eb805879a7a7909b4d164b29ffd6ef8 Mon Sep 17 00:00:00 2001 From: Krunoslav Magazin Date: Sun, 28 Apr 2019 21:40:34 +0200 Subject: [PATCH 2/4] Update classes in extensions boot to flow versions. --- .../boot/CustomServletOverrideTest.java | 3 ++- .../config/VaadinExtensionsConfiguration.java | 3 ++- .../spring/context/VaadinServiceFactory.java | 3 ++- .../spring/context/VaadinSessionFactory.java | 3 ++- .../request/VaadinRequestEndListener.java | 6 ++--- .../request/VaadinRequestStartListener.java | 4 +-- .../spring/servlet/Vaadin4SpringServlet.java | 20 +++++++++----- .../servlet/Vaadin4SpringServletService.java | 27 ++++++++++--------- .../shared/DefaultVaadinSharedSecurity.java | 4 +-- .../VaadinSessionClosingLogoutHandler.java | 3 ++- .../security/util/SuccessfulLoginEvent.java | 3 ++- .../web/DefaultVaadinRedirectStrategy.java | 5 ++-- 12 files changed, 51 insertions(+), 33 deletions(-) diff --git a/extensions/boot/src/test/java/org/vaadin/spring/boot/CustomServletOverrideTest.java b/extensions/boot/src/test/java/org/vaadin/spring/boot/CustomServletOverrideTest.java index 8c14b44b..57352edf 100644 --- a/extensions/boot/src/test/java/org/vaadin/spring/boot/CustomServletOverrideTest.java +++ b/extensions/boot/src/test/java/org/vaadin/spring/boot/CustomServletOverrideTest.java @@ -15,7 +15,6 @@ */ package org.vaadin.spring.boot; -import com.vaadin.server.VaadinServlet; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -26,6 +25,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import com.vaadin.flow.server.VaadinServlet; + import javax.annotation.Resource; import javax.servlet.Servlet; import java.lang.reflect.Method; diff --git a/extensions/core/src/main/java/org/vaadin/spring/config/VaadinExtensionsConfiguration.java b/extensions/core/src/main/java/org/vaadin/spring/config/VaadinExtensionsConfiguration.java index b67eb4f3..ed205004 100644 --- a/extensions/core/src/main/java/org/vaadin/spring/config/VaadinExtensionsConfiguration.java +++ b/extensions/core/src/main/java/org/vaadin/spring/config/VaadinExtensionsConfiguration.java @@ -15,7 +15,6 @@ */ package org.vaadin.spring.config; -import com.vaadin.spring.annotation.EnableVaadin; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; @@ -30,6 +29,8 @@ import org.vaadin.spring.http.HttpService; import org.vaadin.spring.http.VaadinHttpService; +import com.vaadin.flow.spring.annotation.EnableVaadin; + import javax.servlet.ServletContext; /** diff --git a/extensions/core/src/main/java/org/vaadin/spring/context/VaadinServiceFactory.java b/extensions/core/src/main/java/org/vaadin/spring/context/VaadinServiceFactory.java index 82c5aee6..dd858bd4 100644 --- a/extensions/core/src/main/java/org/vaadin/spring/context/VaadinServiceFactory.java +++ b/extensions/core/src/main/java/org/vaadin/spring/context/VaadinServiceFactory.java @@ -1,9 +1,10 @@ package org.vaadin.spring.context; -import com.vaadin.server.VaadinService; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.NamedBean; +import com.vaadin.flow.server.VaadinService; + /** * Factory bean that makes the current {@link com.vaadin.server.VaadinService} available * for injection. Only works if {@link com.vaadin.server.VaadinService#getCurrent()} does not diff --git a/extensions/core/src/main/java/org/vaadin/spring/context/VaadinSessionFactory.java b/extensions/core/src/main/java/org/vaadin/spring/context/VaadinSessionFactory.java index d16751d6..8b96ed3a 100644 --- a/extensions/core/src/main/java/org/vaadin/spring/context/VaadinSessionFactory.java +++ b/extensions/core/src/main/java/org/vaadin/spring/context/VaadinSessionFactory.java @@ -15,10 +15,11 @@ */ package org.vaadin.spring.context; -import com.vaadin.server.VaadinSession; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.NamedBean; +import com.vaadin.flow.server.VaadinSession; + /** * Factory bean that makes the current {@link com.vaadin.server.VaadinSession} available * for injection. Only works if {@link com.vaadin.server.VaadinSession#getCurrent()} does not diff --git a/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestEndListener.java b/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestEndListener.java index 4262347b..f4bd65cc 100644 --- a/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestEndListener.java +++ b/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestEndListener.java @@ -15,9 +15,9 @@ */ package org.vaadin.spring.request; -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinResponse; -import com.vaadin.server.VaadinSession; +import com.vaadin.flow.server.VaadinRequest; +import com.vaadin.flow.server.VaadinResponse; +import com.vaadin.flow.server.VaadinSession; /** * Interface to be implemented by managed (singleton) beans that want to be notified when a Vaadin request ends. diff --git a/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestStartListener.java b/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestStartListener.java index 43108b5e..6335e6b7 100644 --- a/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestStartListener.java +++ b/extensions/core/src/main/java/org/vaadin/spring/request/VaadinRequestStartListener.java @@ -15,8 +15,8 @@ */ package org.vaadin.spring.request; -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinResponse; +import com.vaadin.flow.server.VaadinRequest; +import com.vaadin.flow.server.VaadinResponse; /** * Interface to be implemented by managed (singleton) beans that want to be notified when a Vaadin request starts. diff --git a/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServlet.java b/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServlet.java index 069219d1..86c39e54 100644 --- a/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServlet.java +++ b/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServlet.java @@ -27,11 +27,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; -import com.vaadin.server.*; -import com.vaadin.spring.server.SpringVaadinServlet; +import com.vaadin.flow.function.DeploymentConfiguration; +import com.vaadin.flow.server.ServiceDestroyListener; +import com.vaadin.flow.server.ServiceException; +import com.vaadin.flow.server.SessionDestroyListener; +import com.vaadin.flow.server.SessionInitListener; +import com.vaadin.flow.server.SystemMessagesProvider; +import com.vaadin.flow.server.VaadinServletService; +import com.vaadin.flow.spring.SpringServlet; /** * An extended version of {@link com.vaadin.spring.server.SpringVaadinServlet} that provides the following additional @@ -53,11 +60,13 @@ * @author Petter Holmström (petter@vaadin.com) * @see org.vaadin.spring.servlet.Vaadin4SpringServletService */ -public class Vaadin4SpringServlet extends SpringVaadinServlet { +public class Vaadin4SpringServlet extends SpringServlet { private static final Logger LOGGER = LoggerFactory.getLogger(Vaadin4SpringServlet.class); - public Vaadin4SpringServlet() { + public Vaadin4SpringServlet(ApplicationContext context, + boolean forwardingEnforced) { + super(context, forwardingEnforced); LOGGER.info("Using custom Vaadin4Spring servlet"); } @@ -69,8 +78,7 @@ public void init(ServletConfig servletConfig) throws ServletException { @Override protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException { - final Vaadin4SpringServletService service = new Vaadin4SpringServletService(this, deploymentConfiguration, - getServiceUrlPath()); + final Vaadin4SpringServletService service = new Vaadin4SpringServletService(this, deploymentConfiguration); service.init(); return service; } diff --git a/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServletService.java b/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServletService.java index ab04a7b4..3cf95ec7 100644 --- a/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServletService.java +++ b/extensions/core/src/main/java/org/vaadin/spring/servlet/Vaadin4SpringServletService.java @@ -15,13 +15,7 @@ */ package org.vaadin.spring.servlet; -import com.vaadin.server.DeploymentConfiguration; -import com.vaadin.server.ServiceException; -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinResponse; -import com.vaadin.server.VaadinServlet; -import com.vaadin.server.VaadinSession; -import com.vaadin.spring.server.SpringVaadinServletService; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.context.WebApplicationContext; @@ -29,9 +23,17 @@ import org.vaadin.spring.request.VaadinRequestEndListener; import org.vaadin.spring.request.VaadinRequestStartListener; +import com.vaadin.flow.function.DeploymentConfiguration; +import com.vaadin.flow.server.ServiceException; +import com.vaadin.flow.server.VaadinRequest; +import com.vaadin.flow.server.VaadinResponse; +import com.vaadin.flow.server.VaadinServlet; +import com.vaadin.flow.server.VaadinSession; +import com.vaadin.flow.spring.SpringVaadinServletService; + /** - * Extended version of {@link com.vaadin.spring.server.SpringVaadinServletService} that adds support - * for {@link org.vaadin.spring.request.VaadinRequestStartListener}s and {@link org.vaadin.spring.request.VaadinRequestEndListener}s. + * Extended version of {@link com.vaadin.flow.spring.SpringVaadinServletService} that adds support + * for {@link VaadinRequestStartListener}s and {@link org.vaadin.spring.request.VaadinRequestEndListener}s. * * @author Petter Holmström (petter@vaadin.com) */ @@ -50,10 +52,11 @@ public class Vaadin4SpringServletService extends SpringVaadinServletService { * with a slash) or null for default * @throws ServiceException */ - public Vaadin4SpringServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration, String serviceUrl) throws ServiceException { - super(servlet, deploymentConfiguration, serviceUrl); + public Vaadin4SpringServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration) throws ServiceException { + super(servlet, deploymentConfiguration, WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext())); + this.applicationContext = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext()); logger.info("Using custom Vaadin4Spring servlet service"); - applicationContext = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext()); +// applicationContext = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext()); } @Override diff --git a/extensions/security/src/main/java/org/vaadin/spring/security/shared/DefaultVaadinSharedSecurity.java b/extensions/security/src/main/java/org/vaadin/spring/security/shared/DefaultVaadinSharedSecurity.java index 524551b7..91a1fbf2 100644 --- a/extensions/security/src/main/java/org/vaadin/spring/security/shared/DefaultVaadinSharedSecurity.java +++ b/extensions/security/src/main/java/org/vaadin/spring/security/shared/DefaultVaadinSharedSecurity.java @@ -34,8 +34,8 @@ import org.vaadin.spring.http.HttpService; import org.vaadin.spring.security.AbstractVaadinSecurity; -import com.vaadin.server.VaadinSession; -import com.vaadin.server.WrappedSession; +import com.vaadin.flow.server.VaadinSession; +import com.vaadin.flow.server.WrappedSession; /** * Default implementation of {@link VaadinSharedSecurity}. diff --git a/extensions/security/src/main/java/org/vaadin/spring/security/shared/VaadinSessionClosingLogoutHandler.java b/extensions/security/src/main/java/org/vaadin/spring/security/shared/VaadinSessionClosingLogoutHandler.java index 851c131c..fc40380d 100644 --- a/extensions/security/src/main/java/org/vaadin/spring/security/shared/VaadinSessionClosingLogoutHandler.java +++ b/extensions/security/src/main/java/org/vaadin/spring/security/shared/VaadinSessionClosingLogoutHandler.java @@ -25,7 +25,8 @@ import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.logout.LogoutHandler; -import com.vaadin.server.VaadinSession; +import com.vaadin.flow.server.VaadinSession; + /** * A {@link LogoutHandler} that closes all the Vaadin sessions in the current HTTP servlet session. diff --git a/extensions/security/src/main/java/org/vaadin/spring/security/util/SuccessfulLoginEvent.java b/extensions/security/src/main/java/org/vaadin/spring/security/util/SuccessfulLoginEvent.java index 7d57616d..16d41f87 100644 --- a/extensions/security/src/main/java/org/vaadin/spring/security/util/SuccessfulLoginEvent.java +++ b/extensions/security/src/main/java/org/vaadin/spring/security/util/SuccessfulLoginEvent.java @@ -15,10 +15,11 @@ */ package org.vaadin.spring.security.util; -import com.vaadin.ui.UI; import org.springframework.context.ApplicationEvent; import org.springframework.security.core.Authentication; +import com.vaadin.flow.component.UI; + /** * Event that can be published using either the Spring event publisher or the Vaadin4Spring event bus when a user * logs in successfully. See the security-sample-managed sample application for an example of how it can be used. diff --git a/extensions/security/src/main/java/org/vaadin/spring/security/web/DefaultVaadinRedirectStrategy.java b/extensions/security/src/main/java/org/vaadin/spring/security/web/DefaultVaadinRedirectStrategy.java index 5ed56d58..aa76b84b 100644 --- a/extensions/security/src/main/java/org/vaadin/spring/security/web/DefaultVaadinRedirectStrategy.java +++ b/extensions/security/src/main/java/org/vaadin/spring/security/web/DefaultVaadinRedirectStrategy.java @@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.web.util.UrlUtils; -import com.vaadin.ui.UI; +import com.vaadin.flow.component.UI; /** * Default implementation of {@link VaadinRedirectStrategy}. Based on @@ -44,7 +44,8 @@ public class DefaultVaadinRedirectStrategy implements VaadinRedirectStrategy { public void sendRedirect(String url) { final String redirectUrl = calculateRedirectUrl(servletContext.getContextPath(), url); LOGGER.debug("Redirecting to [" + redirectUrl + "]"); - UI.getCurrent().getPage().setLocation(redirectUrl); + // TODO check change from redirectUrl to url (relative path) + UI.getCurrent().navigate(redirectUrl); } private String calculateRedirectUrl(String contextPath, String url) { From 93468ccfa5dd2af9b48843f93642c53460380432 Mon Sep 17 00:00:00 2001 From: Krunoslav Magazin Date: Sun, 28 Apr 2019 21:41:50 +0200 Subject: [PATCH 3/4] Partial update of import classes to flow in extension boot and security. --- .../org/vaadin/spring/boot/ExtensionsAutoConfiguration.java | 4 ++-- .../navigation/PreAuthorizeViewInstanceAccessControl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/boot/src/main/java/org/vaadin/spring/boot/ExtensionsAutoConfiguration.java b/extensions/boot/src/main/java/org/vaadin/spring/boot/ExtensionsAutoConfiguration.java index 16401333..c5f7a1b6 100644 --- a/extensions/boot/src/main/java/org/vaadin/spring/boot/ExtensionsAutoConfiguration.java +++ b/extensions/boot/src/main/java/org/vaadin/spring/boot/ExtensionsAutoConfiguration.java @@ -15,8 +15,7 @@ */ package org.vaadin.spring.boot; -import com.vaadin.server.VaadinServlet; -import com.vaadin.spring.boot.VaadinAutoConfiguration; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -29,6 +28,7 @@ import org.vaadin.spring.config.VaadinExtensionsConfiguration; import org.vaadin.spring.servlet.Vaadin4SpringServlet; +import com.vaadin.flow.server.VaadinServlet; /** * Auto configuration for Vaadin4Spring core extensions. * diff --git a/extensions/security/src/main/java/org/vaadin/spring/security/navigation/PreAuthorizeViewInstanceAccessControl.java b/extensions/security/src/main/java/org/vaadin/spring/security/navigation/PreAuthorizeViewInstanceAccessControl.java index d8dc4b70..1f5c539e 100644 --- a/extensions/security/src/main/java/org/vaadin/spring/security/navigation/PreAuthorizeViewInstanceAccessControl.java +++ b/extensions/security/src/main/java/org/vaadin/spring/security/navigation/PreAuthorizeViewInstanceAccessControl.java @@ -15,9 +15,9 @@ */ package org.vaadin.spring.security.navigation; +import com.vaadin.flow.component.UI; import com.vaadin.navigator.View; import com.vaadin.spring.access.ViewInstanceAccessControl; -import com.vaadin.ui.UI; import org.aopalliance.intercept.MethodInvocation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From ceca1ce2ebc342751c7be7daeb1153d682d3ecf6 Mon Sep 17 00:00:00 2001 From: Krunoslav Magazin Date: Sun, 28 Apr 2019 21:55:07 +0200 Subject: [PATCH 4/4] Update eventbus README, add enable eventbus instruction. --- addons/eventbus/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/eventbus/README.md b/addons/eventbus/README.md index 3dd3e532..29722828 100644 --- a/addons/eventbus/README.md +++ b/addons/eventbus/README.md @@ -35,6 +35,15 @@ creating a singleton instance of ```ApplicationContextEventBroker```: return new ApplicationContextEventBroker(eventBus); } ``` +# Enable Event Bus + +On configuration class add annotation: +```java + @EnableEventBus + @Configuration + public class MyConfiguration {...} +``` + # Event Bus Topics Events can be published with an optional string based topic. This will distinguish which listener methods will be called. Therefore, when it's the intent to use topics, a topic must be provided when publishing events and at the listener methods.