Skip to content

Commit 76ba02e

Browse files
committed
Update HttpServiceProxyRegistry
See gh-33992
1 parent fb94109 commit 76ba02e

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

Diff for: spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistry.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.web.service.registry;
1818

19-
import org.jspecify.annotations.Nullable;
19+
import java.util.Set;
2020

2121
/**
2222
* A registry that contains HTTP Service client proxies.
@@ -35,18 +35,34 @@ public interface HttpServiceProxyRegistry {
3535
* @param httpServiceType the type of client proxy
3636
* @return the proxy, or {@code null} if not found
3737
* @param <P> the type of HTTP Interface client proxy
38-
* @throws IllegalArgumentException if more than one client proxy of the
38+
* @throws IllegalArgumentException if there is no client proxy of the given
39+
* type, or there is more than one client proxy of the given type.
3940
* given type exists across groups
4041
*/
41-
<P> @Nullable P getClient(Class<P> httpServiceType);
42+
<P> P getClient(Class<P> httpServiceType);
4243

4344
/**
4445
* Return an HTTP service client proxy from the given group.
4546
* @param groupName the name of the group
4647
* @param httpServiceType the type of client proxy
4748
* @return the proxy, or {@code null} if not found
49+
* @throws IllegalArgumentException if there is no group with the given
50+
* name, or no client proxy of the given type in the group.
4851
* @param <P> the type of HTTP Interface client proxy
4952
*/
50-
<P> @Nullable P getClient(String groupName, Class<P> httpServiceType);
53+
<P> P getClient(String groupName, Class<P> httpServiceType);
54+
55+
/**
56+
* Return the names of all groups in the registry.
57+
*/
58+
Set<String> getGroupNames();
59+
60+
/**
61+
* Return the HTTP service types for all client proxies in the given group.
62+
* @param groupName the name of the group
63+
* @return the HTTP service types
64+
* @throws IllegalArgumentException if there is no group with the given name.
65+
*/
66+
Set<Class<?>> getClientTypesInGroup(String groupName);
5167

5268
}

Diff for: spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistryFactoryBean.java

+26-6
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,36 @@ private static final class DefaultHttpServiceProxyRegistry implements HttpServic
278278

279279
@SuppressWarnings("unchecked")
280280
@Override
281-
public <P> @Nullable P getClient(Class<P> type) {
282-
List<Object> proxies = this.directLookupMap.getOrDefault(type, Collections.emptyList());
283-
Assert.state(proxies.size() <= 1, "No unique client of type " + type.getName());
284-
return (!proxies.isEmpty() ? (P) proxies.get(0) : null);
281+
public <P> P getClient(Class<P> type) {
282+
List<Object> map = this.directLookupMap.getOrDefault(type, Collections.emptyList());
283+
Assert.notEmpty(map, "No client of type " + type.getName());
284+
Assert.isTrue(map.size() <= 1, "No unique client of type " + type.getName());
285+
return (P) map.get(0);
285286
}
286287

287288
@SuppressWarnings("unchecked")
288289
@Override
289-
public <P> @Nullable P getClient(String groupName, Class<P> httpServiceType) {
290-
return (P) this.groupProxyMap.getOrDefault(groupName, Collections.emptyMap()).get(httpServiceType);
290+
public <P> P getClient(String groupName, Class<P> type) {
291+
Map<Class<?>, Object> map = getProxyMapForGroup(groupName);
292+
P proxy = (P) map.get(type);
293+
Assert.notNull(proxy, "No client of type " + type + " in group '" + groupName + "': " + map.keySet());
294+
return proxy;
295+
}
296+
297+
@Override
298+
public Set<String> getGroupNames() {
299+
return this.groupProxyMap.keySet();
300+
}
301+
302+
@Override
303+
public Set<Class<?>> getClientTypesInGroup(String groupName) {
304+
return getProxyMapForGroup(groupName).keySet();
305+
}
306+
307+
private Map<Class<?>, Object> getProxyMapForGroup(String groupName) {
308+
Map<Class<?>, Object> map = this.groupProxyMap.get(groupName);
309+
Assert.notNull(map, "No group with name '" + groupName + "'");
310+
return map;
291311
}
292312
}
293313

0 commit comments

Comments
 (0)