diff --git a/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java b/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java index 1390eb05aa..0ff25c6df2 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaEventBusTest.java @@ -44,11 +44,10 @@ public class GuavaEventBusTest { } @Test - public void givenUnSubscribedEvent_whenEventHandledByDeadEvent_thenSuccess() throws InterruptedException { + public void givenUnSubscribedEvent_whenEventHandledByDeadEvent_thenSuccess() { listener.resetEventsHandled(); eventBus.post(12345); - assertEquals(1, listener.getEventsHandled()); } diff --git a/pom.xml b/pom.xml index 7671d05d75..e3dc78eece 100644 --- a/pom.xml +++ b/pom.xml @@ -156,6 +156,7 @@ spring-mvc-tiles spring-mvc-velocity spring-mvc-web-vs-initializer + spring-mvc-webflow spring-mvc-xml spring-mvc-simple spring-security-openid @@ -253,4 +254,4 @@ --> - \ No newline at end of file + diff --git a/spring-mvc-webflow/README.md b/spring-mvc-webflow/README.md new file mode 100644 index 0000000000..e627fdbffe --- /dev/null +++ b/spring-mvc-webflow/README.md @@ -0,0 +1,8 @@ +========= + +## Spring MVC with Spring Web Flow + +###The Course + +### Relevant Articles: +- diff --git a/spring-mvc-webflow/pom.xml b/spring-mvc-webflow/pom.xml new file mode 100644 index 0000000000..e3c3bf92da --- /dev/null +++ b/spring-mvc-webflow/pom.xml @@ -0,0 +1,184 @@ + + 4.0.0 + com.baeldung + 0.1-SNAPSHOT + spring-mvc-webflow + + spring-mvc-webflow + war + + + + + + org.springframework + spring-web + ${org.springframework.version} + + + org.springframework + spring-webmvc + ${org.springframework.version} + + + + + org.springframework.webflow + spring-webflow + ${spring.webflow} + + + + + + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + provided + + + + javax.servlet + jstl + ${jstl.version} + runtime + + + + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + + + + junit + junit + ${junit.version} + test + + + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + + + spring-mvc-webflow + + + src/main/resources + true + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + + + + + + + + + + + 4.3.4.RELEASE + + + 2.4.4.RELEASE + + + 1.7.21 + 1.1.7 + + + 1.3 + 4.12 + 1.10.19 + + 3.1.0 + 1.2 + + 4.4.5 + 4.5.2 + + 2.9.0 + + + 3.6.0 + 2.6 + 2.19.1 + 2.7 + 1.6.1 + + + + \ No newline at end of file diff --git a/spring-mvc-webflow/src/main/java/org/baeldung/servlet/WebInitializer.java b/spring-mvc-webflow/src/main/java/org/baeldung/servlet/WebInitializer.java new file mode 100644 index 0000000000..2f52cad804 --- /dev/null +++ b/spring-mvc-webflow/src/main/java/org/baeldung/servlet/WebInitializer.java @@ -0,0 +1,35 @@ +package org.baeldung.servlet; + +import javax.servlet.ServletRegistration.Dynamic; + +import org.baeldung.spring.WebFlowConfig; +import org.baeldung.spring.WebMvcConfig; +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { + + public WebInitializer() { + super(); + } + + // API + protected Class[] getRootConfigClasses() { + return new Class[] { WebMvcConfig.class, WebFlowConfig.class }; + } + + @Override + protected Class[] getServletConfigClasses() { + return null; + } + + @Override + protected String[] getServletMappings() { + return new String[] { "/" }; + } + + @Override + protected void customizeRegistration(final Dynamic registration) { + super.customizeRegistration(registration); + } + +} diff --git a/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebFlowConfig.java b/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebFlowConfig.java new file mode 100644 index 0000000000..3d2de2a014 --- /dev/null +++ b/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebFlowConfig.java @@ -0,0 +1,43 @@ +package org.baeldung.spring; + +import java.util.Collections; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.webflow.config.AbstractFlowConfiguration; +import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; +import org.springframework.webflow.engine.builder.support.FlowBuilderServices; +import org.springframework.webflow.executor.FlowExecutor; +import org.springframework.webflow.mvc.builder.MvcViewFactoryCreator; + +@Configuration +public class WebFlowConfig extends AbstractFlowConfiguration { + + @Autowired + private WebMvcConfig webMvcConfig; + + @Bean + public FlowDefinitionRegistry flowRegistry() { + return getFlowDefinitionRegistryBuilder(flowBuilderServices()).addFlowLocation("/WEB-INF/flows/activation-flow.xml", "activationFlow").build(); + } + + @Bean + public FlowExecutor flowExecutor() { + return getFlowExecutorBuilder(flowRegistry()).build(); + } + + @Bean + public FlowBuilderServices flowBuilderServices() { + return getFlowBuilderServicesBuilder().setViewFactoryCreator(mvcViewFactoryCreator()).setDevelopmentMode(true).build(); + } + + @Bean + public MvcViewFactoryCreator mvcViewFactoryCreator() { + MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator(); + factoryCreator.setViewResolvers(Collections.singletonList(this.webMvcConfig.viewResolver())); + factoryCreator.setUseSpringBeanBinding(true); + return factoryCreator; + } + +} diff --git a/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebMvcConfig.java b/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebMvcConfig.java new file mode 100644 index 0000000000..0f0f1bacdb --- /dev/null +++ b/spring-mvc-webflow/src/main/java/org/baeldung/spring/WebMvcConfig.java @@ -0,0 +1,54 @@ +package org.baeldung.spring; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; +import org.springframework.webflow.mvc.servlet.FlowHandlerAdapter; +import org.springframework.webflow.mvc.servlet.FlowHandlerMapping; + +@EnableWebMvc // +@Configuration +// @ImportResource("classpath:/flow-definition.xml") +public class WebMvcConfig extends WebMvcConfigurerAdapter { + + @Autowired + private WebFlowConfig webFlowConfig; + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + } + + @Bean + public InternalResourceViewResolver viewResolver() { + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setViewClass(JstlView.class); + viewResolver.setPrefix("/WEB-INF/view/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } + + @Bean + public FlowHandlerMapping flowHandlerMapping() { + FlowHandlerMapping handlerMapping = new FlowHandlerMapping(); + handlerMapping.setOrder(-1); + handlerMapping.setFlowRegistry(this.webFlowConfig.flowRegistry()); + return handlerMapping; + } + + @Bean + public FlowHandlerAdapter flowHandlerAdapter() { + FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter(); + handlerAdapter.setFlowExecutor(this.webFlowConfig.flowExecutor()); + handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true); + return handlerAdapter; + } + +} diff --git a/spring-mvc-webflow/src/main/resources/flow-definition.xml b/spring-mvc-webflow/src/main/resources/flow-definition.xml new file mode 100644 index 0000000000..0240fa6dcb --- /dev/null +++ b/spring-mvc-webflow/src/main/resources/flow-definition.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-webflow/src/main/resources/logback.xml b/spring-mvc-webflow/src/main/resources/logback.xml new file mode 100644 index 0000000000..1146dade63 --- /dev/null +++ b/spring-mvc-webflow/src/main/resources/logback.xml @@ -0,0 +1,20 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/flows/activation-flow.xml b/spring-mvc-webflow/src/main/webapp/WEB-INF/flows/activation-flow.xml new file mode 100644 index 0000000000..ab9eb1a9b7 --- /dev/null +++ b/spring-mvc-webflow/src/main/webapp/WEB-INF/flows/activation-flow.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/activation.jsp b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/activation.jsp new file mode 100644 index 0000000000..ab1d8abfd1 --- /dev/null +++ b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/activation.jsp @@ -0,0 +1,23 @@ + + +

Hello World!

+<%--Start--%> +<%----%> +<%----%> + +
+ + + + +
+ +
+ + + + +
+ + + diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/failure.jsp b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/failure.jsp new file mode 100644 index 0000000000..c0945650c9 --- /dev/null +++ b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/failure.jsp @@ -0,0 +1,5 @@ + + +

Activation Failed

+ + \ No newline at end of file diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/sample.jsp b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/sample.jsp new file mode 100644 index 0000000000..7cc14b5dcd --- /dev/null +++ b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/sample.jsp @@ -0,0 +1,7 @@ + + + + +

This is the body of the sample view

+ + \ No newline at end of file diff --git a/spring-mvc-webflow/src/main/webapp/WEB-INF/view/success.jsp b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/success.jsp new file mode 100644 index 0000000000..ab6163818c --- /dev/null +++ b/spring-mvc-webflow/src/main/webapp/WEB-INF/view/success.jsp @@ -0,0 +1,5 @@ + + +

Activation Successful!

+ + \ No newline at end of file