Skip to content

Commit 51e34a3

Browse files
MichaelMorrisEstvy
andauthored
Fix the reload of key and trust stores on reconfiguration (#2767)
Co-authored-by: Michael Morris <[email protected]> Co-authored-by: Volkan Yazıcı <[email protected]>
1 parent 0536203 commit 51e34a3

File tree

53 files changed

+1583
-1190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1583
-1190
lines changed

log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/package-info.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
* limitations under the license.
1616
*/
1717
@Export
18-
@Version("2.21.1")
18+
@Version("2.25.0")
19+
@BaselineIgnore("2.25.0")
1920
package org.apache.logging.log4j.core.test;
2021

22+
import aQute.bnd.annotation.baseline.BaselineIgnore;
2123
import org.osgi.annotation.bundle.Export;
2224
import org.osgi.annotation.versioning.Version;

log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/ListErrorHandler.java renamed to log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/BufferingErrorHandler.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,55 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.logging.log4j.core.test;
17+
package org.apache.logging.log4j.core.appender;
1818

1919
import java.util.ArrayList;
20+
import java.util.Collections;
2021
import java.util.List;
21-
import java.util.stream.Stream;
2222
import org.apache.logging.log4j.Level;
2323
import org.apache.logging.log4j.core.ErrorHandler;
2424
import org.apache.logging.log4j.core.LogEvent;
2525
import org.apache.logging.log4j.message.SimpleMessage;
2626
import org.apache.logging.log4j.status.StatusData;
2727
import org.apache.logging.log4j.util.StackLocatorUtil;
2828

29-
public class ListErrorHandler implements ErrorHandler {
29+
/**
30+
* {@link ErrorHandler} implementation buffering invocations in the form of {@link StatusData}.
31+
*/
32+
final class BufferingErrorHandler implements ErrorHandler {
33+
34+
private final List<StatusData> statusDataBuffer = Collections.synchronizedList(new ArrayList<>());
3035

31-
private final ArrayList<StatusData> statusData = new ArrayList<>();
36+
BufferingErrorHandler() {}
3237

33-
private void addStatusData(final String msg, final Throwable t) {
34-
synchronized (statusData) {
35-
final StackTraceElement caller = StackLocatorUtil.getStackTraceElement(3);
36-
final String threadName = Thread.currentThread().getName();
37-
statusData.add(new StatusData(caller, Level.ERROR, new SimpleMessage(msg), t, threadName));
38-
}
38+
private void addStatusData(final String message, final Throwable throwable) {
39+
final StackTraceElement caller = StackLocatorUtil.getStackTraceElement(3);
40+
final String threadName = Thread.currentThread().getName();
41+
final StatusData statusData =
42+
new StatusData(caller, Level.ERROR, new SimpleMessage(message), throwable, threadName);
43+
statusDataBuffer.add(statusData);
3944
}
4045

4146
@Override
42-
public void error(String msg) {
43-
addStatusData(msg, null);
47+
public void error(String message) {
48+
addStatusData(message, null);
4449
}
4550

4651
@Override
47-
public void error(String msg, Throwable t) {
48-
addStatusData(msg, t);
52+
public void error(final String message, final Throwable throwable) {
53+
addStatusData(message, throwable);
4954
}
5055

5156
@Override
52-
public void error(String msg, LogEvent event, Throwable t) {
53-
addStatusData(msg, t);
57+
public void error(final String message, final LogEvent event, final Throwable throwable) {
58+
addStatusData(message, throwable);
5459
}
5560

5661
public void clear() {
57-
synchronized (statusData) {
58-
statusData.clear();
59-
}
60-
}
61-
62-
public Stream<StatusData> getStatusData() {
63-
synchronized (statusData) {
64-
return ((List<StatusData>) statusData.clone()).stream();
65-
}
62+
statusDataBuffer.clear();
6663
}
6764

68-
public Stream<StatusData> findStatusData(String regex) {
69-
return getStatusData()
70-
.filter(data -> data.getMessage().getFormattedMessage().matches(regex));
65+
public List<StatusData> getBuffer() {
66+
return statusDataBuffer;
7167
}
7268
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.logging.log4j.core.appender;
18+
19+
import java.net.InetSocketAddress;
20+
import java.util.Arrays;
21+
import java.util.List;
22+
import java.util.stream.Collectors;
23+
import org.apache.logging.log4j.core.net.TcpSocketManager;
24+
25+
/**
26+
* {@link TcpSocketManager.HostResolver} implementation always resolving to the given list of {@link #addresses}.
27+
*/
28+
final class FixedHostResolver extends TcpSocketManager.HostResolver {
29+
30+
private final List<InetSocketAddress> addresses;
31+
32+
private FixedHostResolver(final List<InetSocketAddress> addresses) {
33+
this.addresses = addresses;
34+
}
35+
36+
static FixedHostResolver ofServers(final LineReadingTcpServer... servers) {
37+
final List<InetSocketAddress> addresses = Arrays.stream(servers)
38+
.map(server -> (InetSocketAddress) server.getServerSocket().getLocalSocketAddress())
39+
.collect(Collectors.toList());
40+
return new FixedHostResolver(addresses);
41+
}
42+
43+
@Override
44+
public List<InetSocketAddress> resolveHost(final String ignoredHost, final int ignoredPort) {
45+
return addresses;
46+
}
47+
}

0 commit comments

Comments
 (0)