Skip to content

Commit 9be3d85

Browse files
committed
Merge branch '6.1.x'
2 parents 3984266 + 3296289 commit 9be3d85

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.jms.connection;
18+
19+
import jakarta.jms.Connection;
20+
import jakarta.jms.QueueConnection;
21+
import jakarta.jms.QueueSession;
22+
import jakarta.jms.TopicConnection;
23+
import jakarta.jms.TopicSession;
24+
25+
import org.springframework.aot.hint.RuntimeHints;
26+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
27+
import org.springframework.aot.hint.TypeReference;
28+
import org.springframework.lang.Nullable;
29+
30+
/**
31+
* {@link RuntimeHintsRegistrar} to register hints for JMS connection factories.
32+
*
33+
* @author Brian Clozel
34+
* @see CachingConnectionFactory
35+
* @see SingleConnectionFactory
36+
* @see TransactionAwareConnectionFactoryProxy
37+
*/
38+
class ConnectionFactoriesRuntimeHints implements RuntimeHintsRegistrar {
39+
40+
@Override
41+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
42+
hints.proxies().registerJdkProxy(builder -> builder.onReachableType(TypeReference.of(CachingConnectionFactory.class))
43+
.proxiedInterfaces(SessionProxy.class, TopicSession.class, QueueSession.class));
44+
hints.proxies().registerJdkProxy(builder -> builder.onReachableType(TypeReference.of(SingleConnectionFactory.class))
45+
.proxiedInterfaces(Connection.class, QueueConnection.class, TopicConnection.class));
46+
hints.proxies().registerJdkProxy(builder -> builder.onReachableType(TypeReference.of(TransactionAwareConnectionFactoryProxy.class))
47+
.proxiedInterfaces(Connection.class, QueueConnection.class, TopicConnection.class));
48+
}
49+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
org.springframework.jms.connection.ConnectionFactoriesRuntimeHints
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.jms.connection;
18+
19+
import jakarta.jms.Connection;
20+
import jakarta.jms.QueueConnection;
21+
import jakarta.jms.QueueSession;
22+
import jakarta.jms.TopicConnection;
23+
import jakarta.jms.TopicSession;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
26+
27+
import org.springframework.aot.hint.RuntimeHints;
28+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
29+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
30+
import org.springframework.core.io.support.SpringFactoriesLoader;
31+
import org.springframework.util.ClassUtils;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
/**
36+
* Tests for {@link ConnectionFactoriesRuntimeHints}.
37+
*/
38+
class ConnectionFactoriesRuntimeHintsTests {
39+
40+
private RuntimeHints hints;
41+
42+
@BeforeEach
43+
void setup() {
44+
this.hints = new RuntimeHints();
45+
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
46+
.load(RuntimeHintsRegistrar.class).forEach(registrar -> registrar
47+
.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
48+
}
49+
50+
@Test
51+
void shouldRegisterProxyHints() throws Exception {
52+
assertThat(RuntimeHintsPredicates.proxies().forInterfaces(SessionProxy.class, TopicSession.class, QueueSession.class)).accepts(this.hints);
53+
assertThat(RuntimeHintsPredicates.proxies().forInterfaces(Connection.class, QueueConnection.class, TopicConnection.class)).accepts(this.hints);
54+
}
55+
56+
}

0 commit comments

Comments
 (0)