Catch IllegalStateException if VaultEnvironmentRepository is accessed outside a web context. Fixes #2085 (#2187)

Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
Ryan Baxter
2022-11-10 14:49:07 -05:00
committed by GitHub
parent 8e4be15ece
commit 218b7a42dd

View File

@@ -25,6 +25,9 @@ import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.cloud.config.environment.Environment;
@@ -44,6 +47,8 @@ import static org.springframework.cloud.config.client.ConfigClientProperties.STA
*/
public abstract class AbstractVaultEnvironmentRepository implements EnvironmentRepository, Ordered {
private static Log log = LogFactory.getLog(AbstractVaultEnvironmentRepository.class);
// TODO: move to watchState:String on findOne?
protected final ObjectProvider<HttpServletRequest> request;
@@ -104,8 +109,14 @@ public abstract class AbstractVaultEnvironmentRepository implements EnvironmentR
private String getWatchState() {
HttpServletRequest servletRequest = this.request.getIfAvailable();
if (servletRequest != null) {
String state = servletRequest.getHeader(STATE_HEADER);
return this.watch.watch(state);
try {
String state = servletRequest.getHeader(STATE_HEADER);
return this.watch.watch(state);
}
catch (IllegalStateException e) {
log.debug("Could not get state.", e);
return null;
}
}
return null;
}