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


Java IPolicyContext.getComponent方法代码示例

本文整理汇总了Java中io.apiman.gateway.engine.policy.IPolicyContext.getComponent方法的典型用法代码示例。如果您正苦于以下问题:Java IPolicyContext.getComponent方法的具体用法?Java IPolicyContext.getComponent怎么用?Java IPolicyContext.getComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.apiman.gateway.engine.policy.IPolicyContext的用法示例。


在下文中一共展示了IPolicyContext.getComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: BatchedRep

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
public BatchedRep(Auth3ScaleBean auth3ScaleBean,
        ApiRequest request,
        ApiResponse response,
        IPolicyContext context,
        ReporterImpl<BatchedReportData> reporter,
        StandardAuthCache authCache,
        BatchedAuthCache heuristicCache) {
    this.config = auth3ScaleBean.getThreescaleConfig().getProxyConfig().getBackendConfig();
    this.backendUri = auth3ScaleBean.getBackendEndpoint();
    this.request = request;
    this.context = context;
    this.reporter = reporter;
    this.authCache = authCache;
    this.heuristicCache = heuristicCache;
    this.httpClient = context.getComponent(IHttpClientComponent.class);
    this.failureFactory = context.getComponent(IPolicyFailureFactoryComponent.class);
    this.logger = context.getLogger(BatchedRep.class);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:19,代码来源:BatchedRep.java

示例2: BatchedAuth

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
public BatchedAuth(Auth3ScaleBean auth3ScaleBean,
        ApiRequest request,
        IPolicyContext context,
        StandardAuthCache authCache,
        BatchedAuthCache heuristicCache) {
    this.backendUri = auth3ScaleBean.getBackendEndpoint();
    this.config = auth3ScaleBean.getThreescaleConfig().getProxyConfig().getBackendConfig();
    this.request = request;
    this.context = context;
    this.authCache = authCache;
    this.heuristicCache = heuristicCache;
    this.logger = context.getLogger(BatchedAuth.class);
    this.serviceId = config.getProxy().getServiceId();
    this.httpClient = context.getComponent(IHttpClientComponent.class);
    this.failureFactory = context.getComponent(IPolicyFailureFactoryComponent.class);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:17,代码来源:BatchedAuth.java

示例3: start

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
public BatchedReporter start(IPolicyContext context, BatchedReporterOptions options) {
    if (started) {
        throw new IllegalStateException("Already started");
    }

    this.retryReporter = new RetryReporter(options.getRetryQueueMaxSize());
    reporters.add(retryReporter);

    this.httpClient = context.getComponent(IHttpClientComponent.class);
    this.periodic = context.getComponent(IPeriodicComponent.class);
    this.logger = context.getLogger(BatchedReporter.class);

    this.timerId = periodic.setPeriodicTimer(options.getReportingInterval(),
            options.getInitialWait(),
            id -> send());
    started = true;
    return this;
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:19,代码来源:BatchedReporter.java

示例4: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的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, TimeRestrictedAccessConfig config,
        IPolicyChain<ApiRequest> chain) {
    if (canProcessRequest(config, request.getDestination())) {
        super.doApply(request, context, config, chain);
    } else {
        IPolicyFailureFactoryComponent ffactory = context
                .getComponent(IPolicyFailureFactoryComponent.class);
        String msg = Messages.i18n.format("TimeRestrictedAccessPolicy.Unavailable", //$NON-NLS-1$
                request.getDestination());
        PolicyFailure failure = ffactory.createFailure(PolicyFailureType.Other,
                PolicyFailureCodes.ACCESS_TIME_RESTRICTED, msg);
        chain.doFailure(failure);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:TimeRestrictedAccessPolicy.java

示例5: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的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

示例6: createClient

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * Creates the appropriate jdbc client.
 * @param context 
 * @param config
 */
private IJdbcClient createClient(IPolicyContext context, JDBCIdentitySource config) throws Throwable {
    IJdbcComponent jdbcComponent = context.getComponent(IJdbcComponent.class);

    if (config.getType() == JDBCType.datasource || config.getType() == null) {
        DataSource ds = lookupDatasource(config);
        return jdbcComponent.create(ds);
    }
    if (config.getType() == JDBCType.url) {
        JdbcOptionsBean options = new JdbcOptionsBean();
        options.setJdbcUrl(config.getJdbcUrl());
        options.setUsername(config.getUsername());
        options.setPassword(config.getPassword());
        options.setAutoCommit(true);
        return jdbcComponent.createStandalone(options);
    }
    throw new Exception("Unknown JDBC options."); //$NON-NLS-1$
}
 
开发者ID:apiman,项目名称:apiman,代码行数:23,代码来源:JDBCIdentityValidator.java

示例7: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的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

示例8: doFinalApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * Called when everything is done (the last byte is written).  This is used to
 * record the # of bytes downloaded.
 * @param context
 * @param config
 * @param downloadedBytes
 */
protected void doFinalApply(IPolicyContext context, TransferQuotaConfig config, long downloadedBytes) {
    if (config.getDirection() == TransferDirectionType.download || config.getDirection() == TransferDirectionType.both) {
        final String bucketId = context.getAttribute(BUCKET_ID_ATTR, (String) null);
        final RateBucketPeriod period = context.getAttribute(PERIOD_ATTR, (RateBucketPeriod) null);

        IRateLimiterComponent rateLimiter = context.getComponent(IRateLimiterComponent.class);
        rateLimiter.accept(bucketId, period, config.getLimit(), downloadedBytes, new IAsyncResultHandler<RateLimitResponse>() {
            @Override
            public void handle(IAsyncResult<RateLimitResponse> result) {
                // No need to handle the response - it's too late to do anything meaningful with the result.
                // TODO log any error that might have ocurred
            }
        });
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:23,代码来源:TransferQuotaPolicy.java

示例9: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的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, IgnoredResourcesConfig config,
        IPolicyChain<ApiRequest> chain) {
    if (!satisfiesAnyPath(config, request.getDestination(), request.getType())) {
        super.doApply(request, context, config, chain);
    } else {
        IPolicyFailureFactoryComponent ffactory = context
                .getComponent(IPolicyFailureFactoryComponent.class);
        String msg = Messages.i18n.format("IgnoredResourcesPolicy.PathIgnored", //$NON-NLS-1$
                request.getDestination());
        PolicyFailure failure = ffactory.createFailure(PolicyFailureType.NotFound,
                PolicyFailureCodes.PATHS_TO_IGNORE, msg);
        chain.doFailure(failure);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:IgnoredResourcesPolicy.java

示例10: apply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
public void apply(final ApiResponse response, IPolicyContext context, Object config,
        final IPolicyChain<ApiResponse> chain) {
    final ISharedStateComponent sharedState = context.getComponent(ISharedStateComponent.class);
    final String namespace = "urn:" + getClass().getName();
    final String propName = "test-property";
    sharedState.getProperty(namespace, propName, "NOT_FOUND", new IAsyncResultHandler<String>() {
        @Override
        public void handle(IAsyncResult<String> result) {
            String propVal = result.getResult();
            response.getHeaders().put("X-Shared-State-Value", propVal);
            chain.doApply(response);
        }
    });
}
 
开发者ID:apiman,项目名称:apiman,代码行数:19,代码来源:SimpleSharedStatePolicy.java

示例11: apply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @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)
 */
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    final IHttpClientComponent httpClientComponent = context.getComponent(IHttpClientComponent.class);
    String endpoint = System.getProperty("apiman-gateway-test.endpoints.echo"); //$NON-NLS-1$
    IHttpClientRequest clientRequest = httpClientComponent.request(endpoint, HttpMethod.GET, new IAsyncResultHandler<IHttpClientResponse>() {
        @Override
        public void handle(IAsyncResult<IHttpClientResponse> result) {
            if (result.isError()) {
                request.getHeaders().put("X-HttpClient-Result", "Error"); //$NON-NLS-1$ //$NON-NLS-2$
                request.getHeaders().put("X-HttpClient-Error", result.getError().getMessage()); //$NON-NLS-1$
            } else {
                IHttpClientResponse clientResponse = result.getResult();
                request.getHeaders().put("X-HttpClient-Result", "Success"); //$NON-NLS-1$ //$NON-NLS-2$
                request.getHeaders().put("X-HttpClient-Response-Code", String.valueOf(clientResponse.getResponseCode())); //$NON-NLS-1$
                request.getHeaders().put("X-HttpClient-Response-Message", String.valueOf(clientResponse.getResponseMessage())); //$NON-NLS-1$
                clientResponse.close();
            }
            chain.doApply(request);
        }
    });
    clientRequest.addHeader("X-Test", getClass().getSimpleName()); //$NON-NLS-1$
    clientRequest.end();
}
 
开发者ID:apiman,项目名称:apiman,代码行数:28,代码来源:SimpleHttpClientPolicy.java

示例12: apply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @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)
 */
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    final ISharedStateComponent sharedState = context.getComponent(ISharedStateComponent.class);
    final String namespace = "urn:" + getClass().getName();
    final String propName = "bean-property";
    DataBean db = new DataBean();
    db.setProperty1("my-value");
    db.setProperty2(true);
    db.setProperty3(42);
    sharedState.setProperty(namespace, propName, db, new IAsyncResultHandler<Void>() {
        @Override
        public void handle(IAsyncResult<Void> result) {
            chain.doApply(request);
        }
    });
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:BeanSharedStatePolicy.java

示例13: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的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

示例14: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
@Override
protected void doApply(final ApiRequest request, final IPolicyContext context,
        final CorsConfigBean config, final IPolicyChain<ApiRequest> chain) {
    // Is this request CORS enabled? If not, skip.
    if (CorsConnector.candidateCorsRequest(request)) {
        final CorsConnector corsConnector = new CorsConnector(request, config,
                context.getComponent(IPolicyFailureFactoryComponent.class));

        // We only need to set the short-circuit connector if it's a pre-flight request.
        if (corsConnector.isShortcircuit()) {
            context.setConnectorInterceptor(new IConnectorInterceptor() {

                @Override
                public IApiConnector createConnector() {
                    return corsConnector;
                }
            });
            chain.doSkip(request);
        } else {
            setResponseHeaders(context, corsConnector.getResponseHeaders());

            if (corsConnector.isFailure()) {
                chain.doFailure(corsConnector.getFailure());
            } else {
                chain.doApply(request);
            }
        }
    } else {
        chain.doApply(request);
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:32,代码来源:CorsPolicy.java

示例15: StandardRep

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
public StandardRep(Auth3ScaleBean auth3ScaleBean,
        ApiRequest request,
        ApiResponse response,
        IPolicyContext context,
        StandardAuthCache authCache) {
    this.backendUri = auth3ScaleBean.getBackendEndpoint();
    this.config = auth3ScaleBean.getThreescaleConfig().getProxyConfig().getBackendConfig();
    this.request = request;
    this.context = context;
    this.httpClient = context.getComponent(IHttpClientComponent.class);
    this.failureFactory = context.getComponent(IPolicyFailureFactoryComponent.class);
    this.logger = context.getLogger(StandardRep.class);
    this.authCache = authCache;
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:15,代码来源:StandardRep.java


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