Update HttpServiceProxyRegistry
See gh-33992
This commit is contained in:
parent
fb94109c09
commit
76ba02ec3e
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue