Example usage for io.netty.handler.logging LogLevel ERROR

List of usage examples for io.netty.handler.logging LogLevel ERROR

Introduction

In this page you can find the example usage for io.netty.handler.logging LogLevel ERROR.

Prototype

LogLevel ERROR

To view the source code for io.netty.handler.logging LogLevel ERROR.

Click Source Link

Usage

From source file:com.netflix.ribbon.examples.rx.RxMovieServer.java

License:Apache License

public HttpServer<ByteBuf, ByteBuf> createServer() {
    HttpServer<ByteBuf, ByteBuf> server = RxNetty
            .newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
                @Override/*w  w  w .  jav  a  2  s . c  o  m*/
                public Observable<Void> handle(HttpServerRequest<ByteBuf> request,
                        final HttpServerResponse<ByteBuf> response) {
                    if (request.getPath().contains("/users")) {
                        if (request.getHttpMethod().equals(HttpMethod.GET)) {
                            return handleRecommendationsByUserId(request, response);
                        } else {
                            return handleUpdateRecommendationsForUser(request, response);
                        }
                    }
                    if (request.getPath().contains("/recommendations")) {
                        return handleRecommendationsBy(request, response);
                    }
                    if (request.getPath().contains("/movies")) {
                        return handleRegisterMovie(request, response);
                    }
                    response.setStatus(HttpResponseStatus.NOT_FOUND);
                    return response.close();
                }
            }).pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator())
            .enableWireLogging(LogLevel.ERROR).build();

    System.out.println("RxMovie server started...");
    return server;
}

From source file:com.schibsted.triathlon.service.commands.MarathonClient.java

License:Apache License

public Observable<HttpClientResponse<ByteBuf>> postMessage(String message) {
    PipelineConfigurator<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>> pipelineConfigurator = PipelineConfigurators
            .httpClientConfigurator();//from ww w  .  j a v a2  s.c  o  m

    HttpClient<ByteBuf, ByteBuf> client = RxNetty
            .<ByteBuf, ByteBuf>newHttpClientBuilder(networkAddress.getIpAddress(), port)
            .pipelineConfigurator(pipelineConfigurator).enableWireLogging(LogLevel.ERROR).build();

    HttpClientRequest<ByteBuf> request = HttpClientRequest.createPost("/v2/apps");
    request.withRawContentSource(Observable.just(message), StringTransformer.DEFAULT_INSTANCE);
    request.withHeader("Content-Type", "application/json");
    return client.submit(request);
}

From source file:com.schibsted.triathlon.service.RxTestServer.java

License:Apache License

public HttpServer<ByteBuf, ByteBuf> createServer() {
    HttpServer<ByteBuf, ByteBuf> server = RxNetty
            .newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
                @Override/* w  ww  .j a v  a 2  s.  c om*/
                public Observable<Void> handle(HttpServerRequest<ByteBuf> request,
                        final HttpServerResponse<ByteBuf> response) {
                    if (request.getPath().contains("/v2/apps")) {
                        if (request.getHttpMethod().equals(HttpMethod.POST)) {
                            return handleTest(request, response);
                        }
                    }
                    response.setStatus(HttpResponseStatus.NOT_FOUND);
                    return response.close();
                }
            }).pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator())
            .enableWireLogging(LogLevel.ERROR).build();

    System.out.println("RxTetstServer server started...");
    return server;
}

From source file:com.supermy.im.Application.java

License:Apache License

@SuppressWarnings("unchecked")
@Bean(name = "serverBootstrap")
public ServerBootstrap bootstrap() {

    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup(), workerGroup()) //???accept???io
            .channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.ERROR))
            .childHandler(imChannelInitializer);

    /**//  w  w  w.ja v  a2  s. c o  m
     * ?
     */
    Map<ChannelOption<?>, Object> tcpChannelOptions = tcpChannelOptions();
    Set<ChannelOption<?>> keySet = tcpChannelOptions.keySet();
    for (@SuppressWarnings("rawtypes")
    ChannelOption option : keySet) {
        b.option(option, tcpChannelOptions.get(option));
    }

    return b;
}

