當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。