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


Java IPolicyContext.getAttribute方法代码示例

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


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

示例1: doTokenAuth

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
private Holder<Boolean> doTokenAuth(Holder<Boolean> successStatus, ApiRequest request,
        IPolicyContext context, KeycloakOauthConfigBean config, IPolicyChain<ApiRequest> chain,
        String rawToken) {
    try {
        AccessToken parsedToken = RSATokenVerifier.verifyToken(rawToken, config.getRealmCertificate()
                .getPublicKey(), config.getRealm());

        delegateKerberosTicket(request, config, parsedToken);
        forwardHeaders(request, config, rawToken, parsedToken);
        stripAuthTokens(request, config);
        forwardAuthRoles(context, config, parsedToken);

        RequestMetric metric = context.getAttribute(PolicyContextKeys.REQUEST_METRIC, (RequestMetric) null);
        if (metric != null) {
            metric.setUser(parsedToken.getPreferredUsername());
        }

        return successStatus.setValue(true);
    } catch (VerificationException e) {
        System.out.println(e);
        chain.doFailure(failureFactory.verificationException(context, e));
        return successStatus.setValue(false);
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:25,代码来源:KeycloakOauthPolicy.java

示例2: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
protected void doApply(ApiResponse response, IPolicyContext context, CircuitBreakerConfigBean config,
        IPolicyChain<ApiResponse> chain) {
    Circuit circuit = context.getAttribute(CircuitBreakerPolicy.class.getName() + ".circuit", (Circuit) null); //$NON-NLS-1$
    boolean isFault = isCircuitFault(response, config);
    if (circuit.isResetting()) {
        if (isFault) {
            circuit.trip();
        } else {
            circuit.reset();
        }
    } else {
        if (isFault) {
            circuit.addFault();
        }
    }
    super.doApply(response, context, config, chain);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:22,代码来源:CircuitBreakerPolicy.java

示例3: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
protected void doApply(ApiResponse response, IPolicyContext context, LogHeadersConfigBean config,
        IPolicyChain<ApiResponse> chain) {
    IApimanLogger logger = context.getLogger(getClass());
    if (config.getDirection() != LogHeadersDirectionType.request) {
        String endpoint = context.getAttribute(ENDPOINT_ATTRIBUTE, ""); //$NON-NLS-1$
        if (config.isLogStatusCode()) {
            logger.info(String.format("Status code %d for %s", response.getCode(), endpoint));
        }
        if (config.isLogHeaders()) {
            logHeaders(logger, response.getHeaders(), HttpDirection.RESPONSE, endpoint);
        }
    }
    chain.doApply(response);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:19,代码来源:LogHeadersPolicy.java

示例4: 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

示例5: 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)
 */
@SuppressWarnings("nls")
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    try {
        SOAPEnvelope soapPayload = context.getAttribute(PolicyContextKeys.REQUEST_PAYLOAD, (SOAPEnvelope) null);
        if (soapPayload != null) {
            SOAPHeader header = soapPayload.getHeader();
            SOAPHeaderElement header1 = (SOAPHeaderElement) header.examineAllHeaderElements().next();
            String prop1 = header1.getTextContent();
            request.getHeaders().put("X-Property-1", prop1);
            header.addHeaderElement(new QName("urn:ns5", "Property5")).setTextContent("value-5");
        }
        chain.doApply(request);
    } catch (Exception e) {
        chain.throwError(e);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:22,代码来源:SimpleSoapPayloadPolicy.java

示例6: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * See {@link AbstractMappedPolicy#doApply(ApiResponse, IPolicyContext, Object, IPolicyChain)}
 */
@Override
protected void doApply(ApiResponse response, IPolicyContext context, CookieRemoveConfigBean config,
                       IPolicyChain<ApiResponse> chain) {

    // short-circuit
    if (context.getAttribute(ATTRIBUTE_SKIP, false)) {
        chain.doApply(response);
        return;
    }

    final Cookie cookie = context.getAttribute(ATTRIBUTE_REMOVE_COOKIE, null);
    if (null != cookie) {
        removeCookie(response, config, cookie);
    } else {
        LOGGER.debug(MESSAGES.format("RemovalSkipped"));
    }

    if (ResponseBehaviour.Redirect.equals(config.getResponseBehaviour())) {
        LOGGER.info(MESSAGES.format("Redirecting", config.getRedirectUrl()));

        // remove existing Content-Length header before continuing chain, as API response will not be returned
        response.getHeaders().remove(Constants.HEADER_CONTENT_LENGTH);

        // redirect client
        response.setCode(HttpURLConnection.HTTP_MOVED_TEMP);
        response.getHeaders().put(Constants.HEADER_LOCATION, config.getRedirectUrl());
    }

    chain.doApply(response);
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:34,代码来源:CookieRemovePolicy.java

示例7: responseDataHandler

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * See {@link AbstractMappedDataPolicy#responseDataHandler(ApiResponse, IPolicyContext, Object)}
 */
@Override
protected IReadWriteStream<ApiResponse> responseDataHandler(final ApiResponse response,
                                                            final IPolicyContext context,
                                                            final CookieRemoveConfigBean config) {
    // short-circuit
    if (context.getAttribute(ATTRIBUTE_SKIP, false)) {
        return null;
    }

    if (ResponseBehaviour.PassThrough.equals(config.getResponseBehaviour())) {
        // default response behaviour
        return null;

    } else {
        // discard response body from back-end service
        return new AbstractStream<ApiResponse>() {
            @Override
            protected void handleHead(ApiResponse head) {
            }

            @Override
            public ApiResponse getHead() {
                return response;
            }

            @Override
            public void write(IApimanBuffer chunk) {
                // discard chunk
            }
        };
    }
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:36,代码来源:CookieRemovePolicy.java

示例8: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
@Override
protected void doApply(ApiResponse response, IPolicyContext context, TransformationConfigBean config,
        IPolicyChain<ApiResponse> chain) {
    final DataFormat clientFormat = (DataFormat) context.getAttribute(CLIENT_FORMAT, null);
    final DataFormat serverFormat = (DataFormat) context.getAttribute(SERVER_FORMAT, null);

    if (isValidTransformation(clientFormat, serverFormat)) {
        response.getHeaders().put(CONTENT_TYPE, clientFormat.getContentType());
        response.getHeaders().remove(CONTENT_LENGTH);
    }

    super.doApply(response, context, config, chain);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:14,代码来源:TransformationPolicy.java

示例9: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
@Override
protected void doApply(ApiResponse response, IPolicyContext context, Auth3ScaleBean config, IPolicyChain<ApiResponse> chain) {
    try {
        // Just let it go ahead, and report stuff at our leisure.
        chain.doApply(response);
        ApiRequest request = context.getAttribute(AUTH3SCALE_REQUEST, null);
        auth3scale.getRep(config, response, request, context).rep();
    } catch (Exception e) {
        logger.error("Unexpected error", e);
        e.printStackTrace();
        chain.throwError(UNEXPECTED_ERROR);
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:14,代码来源:Auth3Scale.java

示例10: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
protected void doApply(ApiResponse response, IPolicyContext context, RateLimitingConfig config,
        IPolicyChain<ApiResponse> chain) {
    Map<String, String> headers = context.getAttribute("rate-limit-response-headers", null); //$NON-NLS-1$
    if (headers != null) {
        response.getHeaders().putAll(headers);
    }
    super.doApply(response, context, config, chain);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:13,代码来源:RateLimitingPolicy.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)
 */
@SuppressWarnings("nls")
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    Document xmlPayload = context.getAttribute(PolicyContextKeys.REQUEST_PAYLOAD, (Document) null);
    if (xmlPayload != null) {
        String prop1 = xmlPayload.getElementsByTagName("property-1").item(0).getTextContent();
        request.getHeaders().put("X-Property-1", prop1);
        Element prop5Elem = xmlPayload.createElement("property-5");
        prop5Elem.setTextContent("value-5");
        xmlPayload.getDocumentElement().appendChild(prop5Elem);
    }
    chain.doApply(request);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:18,代码来源:SimpleXmlPayloadPolicy.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)
 */
@SuppressWarnings("nls")
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    Map jsonPayload = context.getAttribute(PolicyContextKeys.REQUEST_PAYLOAD, (Map) null);
    if (jsonPayload != null) {
        String prop1 = (String) jsonPayload.get("property-1");
        request.getHeaders().put("X-Property-1", prop1);
        jsonPayload.put("property-5", "value-5");
    }
    chain.doApply(request);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:16,代码来源:SimpleJsonPayloadPolicy.java

示例13: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * See {@link AbstractMappedPolicy#doApply(ApiResponse, IPolicyContext, Object, IPolicyChain)}
 */
@Override
protected void doApply(ApiResponse response, IPolicyContext context, final CookieIssueConfigBean config,
                       IPolicyChain<ApiResponse> chain) {

    // short-circuit
    if (context.getAttribute(ATTRIBUTE_SKIP, false)) {
        LOGGER.debug(MESSAGES.format("PathMatchFalse"));
        chain.doApply(response);
        return;
    }

    // validate the API response code
    if (response.getCode() != config.getApiResponseCode()) {
        LOGGER.warn(MESSAGES.format("ApiResponseCodeInvalid",
                response.getCode(), config.getApiResponseCode()));

        chain.doFailure(new PolicyFailure(PolicyFailureType.Authentication, HttpURLConnection.HTTP_UNAUTHORIZED,
                Constants.GENERIC_AUTH_FAILURE));

        return;
    }

    final Cookie cookie = generateCookie(config);

    // remember ID
    final String sessionId = cookie.getValue();
    context.setAttribute(ATTRIBUTE_SESSION_ID, sessionId);

    // set the response cookie
    CookieUtil.addResponseCookie(response, cookie);

    LOGGER.info(MESSAGES.format("ApiResponseCodeValid",
            config.getApiResponseCode(), config.getCookieName(), sessionId));

    if (ResponseBehaviour.Redirect.equals(config.getResponseBehaviour())) {
        LOGGER.info(MESSAGES.format("Redirecting", config.getRedirectUrl()));

        // remove existing Content-Length header before continuing chain, as API response will not be returned
        response.getHeaders().remove(Constants.HEADER_CONTENT_LENGTH);

        // redirect client
        response.setCode(HttpURLConnection.HTTP_MOVED_TEMP);
        response.getHeaders().put(Constants.HEADER_LOCATION, config.getRedirectUrl());
    }

    // continue the chain
    chain.doApply(response);
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:52,代码来源:CookieIssuePolicy.java

示例14: getRequestDataHandler

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policy.IDataPolicy#getRequestDataHandler(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
public IReadWriteStream<ApiRequest> getRequestDataHandler(final ApiRequest request,
        IPolicyContext context, Object policyConfiguration) {

    final IBufferFactoryComponent bufferFactory = context.getComponent(IBufferFactoryComponent.class);
    final int contentLength = request.getHeaders().containsKey(CONTENT_LENGTH)
            ? Integer.parseInt(request.getHeaders().get(CONTENT_LENGTH))
            : 0;

    return new AbstractStream<ApiRequest>() {

        private IApimanBuffer readBuffer = bufferFactory.createBuffer(contentLength);

        @Override
        public ApiRequest getHead() {
            return request;
        }

        @Override
        protected void handleHead(ApiRequest head) {
        }

        @Override
        public void write(IApimanBuffer chunk) {
            readBuffer.append(chunk.getBytes());
        }

        @Override
        public void end() {
            final DataFormat clientFormat = (DataFormat) context.getAttribute(CLIENT_FORMAT, null);
            final DataFormat serverFormat = (DataFormat) context.getAttribute(SERVER_FORMAT, null);
            
            if (readBuffer.length() > 0) {
                if (isValidTransformation(clientFormat, serverFormat)) {
                    DataTransformer dataTransformer = DataTransformerFactory.getDataTransformer(clientFormat, serverFormat);
                    IApimanBuffer writeBuffer = bufferFactory.createBuffer(readBuffer.length());

                    String data = dataTransformer.transform(new String(readBuffer.getBytes()));
                    writeBuffer.append(data);

                    super.write(writeBuffer);
                } else {
                    super.write(readBuffer);
                }
            }
            super.end();
        }
    };
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:53,代码来源:TransformationPolicy.java

示例15: getResponseDataHandler

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policy.IDataPolicy#getResponseDataHandler(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
public IReadWriteStream<ApiResponse> getResponseDataHandler(final ApiResponse response,
        IPolicyContext context, Object policyConfiguration) {
    final DataFormat clientFormat = (DataFormat) context.getAttribute(CLIENT_FORMAT, null);
    final DataFormat serverFormat = (DataFormat) context.getAttribute(SERVER_FORMAT, null);

    if (isValidTransformation(clientFormat, serverFormat)) {
        final IBufferFactoryComponent bufferFactory = context.getComponent(IBufferFactoryComponent.class);
        final int contentLength = response.getHeaders().containsKey(CONTENT_LENGTH)
                ? Integer.parseInt(response.getHeaders().get(CONTENT_LENGTH))
                : 0;

        return new AbstractStream<ApiResponse>() {

            private IApimanBuffer readBuffer = bufferFactory.createBuffer(contentLength);

            @Override
            public ApiResponse getHead() {
                return response;
            }

            @Override
            protected void handleHead(ApiResponse head) {
            }

            @Override
            public void write(IApimanBuffer chunk) {
                byte[] bytes = chunk.getBytes();
                readBuffer.append(bytes);
            }

            @Override
            public void end() {
                if (readBuffer.length() > 0) {
                    DataTransformer dataTransformer = DataTransformerFactory.getDataTransformer(serverFormat, clientFormat);
                    IApimanBuffer writeBuffer = bufferFactory.createBuffer(readBuffer.length());

                    String data = dataTransformer.transform(new String(readBuffer.getBytes()));
                    writeBuffer.append(data);

                    super.write(writeBuffer);
                }
                super.end();
            }
        };
    }

    return null;
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:53,代码来源:TransformationPolicy.java


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