From source file:io.reactivesocket.tckdrivers.client.JavaTCPClient.java

License:Apache License

/**
 * A function that creates a ReactiveSocket on a new TCP connection.
 * @return a ReactiveSocket/*from  w  ww .  j a v  a2  s .  c  o  m*/
 */
public static ReactiveSocket createClient() {
    ConnectionSetupPayload setupPayload = ConnectionSetupPayload.create("", "");

    if ("tcp".equals(uri.getScheme())) {
        Function<SocketAddress, TcpClient<ByteBuf, ByteBuf>> clientFactory = socketAddress -> TcpClient
                .newClient(socketAddress);

        if (debug)
            clientFactory = socketAddress -> TcpClient.newClient(socketAddress).enableWireLogging("rs",
                    LogLevel.ERROR);

        return toObservable(
                TcpReactiveSocketConnector.create(setupPayload, Throwable::printStackTrace, clientFactory)
                        .connect(new InetSocketAddress(uri.getHost(), uri.getPort()))).toSingle().toBlocking()
                                .value();
    } else {
        throw new UnsupportedOperationException("uri unsupported: " + uri);
    }
}

From source file:io.reactivesocket.websocket.rxnetty.ClientServerTest.java

License:Apache License

@BeforeClass
public static void setup() {
    ReactiveSocketWebSocketServer serverHandler = ReactiveSocketWebSocketServer
            .create(new ConnectionSetupHandler() {
                @Override/*from w w w  . ja  va 2s  .co  m*/
                public RequestHandler apply(ConnectionSetupPayload setupPayload) throws SetupException {
                    return new RequestHandler() {
                        @Override
                        public Publisher<Payload> handleRequestResponse(Payload payload) {
                            return new Publisher<Payload>() {
                                @Override
                                public void subscribe(Subscriber<? super Payload> s) {
                                    System.out.println("Handling request/response payload => " + s.toString());
                                    Payload response = TestUtil.utf8EncodedPayload("hello world", "metadata");
                                    s.onNext(response);
                                    s.onComplete();
                                }
                            };
                        }

                        @Override
                        public Publisher<Payload> handleRequestStream(Payload payload) {
                            return null;
                        }

                        @Override
                        public Publisher<Payload> handleSubscription(Payload payload) {
                            return null;
                        }

                        @Override
                        public Publisher<Void> handleFireAndForget(Payload payload) {
                            return null;
                        }

                        @Override
                        public Publisher<Payload> handleChannel(Payload initialPayload,
                                Publisher<Payload> payloads) {
                            return null;
                        }

                        @Override
                        public Publisher<Void> handleMetadataPush(Payload payload) {
                            return null;
                        }
                    };
                }
            });

    server = HttpServer.newServer()
            //            .clientChannelOption(ChannelOption.AUTO_READ, true)
            .enableWireLogging(LogLevel.ERROR).start((req, resp) -> {
                return resp.acceptWebSocketUpgrade(serverHandler::acceptWebsocket);
            });

    Observable<WebSocketConnection> wsConnection = HttpClient.newClient("localhost", server.getServerPort())
            .enableWireLogging(LogLevel.ERROR).createGet("/rs").requestWebSocketUpgrade()
            .flatMap(WebSocketResponse::getWebSocketConnection);

    Publisher<WebSocketDuplexConnection> connectionPublisher = WebSocketClientDuplexConnection
            .create(RxReactiveStreams.toPublisher(wsConnection));

    client = RxReactiveStreams.toObservable(connectionPublisher)
            .map(w -> ReactiveSocket.fromClientConnection(w, ConnectionSetupPayload.create("UTF-8", "UTF-8")))
            .toBlocking().single();

    client.startAndWait();
}

From source file:io.reactivex.netty.contexts.http.ContextPropagationTest.java

License:Apache License

