Java Code Examples for io.reactivex.netty.RxNetty#createHttpClient()
The following examples show how to use
io.reactivex.netty.RxNetty#createHttpClient() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxNettyEventEventStreamClient.java From MarketData with Apache License 2.0 | 5 votes |
private Observable<String> initializeStream() { HttpClient<ByteBuf, ServerSentEvent> client = RxNetty.createHttpClient("localhost", port, PipelineConfigurators.<ByteBuf>clientSseConfigurator()); return client.submit(HttpClientRequest.createGet("/hello")). flatMap(response -> { printResponseHeader(response); return response.getContent(); }).map(serverSentEvent -> serverSentEvent.contentAsString()); }
Example 2
Source File: TcpSocketProxyTest.java From mesos-rxjava with Apache License 2.0 | 5 votes |
@Test public void testConnectionTerminatedOnClose() throws Exception { final TcpSocketProxy proxy = new TcpSocketProxy( new InetSocketAddress("localhost", 0), new InetSocketAddress("localhost", server.getServerPort()) ); proxy.start(); final int listenPort = proxy.getListenPort(); final HttpClient<ByteBuf, ByteBuf> client = RxNetty.createHttpClient("localhost", listenPort); final String first = client.submit(HttpClientRequest.createGet("/")) .flatMap(AbstractHttpContentHolder::getContent) .map(bb -> bb.toString(StandardCharsets.UTF_8)) .toBlocking() .first(); assertThat(first).isEqualTo("Hello World"); LOGGER.info("first request done"); proxy.shutdown(); if (proxy.isShutdown()) { proxy.close(); } else { fail("proxy should have been shutdown"); } try { final URI uri = URI.create(String.format("http://localhost:%d/", listenPort)); uri.toURL().getContent(); fail("Shouldn't have been able to get content"); } catch (IOException e) { // expected } }