feat(gateway-engine): use ClassGraph to scan & register policy probe response implementations
MODIFY
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/probe/ProbeRegistry.java
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/probe/ProbeRegistry.java
package io.apiman.gateway.engine.policies.probe;
+import io.apiman.common.logging.ApimanLoggerFactory;
+import io.apiman.common.logging.IApimanLogger;
import io.apiman.gateway.engine.beans.IPolicyProbeResponse;
import java.io.IOException;
@@ -8,6 +10,9 @@ import java.io.UncheckedIOException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfo;
+import io.github.classgraph.ScanResult;
/**
*
@@ -18,12 +23,25 @@ public class ProbeRegistry {
private static final ObjectMapper OM = new ObjectMapper()
.findAndRegisterModules();
+ private static final IApimanLogger LOGGER = ApimanLoggerFactory.getLogger(ProbeRegistry.class);
+
public ProbeRegistry() {
}
static {
- register(RateLimitingProbeResponse.class);
- register(TransferQuotaProbeResponse.class);
+ try (ScanResult scanResult = new ClassGraph()
+ .enableAnnotationInfo()
+ .enableClassInfo()
+ .scan()) {
+ for (ClassInfo klazzInfo : scanResult.getClassesImplementing(IPolicyProbeResponse.class)) {
+ try {
+ Class<IPolicyProbeResponse> klazz = (Class<IPolicyProbeResponse>) klazzInfo.loadClass();
+ LOGGER.info("Found policy probe: {0}", klazz.getCanonicalName());
+ } catch (Throwable t) {
+ LOGGER.warn("Ignoring exception during event class load: {0}", t);
+ }
+ }
+ }
}
public static void register(Class<? extends IPolicyProbeResponse> response) {

MODIFY
manager/api/rest/src/main/java/io/apiman/manager/api/rest/IOrganizationResource.java
manager/api/rest/src/main/java/io/apiman/manager/api/rest/IOrganizationResource.java
@@ -567,7 +567,13 @@ public interface IOrganizationResource {
throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException;
/**
- * Probe a specific contract's policy state
+ * Use this endpoint to probe a specific API contract's policy state
+ * @Summary Probe a policy associated with a contract
+ * @param organizationId The Organization ID.
+ * @param clientId The Client ID.
+ * @param version The Client version.
+ * @param rawPayload The probe payload (refer to the documentation of the probe you want to use for the correct JSON format).
+ * @return A policy probe response
*/
@PermitAll
@POST
@@ -582,7 +588,7 @@ public interface IOrganizationResource {
/**
* Use this endpoint to get a list of all Contracts for an Client.
- * @summary List All Contracts for an Client
+ * @summary List All Contracts for a Client
* @param organizationId The Organization ID.
* @param clientId The Client ID.
* @param version The Client version.

feat(gateway-engine): use ClassGraph to scan & register policy probe response implementations