From 8109a8c288be9140b1304ed52c3a00839c8cb3bc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 4 Aug 2016 03:04:33 +0200 Subject: [PATCH] Updated ServletHttpHandlerAdapter usage --- .../reactive/bootstrap/JettyHttpServer.java | 19 +++++++---------- .../reactive/bootstrap/TomcatHttpServer.java | 21 +++++++------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java index 485af7594b..ae41392538 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,26 +28,18 @@ import org.springframework.util.Assert; /** * @author Rossen Stoyanchev */ -public class JettyHttpServer extends HttpServerSupport implements InitializingBean, HttpServer { +public class JettyHttpServer extends HttpServerSupport implements HttpServer, InitializingBean { private Server jettyServer; private boolean running; - @Override - public boolean isRunning() { - return this.running; - } - @Override public void afterPropertiesSet() throws Exception { - this.jettyServer = new Server(); - Assert.notNull(getHttpHandler()); - ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(); - servlet.setHandler(getHttpHandler()); + ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(getHttpHandler()); ServletHolder servletHolder = new ServletHolder(servlet); ServletContextHandler contextHandler = new ServletContextHandler(this.jettyServer, "", false, false); @@ -86,4 +78,9 @@ public class JettyHttpServer extends HttpServerSupport implements InitializingBe } } + @Override + public boolean isRunning() { + return this.running; + } + } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java index 1a47951590..1a686bbece 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/TomcatHttpServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,13 +24,11 @@ import org.apache.catalina.startup.Tomcat; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; -import org.springframework.util.Assert; - /** * @author Rossen Stoyanchev */ -public class TomcatHttpServer extends HttpServerSupport implements InitializingBean, HttpServer { +public class TomcatHttpServer extends HttpServerSupport implements HttpServer, InitializingBean { private Tomcat tomcatServer; @@ -47,14 +45,8 @@ public class TomcatHttpServer extends HttpServerSupport implements InitializingB } - @Override - public boolean isRunning() { - return this.running; - } - @Override public void afterPropertiesSet() throws Exception { - this.tomcatServer = new Tomcat(); if (this.baseDir != null) { this.tomcatServer.setBaseDir(baseDir); @@ -62,9 +54,7 @@ public class TomcatHttpServer extends HttpServerSupport implements InitializingB this.tomcatServer.setHostname(getHost()); this.tomcatServer.setPort(getPort()); - Assert.notNull(getHttpHandler()); - ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(); - servlet.setHandler(getHttpHandler()); + ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(getHttpHandler()); File base = new File(System.getProperty("java.io.tmpdir")); Context rootContext = tomcatServer.addContext("", base.getAbsolutePath()); @@ -100,4 +90,9 @@ public class TomcatHttpServer extends HttpServerSupport implements InitializingB } } + @Override + public boolean isRunning() { + return this.running; + } + }