Update HttpServiceProxyRegistry
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Waiting to run Details
Build and Deploy Snapshot / Verify (push) Blocked by required conditions Details
Deploy Docs / Dispatch docs deployment (push) Waiting to run Details

See gh-33992
This commit is contained in:
rstoyanchev 2025-04-14 17:40:59 +01:00
parent fb94109c09
commit 76ba02ec3e
2 changed files with 46 additions and 10 deletions

View File

@ -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 <P> 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
*/
<P> @Nullable P getClient(Class<P> httpServiceType);
<P> P getClient(Class<P> 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 <P> the type of HTTP Interface client proxy
*/
<P> @Nullable P getClient(String groupName, Class<P> httpServiceType);
<P> P getClient(String groupName, Class<P> httpServiceType);
/**
* Return the names of all groups in the registry.
*/
Set<String> 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<Class<?>> getClientTypesInGroup(String groupName);
}

View File

@ -278,16 +278,36 @@ public final class HttpServiceProxyRegistryFactoryBean
@SuppressWarnings("unchecked")
@Override
public <P> @Nullable P getClient(Class<P> type) {
List<Object> 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> P getClient(Class<P> type) {
List<Object> 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 <P> @Nullable P getClient(String groupName, Class<P> httpServiceType) {
return (P) this.groupProxyMap.getOrDefault(groupName, Collections.emptyMap()).get(httpServiceType);
public <P> P getClient(String groupName, Class<P> type) {
Map<Class<?>, 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<String> getGroupNames() {
return this.groupProxyMap.keySet();
}
@Override
public Set<Class<?>> getClientTypesInGroup(String groupName) {
return getProxyMapForGroup(groupName).keySet();
}
private Map<Class<?>, Object> getProxyMapForGroup(String groupName) {
Map<Class<?>, Object> map = this.groupProxyMap.get(groupName);
Assert.notNull(map, "No group with name '" + groupName + "'");
return map;
}
}