From bd9f293d8b764e11c316d009f70624c0eda94964 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 16 Apr 2019 13:18:03 -0400 Subject: [PATCH] Adds new env post processor to add default gateway rsocket port. --- ...atewayRSocketEnvironmentPostProcessor.java | 42 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 4 ++ 2 files changed, 46 insertions(+) create mode 100644 spring-cloud-gateway-rsocket/src/main/java/org/springframework/cloud/gateway/rsocket/autoconfigure/GatewayRSocketEnvironmentPostProcessor.java diff --git a/spring-cloud-gateway-rsocket/src/main/java/org/springframework/cloud/gateway/rsocket/autoconfigure/GatewayRSocketEnvironmentPostProcessor.java b/spring-cloud-gateway-rsocket/src/main/java/org/springframework/cloud/gateway/rsocket/autoconfigure/GatewayRSocketEnvironmentPostProcessor.java new file mode 100644 index 00000000..12f93f57 --- /dev/null +++ b/spring-cloud-gateway-rsocket/src/main/java/org/springframework/cloud/gateway/rsocket/autoconfigure/GatewayRSocketEnvironmentPostProcessor.java @@ -0,0 +1,42 @@ +/* + * Copyright 2013-2019 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.cloud.gateway.rsocket.autoconfigure; + +import java.util.Collections; +import java.util.Map; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; + +public class GatewayRSocketEnvironmentPostProcessor implements EnvironmentPostProcessor { + + @Override + public void postProcessEnvironment(ConfigurableEnvironment env, + SpringApplication application) { + Boolean enabled = env.getProperty("spring.cloud.gateway.rsocket.enabled", + Boolean.class, true); + if (enabled && !env.containsProperty("spring.rsocket.server.port")) { + Map map = Collections + .singletonMap("spring.rsocket.server.port", 7002); + env.getPropertySources() + .addLast(new MapPropertySource("Default Gateway RSocket Port", map)); + } + } + +} diff --git a/spring-cloud-gateway-rsocket/src/main/resources/META-INF/spring.factories b/spring-cloud-gateway-rsocket/src/main/resources/META-INF/spring.factories index 4cf65ad1..c7338a85 100644 --- a/spring-cloud-gateway-rsocket/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-gateway-rsocket/src/main/resources/META-INF/spring.factories @@ -1,3 +1,7 @@ # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.cloud.gateway.rsocket.autoconfigure.GatewayRSocketAutoConfiguration + +# Environment Post Processors +org.springframework.boot.env.EnvironmentPostProcessor=\ +org.springframework.cloud.gateway.rsocket.autoconfigure.GatewayRSocketEnvironmentPostProcessor