本文整理匯總了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
}
};
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
};
}
示例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();
}
};
}
示例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;
}
示例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;
}
}