本文整理汇总了Java中io.apiman.gateway.engine.beans.PolicyFailure.setResponseCode方法的典型用法代码示例。如果您正苦于以下问题:Java PolicyFailure.setResponseCode方法的具体用法?Java PolicyFailure.setResponseCode怎么用?Java PolicyFailure.setResponseCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.apiman.gateway.engine.beans.PolicyFailure
的用法示例。
在下文中一共展示了PolicyFailure.setResponseCode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doApply
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
/**
* @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
protected void doApply(ApiRequest request, IPolicyContext context, IPListConfig config,
IPolicyChain<ApiRequest> chain) {
String remoteAddr = getRemoteAddr(request, config);
if (isMatch(config, remoteAddr)) {
IPolicyFailureFactoryComponent ffactory = context.getComponent(IPolicyFailureFactoryComponent.class);
String msg = Messages.i18n.format("IPBlacklistPolicy.Blacklisted", remoteAddr); //$NON-NLS-1$
PolicyFailure failure = ffactory.createFailure(PolicyFailureType.Other, PolicyFailureCodes.IP_BLACKLISTED, msg);
failure.setResponseCode(config.getResponseCode());
if (config.getResponseCode() == 404) {
failure.setType(PolicyFailureType.NotFound);
} else if (config.getResponseCode() == 403) {
failure.setType(PolicyFailureType.Authorization);
} else if (config.getResponseCode() == 0) {
failure.setResponseCode(500);
}
chain.doFailure(failure);
} else {
super.doApply(request, context, config, chain);
}
}
示例2: doApply
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
/**
* @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
protected void doApply(ApiRequest request, IPolicyContext context, IPListConfig config,
IPolicyChain<ApiRequest> chain) {
String remoteAddr = getRemoteAddr(request, config);
if (isMatch(config, remoteAddr)) {
super.doApply(request, context, config, chain);
} else {
IPolicyFailureFactoryComponent ffactory = context.getComponent(IPolicyFailureFactoryComponent.class);
String msg = Messages.i18n.format("IPWhitelistPolicy.NotWhitelisted", remoteAddr); //$NON-NLS-1$
PolicyFailure failure = ffactory.createFailure(PolicyFailureType.Other, PolicyFailureCodes.IP_NOT_WHITELISTED, msg);
failure.setResponseCode(config.getResponseCode());
if (config.getResponseCode() == 404) {
failure.setType(PolicyFailureType.NotFound);
} else if (config.getResponseCode() == 403) {
failure.setType(PolicyFailureType.Authorization);
} else if (config.getResponseCode() == 0) {
failure.setResponseCode(500);
}
chain.doFailure(failure);
}
}
示例3: createAuthenticationPolicyFailure
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
private PolicyFailure createAuthenticationPolicyFailure(IPolicyContext context, int failureCode,
String message) {
PolicyFailure pf = getFailureFactory(context).createFailure(PolicyFailureType.Authentication,
failureCode, message);
pf.setResponseCode(HTTP_UNAUTHORIZED);
return pf;
}
示例4: createAuthorizationPolicyFailure
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
private PolicyFailure createAuthorizationPolicyFailure(IPolicyContext context, int failureCode,
String message) {
PolicyFailure pf = getFailureFactory(context).createFailure(PolicyFailureType.Authorization,
failureCode, message);
pf.setResponseCode(HTTP_UNAUTHORIZED);
return pf;
}
示例5: doApply
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
/**
* @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
protected void doApply(ApiRequest request, IPolicyContext context, CircuitBreakerConfigBean config,
IPolicyChain<ApiRequest> chain) {
CircuitKey ckey = new CircuitKey(request.getApiOrgId(), request.getApiId(), request.getApiVersion());
Circuit circuit = circuits.get(ckey);
if (circuit == null) {
circuit = new Circuit(config.getLimit(), config.getWindow(), config.getReset());
circuits.put(ckey, circuit);
}
context.setAttribute(CircuitBreakerPolicy.class.getName() + ".circuit", circuit); //$NON-NLS-1$
// Is the circuit broken? If so, either immediately send a failure, or else
// if the circuit is ready to be reset (the reset time has elapsed) then try
// to reset the circuit by letting through the request and seeing what happens.
if (circuit.isBroken()) {
// Can the circuit possibly be reset? If so, try...otherwise fail.
if (circuit.isResettable()) {
circuit.startReset();
super.doApply(request, context, config, chain);
} else {
IPolicyFailureFactoryComponent failureFactory = context.getComponent(IPolicyFailureFactoryComponent.class);
PolicyFailure failure = failureFactory.createFailure(PolicyFailureType.Other, BROKEN_CIRCUIT_FAILURE_CODE, "Circuit broken."); //$NON-NLS-1$
failure.setResponseCode(config.getFailureCode());
chain.doFailure(failure);
}
} else {
super.doApply(request, context, config, chain);
}
}
示例6: limitExceededFailure
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
/**
* @see io.apiman.gateway.engine.policies.RateLimitingPolicy#limitExceededFailure(io.apiman.gateway.engine.components.IPolicyFailureFactoryComponent)
*/
@Override
protected PolicyFailure limitExceededFailure(IPolicyFailureFactoryComponent failureFactory) {
PolicyFailure failure = failureFactory.createFailure(PolicyFailureType.Other, PolicyFailureCodes.REQUEST_QUOTA_EXCEEDED, Messages.i18n.format("QuotaPolicy.QuotaExceeded")); //$NON-NLS-1$
failure.setResponseCode(429);
return failure;
}
示例7: limitExceededFailure
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
/**
* @param responseHeaders
* @param failureFactory
*/
protected PolicyFailure limitExceededFailure(IPolicyFailureFactoryComponent failureFactory) {
PolicyFailure failure = failureFactory.createFailure(PolicyFailureType.Other,
PolicyFailureCodes.BYTE_QUOTA_EXCEEDED,
Messages.i18n.format("TransferQuotaPolicy.RateExceeded")); //$NON-NLS-1$
failure.setResponseCode(429);
return failure;
}
示例8: limitExceededFailure
import io.apiman.gateway.engine.beans.PolicyFailure; //导入方法依赖的package包/类
/**
* @param responseHeaders
* @param failureFactory
*/
protected PolicyFailure limitExceededFailure(IPolicyFailureFactoryComponent failureFactory) {
PolicyFailure failure = failureFactory.createFailure(PolicyFailureType.Other, PolicyFailureCodes.RATE_LIMIT_EXCEEDED, Messages.i18n.format("RateLimitingPolicy.RateExceeded")); //$NON-NLS-1$
failure.setResponseCode(429);
return failure;
}