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);
}
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);
}
}
Aggregations