use of com.linkedin.r2.message.stream.StreamRequest in project rest.li by linkedin.
the class ClientStreamCompressionFilter method onStreamError.
@Override
public void onStreamError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
if (ex instanceof StreamException) {
Boolean decompressionOff = (Boolean) requestContext.getLocalAttr(R2Constants.RESPONSE_DECOMPRESSION_OFF);
if (decompressionOff == null || !decompressionOff) {
StreamException se = (StreamException) ex;
StreamResponse response = se.getResponse();
// Check for header encoding
String compressionHeader = response.getHeader(HttpConstants.CONTENT_ENCODING);
// decompress if necessary
if (compressionHeader != null) {
StreamEncodingType encoding = StreamEncodingType.get(compressionHeader.trim().toLowerCase());
if (encoding != null) {
final StreamingCompressor compressor = encoding.getCompressor(_executor);
EntityStream uncompressedStream = compressor.inflate(response.getEntityStream());
StreamResponseBuilder builder = response.builder();
Map<String, String> headers = stripHeaders(builder.getHeaders(), HttpConstants.CONTENT_ENCODING, HttpConstants.CONTENT_LENGTH);
response = builder.setHeaders(headers).build(uncompressedStream);
ex = new StreamException(response);
}
}
}
}
nextFilter.onError(ex, requestContext, wireAttrs);
}
use of com.linkedin.r2.message.stream.StreamRequest in project rest.li by linkedin.
the class UriRewriteProxy method handleRequest.
@Override
public void handleRequest(StreamRequest request, RequestContext requestContext, final Callback<StreamResponse> callback) {
URI newUri = _uriRewriter.rewrite(request.getURI());
StreamRequestBuilder builder = new StreamRequestBuilder(request);
builder.setURI(newUri);
StreamRequest newRequest = builder.build(request.getEntityStream());
_client.streamRequest(newRequest, requestContext, callback);
}
use of com.linkedin.r2.message.stream.StreamRequest in project rest.li by linkedin.
the class AbstractPerfServerFactory method createPureStreamServer.
public Server createPureStreamServer(int port, URI echoUri, final int msg_size, int numHeaders, int headerSize) {
String headerContent = new StringGenerator(headerSize).nextMessage();
StreamRequestHandler handler = new StreamRequestHandler() {
@Override
public void handleRequest(StreamRequest request, RequestContext requestContext, final Callback<StreamResponse> callback) {
request.getEntityStream().setReader(new PerfStreamReader<>(new Callback<None>() {
@Override
public void onError(Throwable e) {
callback.onError(e);
}
@Override
public void onSuccess(None result) {
StreamResponseBuilder builder = new StreamResponseBuilder();
for (int i = 0; i < numHeaders; i++) {
builder.setHeader(STATIC_HEADER_PREFIX + i, headerContent);
}
callback.onSuccess(builder.build(EntityStreams.newEntityStream(new PerfStreamWriter(msg_size))));
}
}, None.none()));
}
};
final TransportDispatcher dispatcher = new TransportDispatcherBuilder().addStreamHandler(echoUri, handler).build();
return createServer(port, dispatcher, true);
}
use of com.linkedin.r2.message.stream.StreamRequest in project rest.li by linkedin.
the class LoggingFilter method onStreamResponse.
@Override
public void onStreamResponse(StreamResponse res, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
EntityStream entityStream = res.getEntityStream();
entityStream.addObserver(new Observer() {
private long startTime;
private long bytesNum = 0;
@Override
public void onDataAvailable(ByteString data) {
if (bytesNum == 0) {
startTime = System.nanoTime();
}
bytesNum += data.length();
}
@Override
public void onDone() {
long stopTime = System.nanoTime();
_log.info("Status: success. Total bytes streamed: " + bytesNum + ". Total stream time: " + (stopTime - startTime) + " nano seconds.");
}
@Override
public void onError(Throwable e) {
long stopTime = System.nanoTime();
_log.error("Status: failed. Total bytes streamed: " + bytesNum + ". Total stream time before failure: " + (stopTime - startTime) + " nano seconds.");
}
});
}
use of com.linkedin.r2.message.stream.StreamRequest in project rest.li by linkedin.
the class FilterUtil method fireStreamRequestResponse.
// Fires a request, saving the local attributes, and then fires a response with the local
// attributes.
public static void fireStreamRequestResponse(FilterChain fc, StreamRequest req, StreamResponse res) {
final RequestContext context = new RequestContext();
wrapFilterChain(fc).onStreamRequest(req, context, emptyWireAttrs());
wrapFilterChain(fc).onStreamResponse(res, context, emptyWireAttrs());
}
Aggregations