List of usage examples for io.netty.handler.logging LogLevel ERROR
LogLevel ERROR
To view the source code for io.netty.handler.logging LogLevel ERROR.
Click Source Link
From source file:io.reactivex.netty.protocol.http.server.Http10Test.java
License:Apache License
@Test public void testHttp1_0RequestWithContent() throws Exception { HttpClientRequest<ByteBuf> request = HttpClientRequest.create(HttpVersion.HTTP_1_0, HttpMethod.GET, "/"); final ByteBuf response = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", mockServerPort) .enableWireLogging(LogLevel.ERROR).build().submit(request) .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<ByteBuf>>() { @Override/*from w w w.j a v a2s . co m*/ public Observable<ByteBuf> call(HttpClientResponse<ByteBuf> response) { return response.getContent(); } }).map(new Func1<ByteBuf, ByteBuf>() { @Override public ByteBuf call(ByteBuf byteBuf) { return byteBuf.retain(); } }).toBlocking().toFuture().get(1, TimeUnit.MINUTES); Assert.assertEquals("Unexpected Content.", WELCOME_SERVER_MSG, response.toString(Charset.defaultCharset())); response.release(); }
From source file:io.reactivex.netty.protocol.http.server.HttpServerTest.java
License:Apache License
@Test public void testNoContentWrite() throws Exception { HttpServer<ByteBuf, ByteBuf> server = RxNetty .newHttpServerBuilder(0, new RequestHandler<ByteBuf, ByteBuf>() { @Override//ww w . ja v a2s . co m public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) { response.setStatus(HttpResponseStatus.NOT_FOUND); return Observable.empty(); } }).enableWireLogging(LogLevel.ERROR).build().start(); final CountDownLatch finishLatch = new CountDownLatch(1); HttpClientResponse<ByteBuf> response = RxNetty.createHttpClient("localhost", server.getServerPort()) .submit(HttpClientRequest.createGet("/")).finallyDo(new Action0() { @Override public void call() { finishLatch.countDown(); } }).toBlocking().toFuture().get(10, TimeUnit.SECONDS); Assert.assertTrue("The returned observable did not finish.", finishLatch.await(1, TimeUnit.MINUTES)); Assert.assertEquals("Request failed.", response.getStatus(), HttpResponseStatus.NOT_FOUND); }
From source file:io.reactivex.netty.protocol.http.server.HttpServerTest.java
License:Apache License
@Test public void testProcessingInADifferentThread() throws Exception { HttpServer<ByteBuf, ByteBuf> server = RxNetty .newHttpServerBuilder(0, new RequestHandler<ByteBuf, ByteBuf>() { @Override// w ww . jav a 2s. c om public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> serverResponse) { return Observable.just(1L, Schedulers.computation()) .flatMap(new Func1<Long, Observable<Void>>() { @Override public Observable<Void> call(Long aLong) { serverResponse.setStatus(HttpResponseStatus.NOT_FOUND); return serverResponse.close(true); // Processing in a separate thread needs a flush. } }); } }).enableWireLogging(LogLevel.ERROR).build().start(); final CountDownLatch finishLatch = new CountDownLatch(1); HttpClientResponse<ByteBuf> response = RxNetty.createHttpClient("localhost", server.getServerPort()) .submit(HttpClientRequest.createGet("/")).finallyDo(new Action0() { @Override public void call() { finishLatch.countDown(); } }).toBlocking().toFuture().get(10, TimeUnit.SECONDS); Assert.assertTrue("The returned observable did not finish.", finishLatch.await(1, TimeUnit.MINUTES)); Assert.assertEquals("Request failed.", response.getStatus(), HttpResponseStatus.NOT_FOUND); }
From source file:io.reactivex.netty.protocol.http.server.HttpServerTest.java
License:Apache License
@Test public void testProxy() throws Exception { HttpServer<ByteBuf, ByteBuf> server = RxNetty .newHttpServerBuilder(0, new RequestHandler<ByteBuf, ByteBuf>() { @Override//from w w w.j a v a 2 s.c om public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> serverResponse) { return RxNetty .<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", mockServer.getServerPort()) .enableWireLogging(LogLevel.DEBUG).build() .submit(HttpClientRequest.createGet("/hello")) .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<Void>>() { @Override public Observable<Void> call(HttpClientResponse<ByteBuf> response) { serverResponse.setStatus(response.getStatus()); return serverResponse.close(true); // Processing in a separate thread needs a flush. } }); } }).enableWireLogging(LogLevel.ERROR).build().start(); final CountDownLatch finishLatch = new CountDownLatch(1); HttpClientResponse<ByteBuf> response = RxNetty .<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", server.getServerPort()) .enableWireLogging(LogLevel.DEBUG).build().submit(HttpClientRequest.createGet("/")) .finallyDo(new Action0() { @Override public void call() { finishLatch.countDown(); } }).toBlocking().toFuture().get(10, TimeUnit.SECONDS); Assert.assertTrue("The returned observable did not finish.", finishLatch.await(10, TimeUnit.SECONDS)); Assert.assertEquals("Request failed.", response.getStatus(), HttpResponseStatus.OK); }
From source file:io.reactivex.netty.protocol.http.sse.ServerSentEventEndToEndTest.java
License:Apache License
private Observable<ServerSentEvent> receiveSse() { return RxNetty.<ByteBuf, ServerSentEvent>newHttpClientBuilder("localhost", sseServer.getServerPort()) .pipelineConfigurator(PipelineConfigurators.<ByteBuf>clientSseConfigurator()) .enableWireLogging(LogLevel.ERROR).build().submit(HttpClientRequest.createGet("/")) .flatMap(new Func1<HttpClientResponse<ServerSentEvent>, Observable<ServerSentEvent>>() { @Override/* ww w. j a v a2 s .c o m*/ public Observable<ServerSentEvent> call(HttpClientResponse<ServerSentEvent> response) { if (response.getStatus().equals(HttpResponseStatus.OK)) { return response.getContent(); } else { return Observable.error(new IllegalStateException( "Server response status: " + response.getStatus().code())); } } }); }
From source file:io.reactivex.netty.protocol.http.sse.ServerSentEventEndToEndTest.java
License:Apache License
private void startServer( final Func2<HttpServerResponse<ServerSentEvent>, Long, Observable<Void>> writeEventForInterval) { sseServer = RxNetty.newHttpServerBuilder(0, new RequestHandler<ByteBuf, ServerSentEvent>() { @Override/*from w w w .java 2 s . com*/ public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ServerSentEvent> response) { return Observable.interval(1, TimeUnit.SECONDS).flatMap(new Func1<Long, Observable<Void>>() { @Override public Observable<Void> call(Long interval) { return writeEventForInterval.call(response, interval); } }); } }).enableWireLogging(LogLevel.ERROR) .pipelineConfigurator(PipelineConfigurators.<ByteBuf>serveSseConfigurator()).build(); sseServer.start(); }
From source file:io.reactivex.netty.protocol.http.websocket.WebSocketMetricsTest.java
License:Apache License
public TestableClientMetricsEventListener sendRequestReply() throws Exception { WebSocketClient<WebSocketFrame, WebSocketFrame> client = RxNetty .newWebSocketClientBuilder("localhost", server.getServerPort()).enableWireLogging(LogLevel.ERROR) .build();/*from ww w. j av a2 s .c o m*/ TestableClientMetricsEventListener eventListener = new TestableClientMetricsEventListener(); client.subscribe(eventListener); client.connect() .flatMap(new Func1<ObservableConnection<WebSocketFrame, WebSocketFrame>, Observable<Void>>() { @Override public Observable<Void> call( final ObservableConnection<WebSocketFrame, WebSocketFrame> connection) { return Observable.concat(connection.writeAndFlush(new TextWebSocketFrame("WS-Request")), connection.getInput().flatMap(new Func1<WebSocketFrame, Observable<Void>>() { @Override public Observable<Void> call(WebSocketFrame webSocketFrame) { return connection.close(); } })); } }).materialize().toBlocking().single(); return eventListener; }
From source file:io.reactivex.netty.RxNettyHttpShorthandsTest.java
License:Apache License
@Before public void setUp() throws Exception { mockServer = RxNetty.newHttpServerBuilder(0, new RequestHandler<ByteBuf, ByteBuf>() { @Override/*ww w . j a v a2 s . c o m*/ public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> response) { response.getHeaders().add(METHOD_HEADER, request.getHttpMethod().name()); return request.getContent().materialize() .flatMap(new Func1<Notification<ByteBuf>, Observable<Void>>() { @Override public Observable<Void> call(Notification<ByteBuf> notification) { switch (notification.getKind()) { case OnNext: response.getHeaders().set(CONTENT_RECEIEVED_HEADER, "true"); return Observable.empty(); case OnError: return Observable.error(notification.getThrowable()); case OnCompleted: return Observable.empty(); } return Observable.error(new IllegalArgumentException("Unknown notification type.")); } }); } }).enableWireLogging(LogLevel.ERROR).build().start(); }
From source file:io.reactivex.netty.samples.SimplePostClient.java
License:Apache License
public Observable<String> postMessage() { HttpClient<String, ByteBuf> client = RxNetty.<String, ByteBuf>newHttpClientBuilder(host, port) .pipelineConfigurator(PipelineConfigurators.httpClientConfigurator()) .enableWireLogging(LogLevel.ERROR).build(); HttpClientRequest<String> request = HttpClientRequest.create(HttpMethod.POST, path); request.withHeader(HttpHeaders.Names.CONTENT_TYPE, "application/x-www-form-urlencoded"); String authString = USERNAME + ":" + PASSWORD; ByteBuf authByteBuf = Unpooled.copiedBuffer(authString.toCharArray(), CharsetUtil.UTF_8); ByteBuf encodedAuthByteBuf = Base64.encode(authByteBuf); request.withHeader(HttpHeaders.Names.AUTHORIZATION, "Basic " + encodedAuthByteBuf.toString(CharsetUtil.UTF_8)); request.withRawContentSource(Observable.just(MESSAGE), StringTransformer.DEFAULT_INSTANCE); return client.submit(request).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<String>>() { @Override/* w ww . j a v a2 s . c o m*/ public Observable<String> call(HttpClientResponse<ByteBuf> response) { if (!response.getStatus().equals(HttpResponseStatus.OK)) { return Observable.<String>error(new HttpStatusNotOKException()); } return response.getContent() // .defaultIfEmpty(Unpooled.EMPTY_BUFFER) .map(new Func1<ByteBuf, ByteBuf>() { @Override public ByteBuf call(ByteBuf buf) { return Unpooled.copiedBuffer(buf); } }).reduce(new Func2<ByteBuf, ByteBuf, ByteBuf>() { @Override public ByteBuf call(ByteBuf buf1, ByteBuf buf2) { ByteBuf buf3 = Unpooled.copiedBuffer(buf1, buf2); buf1.release(); buf2.release(); return buf3; } }).map(new Func1<ByteBuf, String>() { @Override public String call(ByteBuf buf4) { String str = buf4.toString(Charset.defaultCharset()); buf4.release(); return str; } }); } }).retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() { @Override public Observable<?> call(Observable<? extends Throwable> notificationHandler) { return notificationHandler.flatMap(new Func1<Throwable, Observable<Throwable>>() { @Override public Observable<Throwable> call(Throwable e) { if ((e instanceof ConnectException && e.getMessage().subSequence(0, 18).equals("Connection refused")) || (e instanceof HttpStatusNotOKException) || (e instanceof NoSuchElementException && e.getMessage().equals("Sequence contains no elements"))) { // logger.error(e.getMessage(), e); return Observable.<Throwable>just(e); } return Observable.<Throwable>error(e); } }).zipWith(Observable.range(1, 4), (e, i) -> { // TODO create tuple class to contain both e, i if (i < 4) { return new Throwable(String.valueOf(i)); } else { return e; } }).flatMap((e) -> { try { int i = Integer.valueOf(e.getMessage()); logger.info("retry({}{}) after {}sec", i, (i == 1) ? "st" : (i == 2) ? "nd" : (i == 3) ? "rd" : "th", 1); return Observable.timer(3, TimeUnit.SECONDS); } catch (NumberFormatException nfe) { return Observable.<Throwable>error(e); } }); } }); // .toBlocking().singleOrDefault("No Data"); }
From source file:net.smert.frameworkgl.Network.java
License:Apache License
public void setLogLevelError() { this.logLevel = LogLevel.ERROR; }