Search in sources :

Example 1 with IPolicyFactory

use of io.apiman.gateway.engine.policy.IPolicyFactory 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));
    }
}
Also used : IPolicy(io.apiman.gateway.engine.policy.IPolicy) Policy(io.apiman.gateway.engine.beans.Policy) IPolicyProbeResponse(io.apiman.gateway.engine.beans.IPolicyProbeResponse) IPolicy(io.apiman.gateway.engine.policy.IPolicy) ProbeContext(io.apiman.gateway.engine.policy.ProbeContext) IPolicyFactory(io.apiman.gateway.engine.policy.IPolicyFactory) IPolicyProbe(io.apiman.gateway.engine.policy.IPolicyProbe) PolicyContextImpl(io.apiman.gateway.engine.policy.PolicyContextImpl)

Example 2 with IPolicyFactory

use of io.apiman.gateway.engine.policy.IPolicyFactory 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));
    }
}
Also used : IPolicy(io.apiman.gateway.engine.policy.IPolicy) Policy(io.apiman.gateway.engine.beans.Policy) IPolicyProbeResponse(io.apiman.gateway.engine.beans.IPolicyProbeResponse) IPolicy(io.apiman.gateway.engine.policy.IPolicy) ProbeContext(io.apiman.gateway.engine.policy.ProbeContext) IPolicyFactory(io.apiman.gateway.engine.policy.IPolicyFactory) IPolicyProbe(io.apiman.gateway.engine.policy.IPolicyProbe) Api(io.apiman.gateway.engine.beans.Api) Client(io.apiman.gateway.engine.beans.Client) PolicyContextImpl(io.apiman.gateway.engine.policy.PolicyContextImpl)

Example 3 with IPolicyFactory

use of io.apiman.gateway.engine.policy.IPolicyFactory in project apiman by apiman.

the class AbstractEngineFactory method createEngine.

/**
 * Call this to create a new engine. This method uses the engine
 * config singleton to create the engine.
 */
@Override
public final IEngine createEngine() {
    IPluginRegistry pluginRegistry = createPluginRegistry();
    IDataEncrypter encrypter = createDataEncrypter(pluginRegistry);
    CurrentDataEncrypter.instance = encrypter;
    IRegistry registry = createRegistry(pluginRegistry, encrypter);
    IComponentRegistry componentRegistry = createComponentRegistry(pluginRegistry);
    IConnectorFactory cfactory = createConnectorFactory(pluginRegistry);
    IPolicyFactory pfactory = createPolicyFactory(pluginRegistry);
    IMetrics metrics = createMetrics(pluginRegistry);
    IApiRequestPathParser pathParser = createRequestPathParser(pluginRegistry);
    List<IGatewayInitializer> initializers = createInitializers(pluginRegistry);
    for (IGatewayInitializer initializer : initializers) {
        initializer.initialize();
    }
    complete();
    return new EngineImpl(registry, pluginRegistry, componentRegistry, cfactory, pfactory, metrics, pathParser);
}
Also used : IPluginRegistry(io.apiman.gateway.engine.IPluginRegistry) IPolicyFactory(io.apiman.gateway.engine.policy.IPolicyFactory) IApiRequestPathParser(io.apiman.gateway.engine.IApiRequestPathParser) IComponentRegistry(io.apiman.gateway.engine.IComponentRegistry) IConnectorFactory(io.apiman.gateway.engine.IConnectorFactory) IGatewayInitializer(io.apiman.gateway.engine.IGatewayInitializer) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) IRegistry(io.apiman.gateway.engine.IRegistry) IMetrics(io.apiman.gateway.engine.IMetrics)

Example 4 with IPolicyFactory

use of io.apiman.gateway.engine.policy.IPolicyFactory 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));
    }
}
Also used : IPolicy(io.apiman.gateway.engine.policy.IPolicy) Policy(io.apiman.gateway.engine.beans.Policy) IPolicyProbeResponse(io.apiman.gateway.engine.beans.IPolicyProbeResponse) IPolicy(io.apiman.gateway.engine.policy.IPolicy) ProbeContext(io.apiman.gateway.engine.policy.ProbeContext) IPolicyFactory(io.apiman.gateway.engine.policy.IPolicyFactory) IPolicyProbe(io.apiman.gateway.engine.policy.IPolicyProbe) Api(io.apiman.gateway.engine.beans.Api) Client(io.apiman.gateway.engine.beans.Client) PolicyContextImpl(io.apiman.gateway.engine.policy.PolicyContextImpl)

Example 5 with IPolicyFactory

use of io.apiman.gateway.engine.policy.IPolicyFactory 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));
    }
}
Also used : IPolicy(io.apiman.gateway.engine.policy.IPolicy) Policy(io.apiman.gateway.engine.beans.Policy) IPolicyProbeResponse(io.apiman.gateway.engine.beans.IPolicyProbeResponse) IPolicy(io.apiman.gateway.engine.policy.IPolicy) ProbeContext(io.apiman.gateway.engine.policy.ProbeContext) IPolicyFactory(io.apiman.gateway.engine.policy.IPolicyFactory) IPolicyProbe(io.apiman.gateway.engine.policy.IPolicyProbe) PolicyContextImpl(io.apiman.gateway.engine.policy.PolicyContextImpl)

Aggregations

IPolicyFactory (io.apiman.gateway.engine.policy.IPolicyFactory)5 IPolicyProbeResponse (io.apiman.gateway.engine.beans.IPolicyProbeResponse)4 Policy (io.apiman.gateway.engine.beans.Policy)4 IPolicy (io.apiman.gateway.engine.policy.IPolicy)4 IPolicyProbe (io.apiman.gateway.engine.policy.IPolicyProbe)4 PolicyContextImpl (io.apiman.gateway.engine.policy.PolicyContextImpl)4 ProbeContext (io.apiman.gateway.engine.policy.ProbeContext)4 Api (io.apiman.gateway.engine.beans.Api)2 Client (io.apiman.gateway.engine.beans.Client)2 IDataEncrypter (io.apiman.common.util.crypt.IDataEncrypter)1 IApiRequestPathParser (io.apiman.gateway.engine.IApiRequestPathParser)1 IComponentRegistry (io.apiman.gateway.engine.IComponentRegistry)1 IConnectorFactory (io.apiman.gateway.engine.IConnectorFactory)1 IGatewayInitializer (io.apiman.gateway.engine.IGatewayInitializer)1 IMetrics (io.apiman.gateway.engine.IMetrics)1 IPluginRegistry (io.apiman.gateway.engine.IPluginRegistry)1 IRegistry (io.apiman.gateway.engine.IRegistry)1