本文整理汇总了Java中io.vertx.core.http.HttpClientOptions.setDefaultHost方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientOptions.setDefaultHost方法的具体用法?Java HttpClientOptions.setDefaultHost怎么用?Java HttpClientOptions.setDefaultHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpClientOptions
的用法示例。
在下文中一共展示了HttpClientOptions.setDefaultHost方法的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: 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();
}
示例3: 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();
}
示例4: exceptionInMethodBody
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void exceptionInMethodBody() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/exceptionInMethodBody?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("--------exceptionInMethodBody: " + val);
// assertEquals(key, "val");
testComplete();
});
}
});
request.end();
await();
}
示例5: basicTestAndThen
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
// @Ignore
public void basicTestAndThen() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/basicTestAndThen",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
System.out.println("Got a createResponse: " + body.toString());
Assert.assertEquals(body.toString(), "2 final");
testComplete();
});
}
});
request.end();
await();
}
示例6: 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();
}
示例7: 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);
}
示例8: endpointThree
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void endpointThree() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/endpointThree?val=123&tmp=456",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(
body -> {
System.out.println("Got a createResponse: " + body.toString());
assertEquals(body.toString(), "123456");
});
testComplete();
}
});
request.end();
await();
}
示例9: endpointOne
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
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(), "test");
testComplete();
});
}
});
request.end();
await();
}
示例10: 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);
}
示例11: simpleOnFailureResponseBlocking
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
@Test
public void simpleOnFailureResponseBlocking() throws InterruptedException {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultPort(PORT);
options.setDefaultHost(HOST);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request =
client.get(
"/wsService/simpleOnFailureResponseBlocking",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse 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);
}
示例12: 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);
}
示例13: S3Store
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
/**
* Constructs a new store
* @param vertx the Vert.x instance
*/
public S3Store(Vertx vertx) {
super(vertx);
this.vertx = vertx;
JsonObject config = vertx.getOrCreateContext().config();
accessKey = config.getString(ConfigConstants.STORAGE_S3_ACCESS_KEY);
Preconditions.checkNotNull(accessKey, "Missing configuration item \"" +
ConfigConstants.STORAGE_S3_ACCESS_KEY + "\"");
secretKey = config.getString(ConfigConstants.STORAGE_S3_SECRET_KEY);
Preconditions.checkNotNull(secretKey, "Missing configuration item \"" +
ConfigConstants.STORAGE_S3_SECRET_KEY + "\"");
host = config.getString(ConfigConstants.STORAGE_S3_HOST);
Preconditions.checkNotNull(host, "Missing configuration item \"" +
ConfigConstants.STORAGE_S3_HOST + "\"");
port = config.getInteger(ConfigConstants.STORAGE_S3_PORT, 80);
bucket = config.getString(ConfigConstants.STORAGE_S3_BUCKET);
Preconditions.checkNotNull(bucket, "Missing configuration item \"" +
ConfigConstants.STORAGE_S3_BUCKET + "\"");
pathStyleAccess = config.getBoolean(ConfigConstants.STORAGE_S3_PATH_STYLE_ACCESS, true);
forceSignatureV2 = config.getBoolean(ConfigConstants.STORAGE_S3_FORCE_SIGNATURE_V2, false);
requestExpirySeconds = config.getInteger(ConfigConstants.STORAGE_S3_REQUEST_EXPIRY_SECONDS, 600);
HttpClientOptions options = new HttpClientOptions();
options.setDefaultHost(host);
options.setDefaultPort(port);
client = vertx.createHttpClient(options);
}
示例14: 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(
configuration.getJsonObject("httpClientConfiguration", new JsonObject()));
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);
}
示例15: AbstractMeshRestHttpClient
import io.vertx.core.http.HttpClientOptions; //导入方法依赖的package包/类
public AbstractMeshRestHttpClient(String host, int port, boolean ssl, Vertx vertx) {
HttpClientOptions options = new HttpClientOptions();
options.setDefaultHost(host);
options.setTryUseCompression(true);
options.setDefaultPort(port);
options.setSsl(ssl);
this.clientOptions = options;
this.vertx = vertx;
}