use of io.apiman.gateway.engine.io.AbstractStream in project apiman by apiman.
the class SimpleDataPolicy method getRequestDataHandler.
/**
* @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);
}
}
};
}
Aggregations