Update HttpServiceProxyRegistry
See gh-33992
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.web.service.registry;
|
package org.springframework.web.service.registry;
|
||||||
|
|
||||||
import org.jspecify.annotations.Nullable;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A registry that contains HTTP Service client proxies.
|
* A registry that contains HTTP Service client proxies.
|
||||||
@@ -35,18 +35,34 @@ public interface HttpServiceProxyRegistry {
|
|||||||
* @param httpServiceType the type of client proxy
|
* @param httpServiceType the type of client proxy
|
||||||
* @return the proxy, or {@code null} if not found
|
* @return the proxy, or {@code null} if not found
|
||||||
* @param <P> the type of HTTP Interface client proxy
|
* @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
|
* 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.
|
* Return an HTTP service client proxy from the given group.
|
||||||
* @param groupName the name of the group
|
* @param groupName the name of the group
|
||||||
* @param httpServiceType the type of client proxy
|
* @param httpServiceType the type of client proxy
|
||||||
* @return the proxy, or {@code null} if not found
|
* @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
|
* @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")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <P> @Nullable P getClient(Class<P> type) {
|
public <P> P getClient(Class<P> type) {
|
||||||
List<Object> proxies = this.directLookupMap.getOrDefault(type, Collections.emptyList());
|
List<Object> map = this.directLookupMap.getOrDefault(type, Collections.emptyList());
|
||||||
Assert.state(proxies.size() <= 1, "No unique client of type " + type.getName());
|
Assert.notEmpty(map, "No client of type " + type.getName());
|
||||||
return (!proxies.isEmpty() ? (P) proxies.get(0) : null);
|
Assert.isTrue(map.size() <= 1, "No unique client of type " + type.getName());
|
||||||
|
return (P) map.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <P> @Nullable P getClient(String groupName, Class<P> httpServiceType) {
|
public <P> P getClient(String groupName, Class<P> type) {
|
||||||
return (P) this.groupProxyMap.getOrDefault(groupName, Collections.emptyMap()).get(httpServiceType);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user