use of io.reactivex.netty.protocol.http.server.HttpServerRequest in project WSPerfLab by Netflix-Skunkworks.
the class TestRouteBasic method handle.
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
long startTime = System.currentTimeMillis();
List<String> _id = request.getQueryParameters().get("id");
if (_id == null || _id.size() != 1) {
return writeError(request, response, "Please provide a numerical 'id' value. It can be a random number (uuid).");
}
long id = Long.parseLong(String.valueOf(_id.get(0)));
Observable<List<BackendResponse>> acd = getDataFromBackend("/mock.json?numItems=2&itemSize=50&delay=50&id=" + id).doOnError(Throwable::printStackTrace).<// Eclipse 20140224-0627 can't infer without this type hint even though the Java 8 compiler can
List<BackendResponse>>flatMap(responseA -> {
Observable<BackendResponse> responseC = getDataFromBackend("/mock.json?numItems=1&itemSize=5000&delay=80&id=" + responseA.getResponseKey());
Observable<BackendResponse> responseD = getDataFromBackend("/mock.json?numItems=1&itemSize=1000&delay=1&id=" + responseA.getResponseKey());
return Observable.zip(Observable.just(responseA), responseC, responseD, Arrays::asList);
}).doOnError(Throwable::printStackTrace);
Observable<List<BackendResponse>> be = getDataFromBackend("/mock.json?numItems=25&itemSize=30&delay=150&id=" + id).<// Eclipse 20140224-0627 can't infer without this type hint even though the Java 8 compiler can
List<BackendResponse>>flatMap(responseB -> {
Observable<BackendResponse> responseE = getDataFromBackend("/mock.json?numItems=100&itemSize=30&delay=4&id=" + responseB.getResponseKey());
return Observable.zip(Observable.just(responseB), responseE, Arrays::asList);
}).doOnError(Throwable::printStackTrace);
return Observable.zip(acd, be, (_acd, _be) -> {
BackendResponse responseA = _acd.get(0);
BackendResponse responseB = _be.get(0);
BackendResponse responseC = _acd.get(1);
BackendResponse responseD = _acd.get(2);
BackendResponse responseE = _be.get(1);
return new BackendResponse[] { responseA, responseB, responseC, responseD, responseE };
}).flatMap(backendResponses -> {
try {
ByteArrayOutputStream responseStream = ServiceResponseBuilder.buildTestAResponse(jsonFactory, backendResponses);
response.getHeaders().addHeader("Content-Type", "application/json");
addResponseHeaders(response, startTime);
int contentLength = responseStream.size();
response.getHeaders().addHeader("Content-Length", contentLength);
return response.writeBytesAndFlush(responseStream.toByteArray());
} catch (Exception e) {
return writeError(request, response, "Failed: " + e.getMessage());
}
}).doOnError(Throwable::printStackTrace);
}
use of io.reactivex.netty.protocol.http.server.HttpServerRequest in project feign by OpenFeign.
the class RealRequestBenchmarks method setup.
@Setup
public void setup() {
server = RxNetty.createHttpServer(SERVER_PORT, new RequestHandler<ByteBuf, ByteBuf>() {
public rx.Observable handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
return response.flush();
}
});
server.start();
client = new OkHttpClient();
client.setRetryOnConnectionFailure(false);
okFeign = Feign.builder().client(new feign.okhttp.OkHttpClient(client)).target(FeignTestInterface.class, "http://localhost:" + SERVER_PORT);
queryRequest = new Request.Builder().url("http://localhost:" + SERVER_PORT + "/?Action=GetUser&Version=2010-05-08&limit=1").build();
}
use of io.reactivex.netty.protocol.http.server.HttpServerRequest in project spring-framework by spring-projects.
the class RxNettyHttpHandlerAdapter method handle.
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> nativeRequest, HttpServerResponse<ByteBuf> nativeResponse) {
Channel channel = nativeResponse.unsafeNettyChannel();
NettyDataBufferFactory bufferFactory = new NettyDataBufferFactory(channel.alloc());
InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress();
RxNettyServerHttpRequest request = new RxNettyServerHttpRequest(nativeRequest, bufferFactory, remoteAddress);
RxNettyServerHttpResponse response = new RxNettyServerHttpResponse(nativeResponse, bufferFactory);
Publisher<Void> result = this.httpHandler.handle(request, response).otherwise(ex -> {
logger.error("Could not complete request", ex);
nativeResponse.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
return Mono.empty();
}).doOnSuccess(aVoid -> logger.debug("Successfully completed request"));
return RxReactiveStreams.toObservable(result);
}
use of io.reactivex.netty.protocol.http.server.HttpServerRequest in project Hystrix by Netflix.
the class HystrixMetricsStreamHandlerTest method createServer.
// We try a few times in case we hit into used port.
private HttpServer<ByteBuf, ByteBuf> createServer() {
Random random = new Random();
Exception error = null;
for (int i = 0; i < 3 && server == null; i++) {
port = 10000 + random.nextInt(50000);
try {
return RxNetty.newHttpServerBuilder(port, new HystrixMetricsStreamHandler<ByteBuf, ByteBuf>(DEFAULT_HYSTRIX_PREFIX, DEFAULT_INTERVAL, new // Application handler
RequestHandler<ByteBuf, ByteBuf>() {
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
return Observable.empty();
}
})).build().start();
} catch (Exception e) {
error = e;
}
}
throw new RuntimeException("Cannot initialize RxNetty server", error);
}
Aggregations