當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientOptions.setDefaultHost方法代碼示例

本文整理匯總了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);
}
 
開發者ID:gentics,項目名稱:mesh,代碼行數:20,代碼來源:MeshRestAPITest.java

示例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();
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:22,代碼來源:RESTServiceBlockingChainObjectTest.java

示例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();
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:25,代碼來源:RESTServiceSelfhostedTestStaticInitializer.java

示例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();
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:26,代碼來源:RESTServiceExceptionTest.java

示例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();
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:25,代碼來源:RESTServiceChainStringTest.java

示例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();
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:25,代碼來源:RESTServiceBlockingChainObjectTest.java

示例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);
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:26,代碼來源:RESTServiceExceptionTest.java

示例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();
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:24,代碼來源:RESTServiceSelfhostedTestStaticInitializer.java

示例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();
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:24,代碼來源:RESTServiceSelfhostedTest.java

示例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);
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:26,代碼來源:RESTServiceExceptionTest.java

示例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);
}
 
開發者ID:amoAHCP,項目名稱:vxms,代碼行數:26,代碼來源:RESTServiceOnFailureStringResponseTest.java

示例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);

}
 
開發者ID:cescoffier,項目名稱:vertx-configuration-service,代碼行數:37,代碼來源:SpringConfigServerStore.java

示例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);
}
 
開發者ID:georocket,項目名稱:georocket,代碼行數:38,代碼來源:S3Store.java

示例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);

}
 
開發者ID:vert-x3,項目名稱:vertx-config,代碼行數:38,代碼來源:SpringConfigServerStore.java

示例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;
}
 
開發者ID:gentics,項目名稱:mesh,代碼行數:10,代碼來源:AbstractMeshRestHttpClient.java


注:本文中的io.vertx.core.http.HttpClientOptions.setDefaultHost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。