本文整理汇总了Java中io.vertx.core.http.HttpClientOptions.setDefaultPort方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientOptions.setDefaultPort方法的具体用法?Java HttpClientOptions.setDefaultPort怎么用?Java HttpClientOptions.setDefaultPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpClientOptions
的用法示例。
在下文中一共展示了HttpClientOptions.setDefaultPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test404Response
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void test404Response() throws Exception {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultHost("localhost");
options.setDefaultPort(port());
HttpClient client = Mesh.vertx().createHttpClient(options);
CompletableFuture<String> future = new CompletableFuture<>();
HttpClientRequest request = client.request(HttpMethod.POST, "/api/v1/test", rh -> {
rh.bodyHandler(bh -> {
future.complete(bh.toString());
});
});
request.end();
String response = future.get(1, TimeUnit.SECONDS);
assertTrue("The response string should not contain any html specific characters but it was {" + response + "} ",
response.indexOf("<") != 0);
}
示例2: exceptionInErrorHandler
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void exceptionInErrorHandler() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/exceptionInErrorHandler",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
String val = body.getString(0, body.length());
System.out.println("--------exceptionInStringResponse: " + val);
assertEquals(val, "catched");
testComplete();
});
}
});
request.end();
await(5000, TimeUnit.MILLISECONDS);
}
示例3: asyncStringResponse
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void asyncStringResponse() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/asyncStringResponse",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
System.out.println("Got a createResponse: " + body.toString());
Assert.assertEquals(body.toString(), "test");
});
testComplete();
}
});
request.end();
await();
}
示例4: basicTestAndThenWithErrorUnhandled
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
// @Ignore
public void basicTestAndThenWithErrorUnhandled() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/basicTestAndThenWithErrorUnhandled",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
Assert.assertEquals(resp.statusCode(), 500);
Assert.assertEquals(resp.statusMessage(), "test error");
testComplete();
}
});
request.end();
await();
}
示例5: basicTestAndThenWithErrorUnhandledRetry
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
// @Ignore
public void basicTestAndThenWithErrorUnhandledRetry() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/basicTestAndThenWithErrorUnhandledRetry",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
System.out.println("Got a createResponse: " + body.toString());
Assert.assertEquals(body.toString(), "error 4 test error");
testComplete();
});
}
});
request.end();
await();
}
示例6: basicTestSupplyWithErrorUnhandled
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
// @Ignore
public void basicTestSupplyWithErrorUnhandled() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/basicTestSupplyWithErrorUnhandled",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
Assert.assertEquals(resp.statusCode(), 500);
Assert.assertEquals(resp.statusMessage(), "test error");
testComplete();
}
});
request.end();
await();
}
示例7: endpointOne
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
// @Ignore
public void endpointOne() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/endpointOne",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
System.out.println("Got a createResponse: " + body.toString());
Assert.assertEquals(body.toString(), "1test final");
testComplete();
});
}
});
request.end();
await();
}
示例8: endpointFive
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void endpointFive() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/endpointFive?val=123&tmp=456",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
System.out.println("Got a createResponse: " + body.toString());
Payload<String> pp = new Gson().fromJson(body.toString(), Payload.class);
assertEquals(pp.getValue(), new Payload<>("123" + "456").getValue());
});
testComplete();
}
});
request.end();
await();
}
示例9: exceptionInStringResponseWithErrorHandler
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void exceptionInStringResponseWithErrorHandler() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/exceptionInStringResponseWithErrorHandler?val=123&tmp=456",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
String val = body.getString(0, body.length());
System.out.println("--------exceptionInStringResponse: " + val);
// assertEquals(key, "val");
testComplete();
});
}
});
request.end();
await(5000, TimeUnit.MILLISECONDS);
}
示例10: catchedAsyncStringErrorDelay
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void catchedAsyncStringErrorDelay() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/catchedAsyncStringErrorDelay?val=123&tmp=456",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
String val = body.getString(0, body.length());
System.out.println("--------catchedAsyncStringErrorDelay: " + val);
// assertEquals(key, "val");
testComplete();
});
}
});
request.end();
await(5000, TimeUnit.MILLISECONDS);
}
示例11: asyncStringResponseParameter
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void asyncStringResponseParameter() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/asyncStringResponseParameter/123",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
System.out.println("Got a createResponse: " + body.toString());
Assert.assertEquals(body.toString(), "123");
});
testComplete();
}
});
request.end();
await();
}
示例12: catchedAsyncObjectErrorDelay
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void catchedAsyncObjectErrorDelay() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/catchedAsyncObjectErrorDelay?val=123&tmp=456",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
String val = body.getString(0, body.length());
System.out.println("--------catchedAsyncByteErrorDelay: " + val);
// assertEquals(key, "val");
testComplete();
});
}
});
request.end();
await(10000, TimeUnit.MILLISECONDS);
}
示例13: simpleOnFailureResponse
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void simpleOnFailureResponse() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/simpleOnFailureResponse",
resp ->
resp.bodyHandler(
body -> {
String val = body.getString(0, body.length());
System.out.println("--------catchedAsyncByteErrorDelay: " + val);
assertEquals("on failure", val);
testComplete();
}));
request.end();
await(10000, TimeUnit.MILLISECONDS);
}
示例14: testStockTradesAudited
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void testStockTradesAudited(TestContext context) {
Async async = context.async();
HttpClientOptions options = new HttpClientOptions().setDefaultHost(config.getString("http.host"));
options.setDefaultPort(config.getInt("http.port"));
HttpClient client = vertx.createHttpClient(options);
client.get("/", response -> {
context.assertEquals(response.statusCode(), 200);
response.bodyHandler(buffer -> {
JsonArray body = buffer.toJsonArray();
context.assertTrue(body.size() >= 3);
async.complete();
});
}).end();
}
示例15: SpringConfigServerStore
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
SpringConfigServerStore(Vertx vertx, JsonObject configuration) {
String url = configuration.getString("url");
this.timeout = configuration.getLong("timeout", 3000L);
Objects.requireNonNull(url);
HttpClientOptions options = new HttpClientOptions();
try {
URL u = new URL(url);
options.setDefaultHost(u.getHost());
if (u.getPort() == -1) {
options.setDefaultPort(u.getDefaultPort());
} else {
options.setDefaultPort(u.getPort());
}
if (u.getPath() != null) {
path = u.getPath();
} else {
path = "/";
}
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid url for the spring server: " + url);
}
if (configuration.getString("user") != null && configuration.getString("password") != null) {
authHeaderValue = "Basic " + Base64.getEncoder().encodeToString((configuration.getString("user")
+ ":" + configuration.getString("password")).getBytes());
} else {
authHeaderValue = null;
}
client = vertx.createHttpClient(options);
}