@Test
public void testEndToEnd() throws Exception {
    HttpServer<ByteBuf, ByteBuf> server = newTestServerBuilder(
            new Func1<HttpClient<ByteBuf, ByteBuf>, Observable<HttpClientResponse<ByteBuf>>>() {
                @Override//from w  w  w. j ava2  s .  c  om
                public Observable<HttpClientResponse<ByteBuf>> call(HttpClient<ByteBuf, ByteBuf> client) {
                    return client.submit(HttpClientRequest.createGet("/"));
                }
            }).enableWireLogging(LogLevel.ERROR).build().start();

    HttpClient<ByteBuf, ByteBuf> testClient = RxNetty
            .<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", server.getServerPort())
            .enableWireLogging(LogLevel.DEBUG).build();

    String reqId = "testE2E";
    sendTestRequest(testClient, reqId);
}

From source file:io.reactivex.netty.examples.http.post.SimplePostClient.java

License:Apache License

public String postMessage() {
    PipelineConfigurator<HttpClientResponse<ByteBuf>, HttpClientRequest<String>> pipelineConfigurator = PipelineConfigurators
            .httpClientConfigurator();// w  ww  .  ja va 2s .  c  o m

    HttpClient<String, ByteBuf> client = RxNetty.<String, ByteBuf>newHttpClientBuilder("localhost", port)
            .pipelineConfigurator(pipelineConfigurator).enableWireLogging(LogLevel.ERROR).build();

    HttpClientRequest<String> request = HttpClientRequest.create(HttpMethod.POST, "test/post");
    request.withRawContentSource(Observable.just(MESSAGE), StringTransformer.DEFAULT_INSTANCE);

    String result = client.submit(request)
            .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<String>>() {
                @Override
                public Observable<String> call(HttpClientResponse<ByteBuf> response) {
                    return response.getContent().map(new Func1<ByteBuf, String>() {
                        @Override
                        public String call(ByteBuf byteBuf) {
                            return byteBuf.toString(Charset.defaultCharset());
                        }
                    });
                }
            }).toBlocking().single();

    return result;
}

From source file:io.reactivex.netty.examples.http.post.SimplePostServer.java

License:Apache License

public HttpServer<ByteBuf, ByteBuf> createServer() {
    HttpServer<ByteBuf, ByteBuf> server = RxNetty
            .newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
                @Override/*from   www.  j  av  a 2  s  . c  o m*/
                public Observable<Void> handle(HttpServerRequest<ByteBuf> request,
                        final HttpServerResponse<ByteBuf> response) {
                    return request.getContent().map(new Func1<ByteBuf, String>() {
                        @Override
                        public String call(ByteBuf byteBuf) {
                            return byteBuf.toString(Charset.defaultCharset());
                        }
                    }).reduce("", new Func2<String, String, String>() {
                        @Override
                        public String call(String accumulator, String value) {
                            return accumulator + value;
                        }
                    }).flatMap(new Func1<String, Observable<Void>>() {
                        @Override
                        public Observable<Void> call(String clientMessage) {
                            response.writeString(clientMessage.toUpperCase());
                            return response.close(false);
                        }
                    });
                }
            }).enableWireLogging(LogLevel.ERROR).build();
    System.out.println("Simple POST server started...");
    return server;
}

From source file:io.reactivex.netty.examples.http.websocket.WebSocketHelloServer.java

License:Apache License

public RxServer<WebSocketFrame, WebSocketFrame> createServer() {
    RxServer<WebSocketFrame, WebSocketFrame> server = RxNetty
            .newWebSocketServerBuilder(port, new ConnectionHandler<WebSocketFrame, WebSocketFrame>() {
                @Override/*ww w . jav a  2s  .c  o m*/
                public Observable<Void> handle(
                        final ObservableConnection<WebSocketFrame, WebSocketFrame> connection) {
                    return connection.getInput().flatMap(new Func1<WebSocketFrame, Observable<Void>>() {
                        @Override
                        public Observable<Void> call(WebSocketFrame wsFrame) {
                            TextWebSocketFrame textFrame = (TextWebSocketFrame) wsFrame;
                            System.out.println("Got message: " + textFrame.text());
                            return connection
                                    .writeAndFlush(new TextWebSocketFrame(textFrame.text().toUpperCase()));
                        }
                    });
                }
            }).enableWireLogging(LogLevel.ERROR).build();

    System.out.println("WebSocket server started...");
    return server;
}