test(test-policy): Implement failure processor. Set Test-Policy-Process-Failure: true
@@ -17,16 +17,19 @@ package io.apiman.plugins.test_policy;
import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.ApiResponse;
+import io.apiman.gateway.engine.beans.PolicyFailure;
import io.apiman.gateway.engine.beans.exceptions.ConfigurationParseException;
import io.apiman.gateway.engine.policy.IPolicy;
import io.apiman.gateway.engine.policy.IPolicyChain;
import io.apiman.gateway.engine.policy.IPolicyContext;
+import io.apiman.gateway.engine.policy.IPolicyFailureChain;
/**
* A policy that simply adds a header to the inbound http request.
*
* @author eric.wittmann@redhat.com
*/
+@SuppressWarnings("nls")
public class TestPolicy implements IPolicy {
/**
@@ -46,11 +49,12 @@ public class TestPolicy implements IPolicy {
/**
* @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
- @SuppressWarnings("nls")
@Override
public void apply(ApiRequest request, IPolicyContext context, Object config,
IPolicyChain<ApiRequest> chain) {
request.getHeaders().put("Test-Policy", "true");
+ request.getHeaders().put("Test-Shooooo", "true");
+
chain.doApply(request);
}
@@ -60,7 +64,16 @@ public class TestPolicy implements IPolicy {
@Override
public void apply(ApiResponse response, IPolicyContext context, Object config,
IPolicyChain<ApiResponse> chain) {
+ response.getHeaders().put("Test-Reply", "true");
+
chain.doApply(response);
}
+ @Override
+ public void processFailure(PolicyFailure failure, IPolicyContext context, Object config, IPolicyFailureChain chain) {
+ failure.getHeaders().put("Test-Policy-Process-Failure", "true");
+
+ chain.doFailure(failure);
+ }
+
}
