当前位置: 首页>>代码示例>>Java>>正文


Java PolicyFailure.setResponseCode方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:26,代码来源:IPBlacklistPolicy.java

示例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);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:25,代码来源:IPWhitelistPolicy.java

示例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;
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:8,代码来源:PolicyFailureFactory.java

示例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;
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:8,代码来源:PolicyFailureFactory.java

示例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);
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:34,代码来源:CircuitBreakerPolicy.java

示例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;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:10,代码来源:QuotaPolicy.java

示例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;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:12,代码来源:TransferQuotaPolicy.java

示例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;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:10,代码来源:RateLimitingPolicy.java


注:本文中的io.apiman.gateway.engine.beans.PolicyFailure.setResponseCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。