use of io.apiman.gateway.engine.policy.ProbeContext in project apiman by apiman.
the class ApiResourceImpl method getPolicy.
private void getPolicy(Api api, int policyIdx, String probeConfigRaw, AsyncResponse response) {
if (policyIdx < api.getApiPolicies().size()) {
// Get API policy by index
Policy policyConfig = api.getApiPolicies().get(policyIdx);
IPolicyFactory policyFactory = getEngine().getPolicyFactory();
// Load the policy (may not have been loaded yet, but is usually cached).
policyFactory.loadPolicy(policyConfig.getPolicyImpl(), policyLoad -> {
// Generate & load appropriate config for policy (is cached, so OK to do repeatedly).
IPolicy policy = policyLoad.getResult();
PolicyContextImpl policyContext = new PolicyContextImpl(getEngine().getComponentRegistry());
ProbeContext probeContext = buildProbeContext(api, null, null, api.getEndpointType());
// Probe it!
if (policy instanceof IPolicyProbe) {
IPolicyProbe<?, ?> policyWithProbe = (IPolicyProbe<?, ?>) policy;
policyWithProbe.probe(probeConfigRaw, policyConfig.getPolicyJsonConfig(), probeContext, policyContext, probeResult -> {
IPolicyProbeResponse probeResponse = probeResult.getResult();
LOGGER.debug("Probe response for config {0} -> {1}", probeConfigRaw, probeResponse);
response.resume(Response.ok(probeResponse).build());
});
} else {
response.resume(Response.status(Status.NOT_IMPLEMENTED.getStatusCode(), "Requested policy does not implement a policy probe").build());
}
});
} else {
response.resume(new IllegalArgumentException("Provided policy index out of bounds: " + policyIdx));
}
}
use of io.apiman.gateway.engine.policy.ProbeContext in project apiman by apiman.
the class ApiResourceImpl method getPolicy.
private void getPolicy(ApiContract contract, int policyIdx, String probeConfigRaw, AsyncResponse response) {
if (policyIdx < contract.getPolicies().size()) {
// Get API policy by index
Policy policyConfig = contract.getPolicies().get(policyIdx);
IPolicyFactory policyFactory = getEngine().getPolicyFactory();
// Load the policy (may not have been loaded yet, but is usually cached).
policyFactory.loadPolicy(policyConfig.getPolicyImpl(), policyLoad -> {
// Generate & load appropriate config for policy (is cached, so OK to do repeatedly).
IPolicy policy = policyLoad.getResult();
PolicyContextImpl policyContext = new PolicyContextImpl(getEngine().getComponentRegistry());
Api api = contract.getApi();
Client client = contract.getClient();
ProbeContext probeContext = buildProbeContext(contract.getApi(), contract, client.getApiKey(), api.getEndpointType());
// Probe it!
if (policy instanceof IPolicyProbe) {
IPolicyProbe<?, ?> policyWithProbe = (IPolicyProbe<?, ?>) policy;
policyWithProbe.probe(probeConfigRaw, policyConfig.getPolicyJsonConfig(), probeContext, policyContext, probeResult -> {
IPolicyProbeResponse probeResponse = probeResult.getResult();
LOGGER.debug("Probe response for config {0} -> {1}", probeConfigRaw, probeResponse);
response.resume(Response.ok(ProbeRegistry.serialize(probeResponse)).build());
});
} else {
response.resume(Response.status(Status.NOT_IMPLEMENTED.getStatusCode(), "Requested policy does not implement a policy probe").build());
}
});
} else {
response.resume(new IllegalArgumentException("Provided policy index out of bounds: " + policyIdx));
}
}
use of io.apiman.gateway.engine.policy.ProbeContext in project apiman by apiman.
the class ApiResourceImpl method getPolicy.
private void getPolicy(ApiContract contract, int policyIdx, String probeConfigRaw, AsyncResponse response) {
if (policyIdx < contract.getPolicies().size()) {
// Get API policy by index
Policy policyConfig = contract.getPolicies().get(policyIdx);
IPolicyFactory policyFactory = engine.getPolicyFactory();
// Load the policy (may not have been loaded yet, but is usually cached).
policyFactory.loadPolicy(policyConfig.getPolicyImpl(), policyLoad -> {
// Generate & load appropriate config for policy (is cached, so OK to do repeatedly).
IPolicy policy = policyLoad.getResult();
PolicyContextImpl policyContext = new PolicyContextImpl(engine.getComponentRegistry());
Api api = contract.getApi();
Client client = contract.getClient();
ProbeContext probeContext = buildProbeContext(contract.getApi(), contract, client.getApiKey(), api.getEndpointType());
// Probe it!
if (policy instanceof IPolicyProbe) {
IPolicyProbe<?, ?> policyWithProbe = (IPolicyProbe<?, ?>) policy;
policyWithProbe.probe(probeConfigRaw, policyConfig.getPolicyJsonConfig(), probeContext, policyContext, probeResult -> {
IPolicyProbeResponse probeResponse = probeResult.getResult();
LOGGER.debug("Probe response for config {0} -> {1}", probeConfigRaw, probeResponse);
response.resume(Response.ok(probeResponse).build());
});
} else {
response.resume(Response.status(Status.NOT_IMPLEMENTED.getStatusCode(), "Requested policy does not implement a policy probe").build());
}
});
} else {
response.resume(new IllegalArgumentException("Provided policy index out of bounds: " + policyIdx));
}
}
use of io.apiman.gateway.engine.policy.ProbeContext in project apiman by apiman.
the class ApiResourceImpl method getPolicy.
private void getPolicy(Api api, int policyIdx, String probeConfigRaw, @Suspended AsyncResponse response) {
if (policyIdx < api.getApiPolicies().size()) {
// Get API policy by index
Policy policyConfig = api.getApiPolicies().get(policyIdx);
IPolicyFactory policyFactory = engine.getPolicyFactory();
// Load the policy (may not have been loaded yet, but is usually cached).
policyFactory.loadPolicy(policyConfig.getPolicyImpl(), policyLoad -> {
// Generate & load appropriate config for policy (is cached, so OK to do repeatedly).
IPolicy policy = policyLoad.getResult();
PolicyContextImpl policyContext = new PolicyContextImpl(engine.getComponentRegistry());
ProbeContext probeContext = buildProbeContext(api, null, null, api.getEndpointType());
// Probe it!
if (policy instanceof IPolicyProbe) {
IPolicyProbe<?, ?> policyWithProbe = (IPolicyProbe<?, ?>) policy;
policyWithProbe.probe(probeConfigRaw, policyConfig.getPolicyJsonConfig(), probeContext, policyContext, probeResult -> {
IPolicyProbeResponse probeResponse = probeResult.getResult();
LOGGER.debug("Probe response for config {0} -> {1}", probeConfigRaw, probeResponse);
response.resume(Response.ok(ProbeRegistry.serialize(probeResponse)).build());
});
} else {
response.resume(Response.status(Status.NOT_IMPLEMENTED.getStatusCode(), "Requested policy does not implement a policy probe").build());
}
});
} else {
response.resume(new IllegalArgumentException("Provided policy index out of bounds: " + policyIdx));
}
}
Aggregations