Skip to content

Commit adb9747

Browse files
committed
Merge branch '3.2.x' into 3.3.x
Closes gh-41214
2 parents c8febf4 + b8927eb commit adb9747

File tree

4 files changed

+35
-62
lines changed

4 files changed

+35
-62
lines changed

Diff for: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,9 +61,11 @@ ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
6161
private static ActiveMQConnectionFactory createJmsConnectionFactory(ActiveMQProperties properties,
6262
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers,
6363
ActiveMQConnectionDetails connectionDetails) {
64-
return new ActiveMQConnectionFactoryFactory(properties, factoryCustomizers.orderedStream().toList(),
65-
connectionDetails)
66-
.createConnectionFactory(ActiveMQConnectionFactory.class);
64+
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionDetails.getUser(),
65+
connectionDetails.getPassword(), connectionDetails.getBrokerUrl());
66+
new ActiveMQConnectionFactoryConfigurer(properties, factoryCustomizers.orderedStream().toList())
67+
.configure(connectionFactory);
68+
return connectionFactory;
6769
}
6870

6971
@Configuration(proxyBeanMethods = false)
@@ -98,9 +100,10 @@ static class PooledConnectionFactoryConfiguration {
98100
JmsPoolConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
99101
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers,
100102
ActiveMQConnectionDetails connectionDetails) {
101-
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties,
102-
factoryCustomizers.orderedStream().toList(), connectionDetails)
103-
.createConnectionFactory(ActiveMQConnectionFactory.class);
103+
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionDetails.getUser(),
104+
connectionDetails.getPassword(), connectionDetails.getBrokerUrl());
105+
new ActiveMQConnectionFactoryConfigurer(properties, factoryCustomizers.orderedStream().toList())
106+
.configure(connectionFactory);
104107
return new JmsPoolConnectionFactoryFactory(properties.getPool())
105108
.createPooledConnectionFactory(connectionFactory);
106109
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,51 +16,37 @@
1616

1717
package org.springframework.boot.autoconfigure.jms.activemq;
1818

19-
import java.lang.reflect.InvocationTargetException;
2019
import java.util.Collections;
2120
import java.util.List;
2221

2322
import org.apache.activemq.ActiveMQConnectionFactory;
2423

2524
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties.Packages;
2625
import org.springframework.util.Assert;
27-
import org.springframework.util.StringUtils;
2826

2927
/**
30-
* Factory to create a {@link ActiveMQConnectionFactory} instance from properties defined
31-
* in {@link ActiveMQProperties}.
28+
* Class to configure an {@link ActiveMQConnectionFactory} instance from properties
29+
* defined in {@link ActiveMQProperties} and any
30+
* {@link ActiveMQConnectionFactoryCustomizer customizers}.
3231
*
3332
* @author Phillip Webb
3433
* @author Venil Noronha
3534
* @author Eddú Meléndez
3635
*/
37-
class ActiveMQConnectionFactoryFactory {
36+
class ActiveMQConnectionFactoryConfigurer {
3837

3938
private final ActiveMQProperties properties;
4039

4140
private final List<ActiveMQConnectionFactoryCustomizer> factoryCustomizers;
4241

43-
private final ActiveMQConnectionDetails connectionDetails;
44-
45-
ActiveMQConnectionFactoryFactory(ActiveMQProperties properties,
46-
List<ActiveMQConnectionFactoryCustomizer> factoryCustomizers, ActiveMQConnectionDetails connectionDetails) {
42+
ActiveMQConnectionFactoryConfigurer(ActiveMQProperties properties,
43+
List<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
4744
Assert.notNull(properties, "Properties must not be null");
4845
this.properties = properties;
4946
this.factoryCustomizers = (factoryCustomizers != null) ? factoryCustomizers : Collections.emptyList();
50-
this.connectionDetails = connectionDetails;
51-
}
52-
53-
<T extends ActiveMQConnectionFactory> T createConnectionFactory(Class<T> factoryClass) {
54-
try {
55-
return doCreateConnectionFactory(factoryClass);
56-
}
57-
catch (Exception ex) {
58-
throw new IllegalStateException("Unable to create ActiveMQConnectionFactory", ex);
59-
}
6047
}
6148

62-
private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Class<T> factoryClass) throws Exception {
63-
T factory = createConnectionFactoryInstance(factoryClass);
49+
void configure(ActiveMQConnectionFactory factory) {
6450
if (this.properties.getCloseTimeout() != null) {
6551
factory.setCloseTimeout((int) this.properties.getCloseTimeout().toMillis());
6652
}
@@ -76,19 +62,6 @@ private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Class<
7662
factory.setTrustedPackages(packages.getTrusted());
7763
}
7864
customize(factory);
79-
return factory;
80-
}
81-
82-
private <T extends ActiveMQConnectionFactory> T createConnectionFactoryInstance(Class<T> factoryClass)
83-
throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
84-
String brokerUrl = this.connectionDetails.getBrokerUrl();
85-
String user = this.connectionDetails.getUser();
86-
String password = this.connectionDetails.getPassword();
87-
if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) {
88-
return factoryClass.getConstructor(String.class, String.class, String.class)
89-
.newInstance(user, password, brokerUrl);
90-
}
91-
return factoryClass.getConstructor(String.class).newInstance(brokerUrl);
9265
}
9366

