From 76ba02ec3e58f20dcf9e57ddddd0a113105c8d63 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 14 Apr 2025 17:40:59 +0100 Subject: [PATCH] Update HttpServiceProxyRegistry See gh-33992 --- .../registry/HttpServiceProxyRegistry.java | 24 +++++++++++--- .../HttpServiceProxyRegistryFactoryBean.java | 32 +++++++++++++++---- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistry.java b/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistry.java index 29f8c330e1..712a7f35a5 100644 --- a/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistry.java +++ b/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistry.java @@ -16,7 +16,7 @@ package org.springframework.web.service.registry; -import org.jspecify.annotations.Nullable; +import java.util.Set; /** * A registry that contains HTTP Service client proxies. @@ -35,18 +35,34 @@ public interface HttpServiceProxyRegistry { * @param httpServiceType the type of client proxy * @return the proxy, or {@code null} if not found * @param

the type of HTTP Interface client proxy - * @throws IllegalArgumentException if more than one client proxy of the + * @throws IllegalArgumentException if there is no client proxy of the given + * type, or there is more than one client proxy of the given type. * given type exists across groups */ -

@Nullable P getClient(Class

httpServiceType); +

P getClient(Class

httpServiceType); /** * Return an HTTP service client proxy from the given group. * @param groupName the name of the group * @param httpServiceType the type of client proxy * @return the proxy, or {@code null} if not found + * @throws IllegalArgumentException if there is no group with the given + * name, or no client proxy of the given type in the group. * @param

the type of HTTP Interface client proxy */ -

@Nullable P getClient(String groupName, Class

httpServiceType); +

P getClient(String groupName, Class

httpServiceType); + + /** + * Return the names of all groups in the registry. + */ + Set getGroupNames(); + + /** + * Return the HTTP service types for all client proxies in the given group. + * @param groupName the name of the group + * @return the HTTP service types + * @throws IllegalArgumentException if there is no group with the given name. + */ + Set> getClientTypesInGroup(String groupName); } diff --git a/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistryFactoryBean.java b/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistryFactoryBean.java index b890f4d4c7..fcfc13f40a 100644 --- a/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistryFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/service/registry/HttpServiceProxyRegistryFactoryBean.java @@ -278,16 +278,36 @@ public final class HttpServiceProxyRegistryFactoryBean @SuppressWarnings("unchecked") @Override - public

@Nullable P getClient(Class

type) { - List proxies = this.directLookupMap.getOrDefault(type, Collections.emptyList()); - Assert.state(proxies.size() <= 1, "No unique client of type " + type.getName()); - return (!proxies.isEmpty() ? (P) proxies.get(0) : null); + public

P getClient(Class

type) { + List map = this.directLookupMap.getOrDefault(type, Collections.emptyList()); + Assert.notEmpty(map, "No client of type " + type.getName()); + Assert.isTrue(map.size() <= 1, "No unique client of type " + type.getName()); + return (P) map.get(0); } @SuppressWarnings("unchecked") @Override - public

@Nullable P getClient(String groupName, Class

httpServiceType) { - return (P) this.groupProxyMap.getOrDefault(groupName, Collections.emptyMap()).get(httpServiceType); + public

P getClient(String groupName, Class

type) { + Map, Object> map = getProxyMapForGroup(groupName); + P proxy = (P) map.get(type); + Assert.notNull(proxy, "No client of type " + type + " in group '" + groupName + "': " + map.keySet()); + return proxy; + } + + @Override + public Set getGroupNames() { + return this.groupProxyMap.keySet(); + } + + @Override + public Set> getClientTypesInGroup(String groupName) { + return getProxyMapForGroup(groupName).keySet(); + } + + private Map, Object> getProxyMapForGroup(String groupName) { + Map, Object> map = this.groupProxyMap.get(groupName); + Assert.notNull(map, "No group with name '" + groupName + "'"); + return map; } }