本文整理汇总了Java中io.reactivex.netty.protocol.http.client.HttpClient.newClient方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClient.newClient方法的具体用法?Java HttpClient.newClient怎么用?Java HttpClient.newClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.netty.protocol.http.client.HttpClient
的用法示例。
在下文中一共展示了HttpClient.newClient方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
public static HttpClient<ByteBuf, ByteBuf> create(String server, final String portStr) {
int port = 0;
try {
URL url = new URL(defaultToHttps(server));
if (portStr == null) {
port = url.getDefaultPort();
} else if (Integer.parseInt(portStr) > 0){
port = Integer.parseInt(portStr);
}
final HttpClient<ByteBuf, ByteBuf> httpClient = HttpClient.newClient(new InetSocketAddress(
url.getHost(), port));
if(url.getProtocol().equals("https")) {
return httpClient.unsafeSecure();
} else if (url.getProtocol().equals("http")) {
return httpClient;
} else {
throw new RuntimeException("Unsuported protocol");
}
}
catch(MalformedURLException e){
throw new RuntimeException(e);
}
}
示例2: getHttpClient
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
public HttpClient<ByteBuf, ByteBuf> getHttpClient () {
if (client == null) {
HttpClient<ByteBuf, ByteBuf> _client = embedded ? HttpClient.newClient(getServerAddress()) : HttpClient.newClient(new InetSocketAddress("localhost", 8080));
client = _client;
}
return client;
}
示例3: testGET
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void testGET() throws InterruptedException, ExecutionException, TimeoutException {
SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());
/*Create a new client for the server address*/
HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createGet(PATH_1 + "?" + QUERY_1);
Object result1 = req1
.flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
.map(bb -> bb.toString(Charset.defaultCharset())))
.singleOrDefault(null).toBlocking().toFuture().get(5, TimeUnit.SECONDS);
assertNull(result1);
Wait.until(() -> getApmMockServer().getTraces().size() == 1);
// Check stored traces (including 1 for the test client)
assertEquals(1, getApmMockServer().getTraces().size());
List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);
assertEquals("Expecting 1 producers", 1, producers.size());
Producer testProducer = producers.get(0);
assertEquals(PATH_1, testProducer.getUri());
assertEquals(QUERY_1, testProducer.getProperties(Constants.PROP_HTTP_QUERY).iterator().next().getValue());
assertEquals("GET", testProducer.getOperation());
assertEquals("GET", testProducer.getProperties("http_method").iterator().next().getValue());
}
示例4: testPOST
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void testPOST() throws InterruptedException, ExecutionException, TimeoutException {
SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());
/*Create a new client for the server address*/
HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createPost(PATH_2);
req1.writeStringContent(Observable.just(HELLO_THERE));
Object result1 = req1
.flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
.map(bb -> bb.toString(Charset.defaultCharset())))
.singleOrDefault(null).toBlocking().toFuture().get(5, TimeUnit.SECONDS);
assertNull(result1);
Wait.until(() -> getApmMockServer().getTraces().size() == 1);
// Check stored traces (including 1 for the test client)
assertEquals(1, getApmMockServer().getTraces().size());
List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);
assertEquals("Expecting 1 producers", 1, producers.size());
Producer testProducer = producers.get(0);
assertEquals(PATH_2, testProducer.getUri());
assertTrue(testProducer.getProperties(Constants.PROP_HTTP_QUERY).isEmpty());
assertEquals("POST", testProducer.getOperation());
assertEquals("POST", testProducer.getProperties("http_method").iterator().next().getValue());
}
示例5: testPUT
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void testPUT() throws InterruptedException, ExecutionException, TimeoutException {
SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());
/*Create a new client for the server address*/
HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createPut(PATH_3);
req1.writeStringContent(Observable.just(HELLO_THERE));
Object result1 = req1
.flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
.map(bb -> bb.toString(Charset.defaultCharset())))
.singleOrDefault(null).toBlocking().toFuture().get(5, TimeUnit.SECONDS);
assertNull(result1);
Wait.until(() -> getApmMockServer().getTraces().size() == 1);
// Check stored traces (including 1 for the test client)
assertEquals(1, getApmMockServer().getTraces().size());
List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);
assertEquals("Expecting 1 producers", 1, producers.size());
Producer testProducer = producers.get(0);
assertEquals(PATH_3, testProducer.getUri());
assertTrue(testProducer.getProperties(Constants.PROP_HTTP_QUERY).isEmpty());
assertEquals("PUT", testProducer.getOperation());
assertEquals("PUT", testProducer.getProperties("http_method").iterator().next().getValue());
}
示例6: testGET
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void testGET() throws InterruptedException, ExecutionException, TimeoutException {
SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());
/*Create a new client for the server address*/
HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createGet(PATH_1 + "?" + QUERY_1);
Object result1 = req1
.flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
.map(bb -> bb.toString(Charset.defaultCharset())))
.single().toBlocking().toFuture().get(5, TimeUnit.SECONDS);
assertEquals(HELLO_WORLD, result1);
// Check stored traces (including 1 for the test client)
Wait.until(() -> getApmMockServer().getTraces().size() == 1);
assertEquals(1, getApmMockServer().getTraces().size());
List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);
assertEquals("Expecting 1 producers", 1, producers.size());
Producer testProducer = producers.get(0);
assertEquals(PATH_1, testProducer.getUri());
assertEquals(QUERY_1, testProducer.getProperties(Constants.PROP_HTTP_QUERY).iterator().next().getValue());
assertEquals("GET", testProducer.getOperation());
assertEquals("GET", testProducer.getProperties("http_method").iterator().next().getValue());
}
示例7: testPOST
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void testPOST() throws InterruptedException, ExecutionException, TimeoutException {
SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());
/*Create a new client for the server address*/
HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createPost(PATH_2);
req1.writeStringContent(Observable.just(HELLO_THERE));
Object result1 = req1
.flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
.map(bb -> bb.toString(Charset.defaultCharset())))
.single().toBlocking().toFuture().get(5, TimeUnit.SECONDS);
assertEquals(HELLO_WORLD, result1);
// Check stored traces (including 1 for the test client)
Wait.until(() -> getApmMockServer().getTraces().size() == 1);
assertEquals(1, getApmMockServer().getTraces().size());
List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);
assertEquals("Expecting 1 producers", 1, producers.size());
Producer testProducer = producers.get(0);
assertEquals(PATH_2, testProducer.getUri());
assertTrue(testProducer.getProperties(Constants.PROP_HTTP_QUERY).isEmpty());
assertEquals("POST", testProducer.getOperation());
assertEquals("POST", testProducer.getProperties("http_method").iterator().next().getValue());
}
示例8: testPUT
import io.reactivex.netty.protocol.http.client.HttpClient; //导入方法依赖的package包/类
@Test
public void testPUT() throws InterruptedException, ExecutionException, TimeoutException {
SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());
/*Create a new client for the server address*/
HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createPut(PATH_3);
req1.writeStringContent(Observable.just(HELLO_THERE));
Object result1 = req1
.flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
.map(bb -> bb.toString(Charset.defaultCharset())))
.single().toBlocking().toFuture().get(5, TimeUnit.SECONDS);
assertEquals(HELLO_WORLD, result1);
// Check stored traces (including 1 for the test client)
Wait.until(() -> getApmMockServer().getTraces().size() == 1);
assertEquals(1, getApmMockServer().getTraces().size());
List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);
assertEquals("Expecting 1 producers", 1, producers.size());
Producer testProducer = producers.get(0);
assertEquals(PATH_3, testProducer.getUri());
assertTrue(testProducer.getProperties(Constants.PROP_HTTP_QUERY).isEmpty());
assertEquals("PUT", testProducer.getOperation());
assertEquals("PUT", testProducer.getProperties("http_method").iterator().next().getValue());
}