mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-30 00:32:14 +00:00
Revert "webflux-form sample uses Tomcat"
This reverts commit 67bb91bb76beb6d1d6e5118770217f66b4074c86. We can use Netty again now that reactor/reactor-netty#248 has been resolved. Fixes: gh-4923
This commit is contained in:
parent
6a0833165a
commit
fe40952908
@ -20,8 +20,9 @@ dependencies {
|
|||||||
compile project(':spring-security-core')
|
compile project(':spring-security-core')
|
||||||
compile project(':spring-security-config')
|
compile project(':spring-security-config')
|
||||||
compile project(':spring-security-web')
|
compile project(':spring-security-web')
|
||||||
compile 'org.apache.tomcat.embed:tomcat-embed-core'
|
|
||||||
compile 'com.fasterxml.jackson.core:jackson-databind'
|
compile 'com.fasterxml.jackson.core:jackson-databind'
|
||||||
|
compile 'io.netty:netty-buffer'
|
||||||
|
compile 'io.projectreactor.ipc:reactor-netty'
|
||||||
compile 'org.springframework:spring-context'
|
compile 'org.springframework:spring-context'
|
||||||
compile 'org.springframework:spring-webflux'
|
compile 'org.springframework:spring-webflux'
|
||||||
compile 'org.thymeleaf:thymeleaf-spring5'
|
compile 'org.thymeleaf:thymeleaf-spring5'
|
||||||
|
@ -28,20 +28,17 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
import sample.webdriver.IndexPage;
|
import sample.webdriver.IndexPage;
|
||||||
import sample.webdriver.LoginPage;
|
import sample.webdriver.LoginPage;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@ContextConfiguration(classes = WebfluxFormApplication.class)
|
@ContextConfiguration(classes = WebfluxFormApplication.class)
|
||||||
@TestPropertySource(properties = "server.port=#{T(sample.WebfluxFormApplicationTests).availablePort()}")
|
@TestPropertySource(properties = "server.port=0")
|
||||||
public class WebfluxFormApplicationTests {
|
public class WebfluxFormApplicationTests {
|
||||||
WebDriver driver;
|
WebDriver driver;
|
||||||
|
|
||||||
@Value("#{@tomcat.server.port}")
|
@Value("#{@nettyContext.address().getPort()}")
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -79,12 +76,4 @@ public class WebfluxFormApplicationTests {
|
|||||||
.assertAt()
|
.assertAt()
|
||||||
.assertLogout();
|
.assertLogout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int availablePort() {
|
|
||||||
try(ServerSocket socket = new ServerSocket(0)) {
|
|
||||||
return socket.getLocalPort();
|
|
||||||
} catch(IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,20 +16,15 @@
|
|||||||
|
|
||||||
package sample;
|
package sample;
|
||||||
|
|
||||||
import org.apache.catalina.Context;
|
|
||||||
import org.apache.catalina.startup.Tomcat;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.*;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.server.reactive.HttpHandler;
|
import org.springframework.http.server.reactive.HttpHandler;
|
||||||
import org.springframework.http.server.reactive.ServletHttpHandlerAdapter;
|
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
||||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||||
|
import reactor.ipc.netty.NettyContext;
|
||||||
import javax.servlet.Servlet;
|
import reactor.ipc.netty.http.server.HttpServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
@ -43,26 +38,19 @@ public class WebfluxFormApplication {
|
|||||||
private int port = 8080;
|
private int port = 8080;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Object lock = new Object();
|
|
||||||
try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
WebfluxFormApplication.class)) {
|
WebfluxFormApplication.class)) {
|
||||||
synchronized (lock) {
|
context.getBean(NettyContext.class).onClose().block();
|
||||||
lock.wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(destroyMethod = "stop", initMethod = "start")
|
@Profile("default")
|
||||||
public Tomcat tomcat(ApplicationContext context) throws Exception {
|
@Bean
|
||||||
|
public NettyContext nettyContext(ApplicationContext context) {
|
||||||
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context)
|
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context)
|
||||||
.build();
|
.build();
|
||||||
Servlet servlet = new ServletHttpHandlerAdapter(handler);
|
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
|
||||||
Tomcat server = new Tomcat();
|
HttpServer httpServer = HttpServer.create("localhost", port);
|
||||||
server.setPort(this.port);
|
return httpServer.newHandler(adapter).block();
|
||||||
server.getServer().setPort(this.port);
|
|
||||||
Context rootContext = server.addContext("", System.getProperty("java.io.tmpdir"));
|
|
||||||
Tomcat.addServlet(rootContext, "servlet", servlet);
|
|
||||||
rootContext.addServletMapping("/", "servlet");
|
|
||||||
return server;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user