Search in sources :

Example 1 with ConfigurationParseException

use of io.apiman.gateway.engine.beans.exceptions.ConfigurationParseException in project apiman by apiman.

the class PolicyChainTest method shouldEndChainImmediatelyWhenSkipCalled.

@Test
public void shouldEndChainImmediatelyWhenSkipCalled() {
    IPolicy skipPolicy = spy(new IPolicy() {

        @Override
        public Object parseConfiguration(String jsonConfiguration) throws ConfigurationParseException {
            return null;
        }

        @Override
        public void apply(ApiRequest request, IPolicyContext context, Object config, IPolicyChain<ApiRequest> chain) {
            chain.doSkip(request);
        }

        @Override
        public void apply(ApiResponse response, IPolicyContext context, Object config, IPolicyChain<ApiResponse> chain) {
            chain.doSkip(response);
        }
    });
    PolicyWithConfiguration pwcSkip = new PolicyWithConfiguration(skipPolicy, null);
    policies.add(pwcSkip);
    policies.add(pwcTwo);
    requestChain = new RequestChain(policies, mockContext);
    requestChain.bodyHandler(mockBodyHandler);
    requestChain.endHandler(mockEndHandler);
    requestChain.doApply(mockRequest);
    requestChain.end();
    verify(mockEndHandler, times(1)).handle((Void) null);
    // Should only be called once, as the second is skipped
    verify(skipPolicy, times(1)).apply(mockRequest, mockContext, null, requestChain);
    verify(policyOne, never()).apply(mockRequest, mockContext, null, requestChain);
}
Also used : IPolicy(io.apiman.gateway.engine.policy.IPolicy) IPolicyContext(io.apiman.gateway.engine.policy.IPolicyContext) ConfigurationParseException(io.apiman.gateway.engine.beans.exceptions.ConfigurationParseException) RequestChain(io.apiman.gateway.engine.policy.RequestChain) ApiRequest(io.apiman.gateway.engine.beans.ApiRequest) PolicyWithConfiguration(io.apiman.gateway.engine.policy.PolicyWithConfiguration) ApiResponse(io.apiman.gateway.engine.beans.ApiResponse) Test(org.junit.Test)

Example 2 with ConfigurationParseException

use of io.apiman.gateway.engine.beans.exceptions.ConfigurationParseException in project apiman by apiman.

the class IPolicyProbe method probe.

/**
 * This version uses Jackson to parse the probe configuration into the class specified by
 * {@link #getProbeRequestClass()}, and the policy config specified by {@link #getConfigurationClass()}.
 * <p>
 * Most implementors should override the abstract
 * {@link #probe(IPolicyProbeRequest, Object, ProbeContext, IPolicyContext, IAsyncResultHandler)}  method rather than this one,
 * unless they are doing something more exotic (e.g. not using JSON).
 */
default void probe(String rawProbeConfiguration, String rawPolicyConfiguration, ProbeContext probeContext, IPolicyContext policyContext, IAsyncResultHandler<IPolicyProbeResponse> resultHandler) {
    try {
        P probeConfig = mapper.readValue(rawProbeConfiguration, getProbeRequestClass());
        C policyConfig = mapper.readValue(rawPolicyConfiguration, getConfigurationClass());
        probe(probeConfig, policyConfig, probeContext, policyContext, resultHandler);
    } catch (Exception e) {
        throw new ConfigurationParseException(e);
    }
}
Also used : ConfigurationParseException(io.apiman.gateway.engine.beans.exceptions.ConfigurationParseException) ConfigurationParseException(io.apiman.gateway.engine.beans.exceptions.ConfigurationParseException)

Aggregations

ConfigurationParseException (io.apiman.gateway.engine.beans.exceptions.ConfigurationParseException)2 ApiRequest (io.apiman.gateway.engine.beans.ApiRequest)1 ApiResponse (io.apiman.gateway.engine.beans.ApiResponse)1 IPolicy (io.apiman.gateway.engine.policy.IPolicy)1 IPolicyContext (io.apiman.gateway.engine.policy.IPolicyContext)1 PolicyWithConfiguration (io.apiman.gateway.engine.policy.PolicyWithConfiguration)1 RequestChain (io.apiman.gateway.engine.policy.RequestChain)1 Test (org.junit.Test)1