Skip to content

Commit 9dfbc25

Browse files
committed
Polish
1 parent e130c00 commit 9dfbc25

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public RedisMetricRepository(RedisConnectionFactory redisConnectionFactory) {
6060
this.redisOperations = RedisUtils.stringTemplate(redisConnectionFactory);
6161
this.zSetOperations = this.redisOperations.boundZSetOps(this.key);
6262
}
63-
63+
6464
@Override
6565
public void afterPropertiesSet() {
6666
if (!DEFAULT_METRICS_PREFIX.equals(this.prefix)) {
@@ -72,7 +72,7 @@ public void afterPropertiesSet() {
7272
this.zSetOperations = this.redisOperations.boundZSetOps(this.key);
7373
}
7474
}
75-
75+
7676
/**
7777
* The prefix for all metrics keys.
7878
* @param prefix the prefix to set for all metrics keys

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/ApplicationPidListener.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626
import org.springframework.context.ApplicationListener;
2727
import org.springframework.core.Ordered;
2828
import org.springframework.util.Assert;
29-
import org.springframework.util.SystemPropertyUtils;
3029

3130
/**
3231
* An {@link org.springframework.context.ApplicationListener} that saves application PID
33-
* into file. This application listener will be triggered exactly once per JVM, and the file
34-
* name can be overridden at runtime with a System property or environment variable named
35-
* "PIDFILE" (or "pidfile").
32+
* into file. This application listener will be triggered exactly once per JVM, and the
33+
* file name can be overridden at runtime with a System property or environment variable
34+
* named "PIDFILE" (or "pidfile").
3635
*
3736
* @author Jakub Kubrynski
3837
* @author Dave Syer
@@ -46,6 +45,8 @@ public class ApplicationPidListener implements
4645

4746
private static final String DEFAULT_FILE_NAME = "application.pid";
4847

48+
private static final String[] PROPERTY_VARIABLES = { "PIDFILE", "pidfile" };
49+
4950
private static final AtomicBoolean created = new AtomicBoolean(false);
5051

5152
private int order = Ordered.HIGHEST_PRECEDENCE + 13;
@@ -74,10 +75,30 @@ public ApplicationPidListener(String filename) {
7475
*/
7576
public ApplicationPidListener(File file) {
7677
Assert.notNull(file, "File must not be null");
77-
String actual = SystemPropertyUtils.resolvePlaceholders("${PIDFILE}", true);
78-
actual = !actual.contains("$") ? actual : SystemPropertyUtils.resolvePlaceholders("${pidfile}", true);
79-
actual = !actual.contains("$") ? actual : file.getAbsolutePath();
80-
this.file = new File(actual);
78+
String override = getOverride();
79+
if (override != null) {
80+
this.file = new File(override);
81+
}
82+
else {
83+
this.file = file;
84+
}
85+
}
86+
87+
private String getOverride() {
88+
for (String property : PROPERTY_VARIABLES) {
89+
try {
90+
String override = System.getProperty(property);
91+
override = (override != null ? override : System.getenv(property));
92+
if (override != null) {
93+
return override;
94+
}
95+
}
96+
catch (Throwable ex) {
97+
System.err.println("Could not resolve '" + property
98+
+ "' as system property: " + ex);
99+
}
100+
}
101+
return null;
81102
}
82103

83104
@Override

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidListenerTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public void overridePidFile() throws Exception {
6767
System.setProperty("PIDFILE", this.temporaryFolder.newFile().getAbsolutePath());
6868
ApplicationPidListener listener = new ApplicationPidListener(file);
6969
listener.onApplicationEvent(EVENT);
70-
assertThat(FileCopyUtils.copyToString(new FileReader(System.getProperty("PIDFILE"))), not(isEmptyString()));
70+
assertThat(
71+
FileCopyUtils.copyToString(new FileReader(System.getProperty("PIDFILE"))),
72+
not(isEmptyString()));
7173
}
7274

7375
}

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,21 +465,20 @@ HTTPS connector:
465465

466466
[[howto-use-tomcat-behind-a-proxy-server]]
467467
=== Use Tomcat behind a front-end proxy server
468-
Spring Boot will automatically configure Tomcat's `RemoteIpValve` if you enable it. This allows you to
469-
transparently use the standard `x-forwarded-for` and `x-forwarded-proto` headers that
470-
most front-end proxy servers add. The valve is switched on by setting one or both of these
471-
properties to something non-empty (these are the conventional values used by most proxies, and if
472-
you only set one the other will be set automatically):
468+
Spring Boot will automatically configure Tomcat's `RemoteIpValve` if you enable it. This
469+
allows you to transparently use the standard `x-forwarded-for` and `x-forwarded-proto`
470+
headers that most front-end proxy servers add. The valve is switched on by setting one or
471+
both of these properties to something non-empty (these are the conventional values used by
472+
most proxies, and if you only set one the other will be set automatically):
473473

474474
[indent=0]
475475
----
476476
server.tomcat.remote_ip_header=x-forwarded-for
477477
server.tomcat.protocol_header=x-forwarded-protocol
478478
----
479479

480-
If your proxy uses different headers you can
481-
customize the valve's configuration by adding some entries to `application.properties`,
482-
e.g.
480+
If your proxy uses different headers you can customize the valve's configuration by adding
481+
some entries to `application.properties`, e.g.
483482

484483
[indent=0]
485484
----

0 commit comments

Comments
 (0)