9467
private void customize(ActiveMQConnectionFactory connectionFactory) {

Diff for: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,9 +49,10 @@ class ActiveMQXAConnectionFactoryConfiguration {
4949
ConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
5050
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers, XAConnectionFactoryWrapper wrapper,
5151
ActiveMQConnectionDetails connectionDetails) throws Exception {
52-
ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties,
53-
factoryCustomizers.orderedStream().toList(), connectionDetails)
54-
.createConnectionFactory(ActiveMQXAConnectionFactory.class);
52+
ActiveMQXAConnectionFactory connectionFactory = new ActiveMQXAConnectionFactory(connectionDetails.getUser(),
53+
connectionDetails.getPassword(), connectionDetails.getBrokerUrl());
54+
new ActiveMQConnectionFactoryConfigurer(properties, factoryCustomizers.orderedStream().toList())
55+
.configure(connectionFactory);
5556
return wrapper.wrapConnectionFactory(connectionFactory);
5657
}
5758

@@ -61,9 +62,11 @@ ConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
6162
ActiveMQConnectionFactory nonXaJmsConnectionFactory(ActiveMQProperties properties,
6263
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers,
6364
ActiveMQConnectionDetails connectionDetails) {
64-
return new ActiveMQConnectionFactoryFactory(properties, factoryCustomizers.orderedStream().toList(),
65-
connectionDetails)
66-
.createConnectionFactory(ActiveMQConnectionFactory.class);
65+
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionDetails.getUser(),
66+
connectionDetails.getPassword(), connectionDetails.getBrokerUrl());
67+
new ActiveMQConnectionFactoryConfigurer(properties, factoryCustomizers.orderedStream().toList())
68+
.configure(connectionFactory);
69+
return connectionFactory;
6770
}
6871

6972
}

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,15 +16,13 @@
1616

1717
package org.springframework.boot.autoconfigure.jms.activemq;
1818

19-
import java.util.Collections;
20-
2119
import org.apache.activemq.ActiveMQConnectionFactory;
2220
import org.junit.jupiter.api.Test;
2321

2422
import static org.assertj.core.api.Assertions.assertThat;
2523

2624
/**
27-
* Tests for {@link ActiveMQProperties} and {@link ActiveMQConnectionFactoryFactory}.
25+
* Tests for {@link ActiveMQProperties} and {@link ActiveMQConnectionFactoryConfigurer}.
2826
*
2927
* @author Stephane Nicoll
3028
* @author Aurélien Leboulanger
@@ -50,25 +48,21 @@ void getBrokerUrlUseExplicitBrokerUrl() {
5048

5149
@Test
5250
void setTrustAllPackages() {
51+
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
5352
this.properties.getPackages().setTrustAll(true);
54-
assertThat(createFactory(this.properties).createConnectionFactory(ActiveMQConnectionFactory.class)
55-
.isTrustAllPackages()).isTrue();
53+
new ActiveMQConnectionFactoryConfigurer(this.properties, null).configure(factory);
54+
assertThat(factory.isTrustAllPackages()).isTrue();
5655
}
5756

5857
@Test
5958
void setTrustedPackages() {
59+
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
6060
this.properties.getPackages().setTrustAll(false);
6161
this.properties.getPackages().getTrusted().add("trusted.package");
62-
ActiveMQConnectionFactory factory = createFactory(this.properties)
63-
.createConnectionFactory(ActiveMQConnectionFactory.class);
62+
new ActiveMQConnectionFactoryConfigurer(this.properties, null).configure(factory);
6463
assertThat(factory.isTrustAllPackages()).isFalse();
6564
assertThat(factory.getTrustedPackages()).hasSize(1);
6665
assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package");
6766
}
6867

69-
private ActiveMQConnectionFactoryFactory createFactory(ActiveMQProperties properties) {
70-
return new ActiveMQConnectionFactoryFactory(properties, Collections.emptyList(),
71-
new ActiveMQAutoConfiguration.PropertiesActiveMQConnectionDetails(properties));
72-
}
73-
7468
}

0 commit comments

Comments
 (0)