/*
 * Copyright 2002-2020 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.
 * You may obtain a copy of the License at
 *
 *      https://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 org.springframework.web.testfixture.http.server.reactive.bootstrap;

import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicReference;

import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import reactor.netty.DisposableServer;
import reactor.netty.tcp.SslProvider.DefaultConfigurationType;

import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;

/**
 * @author Stephane Maldini
 */
public class ReactorHttpsServer extends AbstractHttpServer {

	private ReactorHttpHandlerAdapter reactorHandler;

	private reactor.netty.http.server.HttpServer reactorServer;

	private AtomicReference<DisposableServer> serverRef = new AtomicReference<>();


	@Override
	protected void initServer() throws Exception {

		SelfSignedCertificate cert = new SelfSignedCertificate();
		SslContextBuilder builder = SslContextBuilder.forServer(cert.certificate(), cert.privateKey());

		this.reactorHandler = createHttpHandlerAdapter();
		this.reactorServer = reactor.netty.http.server.HttpServer.create()
			.host(getHost())
			.port(getPort())
			.secure(spec -> spec.sslContext(builder).defaultConfiguration(DefaultConfigurationType.TCP));
	}

	private ReactorHttpHandlerAdapter createHttpHandlerAdapter() {
		return new ReactorHttpHandlerAdapter(resolveHttpHandler());
	}

	@Override
	protected void startInternal() {
		DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block();
		setPort(((InetSocketAddress) server.address()).getPort());
		this.serverRef.set(server);
	}

	@Override
	protected void stopInternal() {
		this.serverRef.get().dispose();
	}

	@Override
	protected void resetInternal() {
		this.reactorServer = null;
		this.reactorHandler = null;
		this.serverRef.set(null);
	}

}

@@ -17,17 +17,17 @@
 2002-202
-0
+1
  the ori
@@ -785,55 +785,8 @@
 e;%0A%0A
-import io.netty.handler.ssl.SslContextBuilder;%0A
 impo
@@ -901,48 +901,33 @@
 tty.
-tcp.SslProvider.DefaultConfigurationTy
+http.Http11SslContextS
 pe
+c
 ;%0A%0Ai
@@ -1354,17 +1354,16 @@
 ption %7B%0A
-%0A
 %09%09SelfSi
@@ -1416,16 +1416,22 @@
 te();%0A%09%09
+Http11
 SslConte
@@ -1436,26 +1436,42 @@
 text
-Builder builder = 
+Spec http11SslContextSpec = Http11
 SslC
@@ -1480,15 +1480,12 @@
 text
-Builder
+Spec
 .for
@@ -1709,20 +1709,25 @@
 re(s
+slContextS
 pec -%3E 
-spec.
 sslC
@@ -1736,67 +1736,44 @@
 text
-(builder).defaultConfiguration(DefaultConfigurationType.TCP
+Spec.sslContext(http11SslContextSpec
 ));%0A

Stop using deprecated Netty feature in ReactorHttpsServer