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


Java AbstractStream类代码示例

本文整理汇总了Java中io.apiman.gateway.engine.io.AbstractStream的典型用法代码示例。如果您正苦于以下问题:Java AbstractStream类的具体用法?Java AbstractStream怎么用?Java AbstractStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: responseDataHandler

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

示例2: requestDataHandler

import io.apiman.gateway.engine.io.AbstractStream; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedDataPolicy#requestDataHandler(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
protected IReadWriteStream<ApiRequest> requestDataHandler(final ApiRequest request,
        final IPolicyContext context, final TransferQuotaConfig config) {
    // *************************************************************
    // Step 2:  if upload quotas are enabled, then count all bytes
    //          uploaded to the back-end API
    // *************************************************************
    if (config.getDirection() == TransferDirectionType.upload || config.getDirection() == TransferDirectionType.both) {
        return new AbstractStream<ApiRequest>() {
            private long total = 0;
            @Override
            public ApiRequest getHead() {
                return request;
            }
            @Override
            protected void handleHead(ApiRequest head) {
            }
            @Override
            public void write(IApimanBuffer chunk) {
                total += chunk.length();
                super.write(chunk);
            }
            @Override
            public void end() {
                context.setAttribute(BYTES_UPLOADED_ATTR, total);
                super.end();
            }
        };
    } else {
        return null;
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:36,代码来源:TransferQuotaPolicy.java

示例3: responseDataHandler

import io.apiman.gateway.engine.io.AbstractStream; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedDataPolicy#responseDataHandler(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
protected IReadWriteStream<ApiResponse> responseDataHandler(final ApiResponse response,
        final IPolicyContext context, final TransferQuotaConfig config) {
    // *************************************************************
    // Step 4:  if download quotas are enabled, then count all bytes
    //          downloaded from the back-end API and store the count
    // ---
    // Note: we have no easy way to fail the request if the download
    //       quota is exceeded - so we'll pass and then fail on the
    //       next request (see Step 1)
    // *************************************************************
    if (config.getDirection() == TransferDirectionType.download || config.getDirection() == TransferDirectionType.both) {
        return new AbstractStream<ApiResponse>() {
            private long total = 0;
            @Override
            public ApiResponse getHead() {
                return response;
            }
            @Override
            protected void handleHead(ApiResponse head) {
            }
            @Override
            public void write(IApimanBuffer chunk) {
                total += chunk.length();
                super.write(chunk);
            }
            @Override
            public void end() {
                doFinalApply(context, config, total);
                super.end();
            }
        };
    } else {
        return null;
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:40,代码来源:TransferQuotaPolicy.java

示例4: getRequestDataHandler

import io.apiman.gateway.engine.io.AbstractStream; //导入依赖的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,
        final IPolicyContext context, final Object policyConfiguration) {
    return new AbstractStream<ApiRequest>() {
        @Override
        public ApiRequest getHead() {
            return request;
        }

        @Override
        protected void handleHead(ApiRequest head) {
        }

        @Override
        public void write(IApimanBuffer chunk) {
            try {
                String chunkstr = chunk.toString("UTF-8");
                if (chunkstr.contains("$NAME")) {
                    chunkstr = chunkstr.replaceAll("\\$NAME", "Barry Allen");
                    IBufferFactoryComponent bufferFactory = context.<IBufferFactoryComponent>getComponent(IBufferFactoryComponent.class);

                    super.write(bufferFactory.createBuffer(chunkstr));
                } else {
                    super.write(chunk);
                }
            } catch (UnsupportedEncodingException e) {
                super.write(chunk);
            }
        }
    };
}
 
开发者ID:apiman,项目名称:apiman,代码行数:35,代码来源:SimpleDataPolicy.java

示例5: getRequestDataHandler

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

示例6: getResponseDataHandler

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

示例7: responseDataHandler

import io.apiman.gateway.engine.io.AbstractStream; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedDataPolicy#responseDataHandler(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
protected IReadWriteStream<ApiResponse> responseDataHandler(final ApiResponse response,
        IPolicyContext context, CachingConfig policyConfiguration) {

    // Possibly cache the response for future posterity.
    // Check the response code against list in config (empty/null list means cache all).
    final boolean shouldCache = (context.getAttribute(SHOULD_CACHE_ATTR, Boolean.TRUE) &&
            ofNullable(policyConfiguration.getStatusCodes())
                .map(statusCodes -> statusCodes.isEmpty() || statusCodes.contains(String.valueOf(response.getCode())))
                .orElse(true));

    if (shouldCache) {
        try {
            String cacheId = context.getAttribute(CACHE_ID_ATTR, null);
            ICacheStoreComponent cache = context.getComponent(ICacheStoreComponent.class);
            final ISignalWriteStream writeStream = cache.putBinary(cacheId, response, policyConfiguration.getTtl());
            return new AbstractStream<ApiResponse>() {
                @Override
                public ApiResponse getHead() {
                    return response;
                }
                @Override
                protected void handleHead(ApiResponse head) {
                }
                @Override
                public void write(IApimanBuffer chunk) {
                    writeStream.write(chunk);
                    super.write(chunk);
                }
                @Override
                public void end() {
                    writeStream.end();
                    super.end();
                }
            };
        } catch (ComponentNotFoundException | IOException e) {
            // TODO log error
            return null;
        }
    } else {
        return null;
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:47,代码来源:CachingPolicy.java


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