Java Code Examples for io.vertx.core.http.HttpClientOptions#setDefaultPort()

The following examples show how to use io.vertx.core.http.HttpClientOptions#setDefaultPort() . 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: RESTVerticleRouteBuilderSelfhostedTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void endpointFourErrorReturnRetryTest() throws InterruptedException {
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/endpointFourErrorReturnRetryTest?productType=123&product=456",
          resp -> resp.bodyHandler(
              body -> {
                System.out.println(
                    "Got a createResponse endpointFourErrorReturnRetryTest: "
                        + body.toString());
                assertEquals(body.toString(), "456123");
                testComplete();
              }));
  request.end();
  await();
}
 
Example 2
Source File: RESTJerseyClientEventStringResponseTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void complexSyncErrorResponseTest() throws InterruptedException {
  System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT2);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/complexSyncErrorResponse",
          resp -> {
            resp.bodyHandler(
                body -> {
                  System.out.println("Got a createResponse" + body.toString());

                  assertEquals(body.toString(), "test exception");
                });

            testComplete();
          });
  request.end();
  await();
}
 
Example 3
Source File: RESTServiceExceptionTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void exceptionInByteResponse() throws InterruptedException {
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/exceptionInByteResponse?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("--------exceptionInByteResponse: " + val);
                    // assertEquals(key, "val");
                    testComplete();
                  });
            }
          });
  request.end();

  await(5000, TimeUnit.MILLISECONDS);
}
 
Example 4
Source File: RESTAsyncThreadCheck.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleTimeoutTest() throws InterruptedException {

  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/simpleTimeoutTest",
          resp ->
              resp.bodyHandler(
                  body -> {
                    System.out.println("Got a createResponse: " + body.toString());
                    assertEquals(body.toString(), "operation _timeout");
                    testComplete();
                  }));
  request.end();
  await();
}
 
Example 5
Source File: RESTJerseyClientErrorTests.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void stringGETResponseAsyncSync() throws InterruptedException {

  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/stringGETResponseAsyncSync",
          resp ->
              resp.bodyHandler(
                  body -> {
                    String val = body.getString(0, body.length());
                    System.out.println(val);
                    assertEquals("test-123", val);
                    testComplete();
                  }));
  request.end();

  await(10000, TimeUnit.MILLISECONDS);
}
 
Example 6
Source File: RESTServiceSelfhostedAsyncTestStaticInitializer.java    From vxms with Apache License 2.0 6 votes vote down vote up
@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",
          resp -> {
            resp.bodyHandler(
                body -> {
                  System.out.println("Got a createResponse: " + body.toString());
                  assertEquals(body.toString(), "123");
                });
            testComplete();
          });
  request.end();
  await();
}
 
Example 7
Source File: RESTServiceExceptionFallbackTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 8
Source File: RESTServiceOnFailureStringResponseTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 9
Source File: RESTJerseyClientEventStringResponseTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleSyncNoConnectionExceptionRetryErrorResponseTest() throws InterruptedException {
  System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT2);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/simpleSyncNoConnectionExceptionRetryErrorResponse",
          resp -> {
            resp.bodyHandler(
                body -> {
                  System.out.println("Got a createResponse" + body.toString());

                  assertEquals(body.toString(), "hello1");
                });

            testComplete();
          });
  request.end();
  await();
}
 
Example 10
Source File: RESTServiceSelfhostedTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void endpointEight_header() throws InterruptedException {
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/endpointEight_header?val=123&tmp=456",
          resp -> {
            resp.bodyHandler(
                body -> {
                  System.out.println(
                      "Got a createResponse endpointFourErrorReturnRetryTest: "
                          + body.toString());

                  assertEquals(body.toString(), "123456");
                });
            String contentType = resp.getHeader("Content-Type");
            assertEquals(contentType, "application/json");
            testComplete();
          });
  request.end();
  await();
}
 
Example 11
Source File: RESTVerticleRouteBuilderSelfhostedTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@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",
          resp -> {
            resp.bodyHandler(
                body -> {
                  System.out.println("Got a createResponse: " + body.toString());
                  if(resp.statusCode()!=200) {
                      fail();
                  }
                  Payload<String> pp = new Gson().fromJson(body.toString(), Payload.class);
                  assertEquals(pp.getValue(), new Payload<>("123" + "456").getValue());
                    testComplete();
                });
          });
  request.end();
  await();
}
 
Example 12
Source File: RESTServiceBlockingChainStringTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@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) {
              assertEquals(resp.statusCode(), 500);
              assertEquals(resp.statusMessage(), "test error");
              testComplete();
            }
          });
  request.end();
  await();
}
 
Example 13
Source File: RESTServiceOnFailureTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@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",
          new Handler<HttpClientResponse>() {
            public void handle(HttpClientResponse resp) {
              System.out.println(resp.statusMessage());
              resp.bodyHandler(
                  body -> {
                    String val = body.getString(0, body.length());
                    System.out.println("--------catchedAsyncByteErrorDelay: " + val);
                    assertEquals("", val);
                    testComplete();
                  });
            }
          });
  request.end();

  await(10000, TimeUnit.MILLISECONDS);
}
 
Example 14
Source File: RESTJerseyClientTests.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void stringDELETEResponse() throws InterruptedException, ExecutionException {

  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client
          .delete(
              "/wsService/stringDELETEResponse",
              resp -> {
                resp.exceptionHandler(error -> {});

                resp.bodyHandler(
                    body -> {
                      System.out.println("Got a createResponse: " + body.toString());
                      assertEquals(body.toString(), "hello");
                      testComplete();
                    });
              })
          .putHeader("Content-Type", "application/json;charset=UTF-8");
  request.end();
  await();
}
 
Example 15
Source File: RESTVerticleRouteBuilderSelfhostedTestStaticInitializer.java    From vxms with Apache License 2.0 6 votes vote down vote up
@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",
          resp -> {
            resp.bodyHandler(
                body -> {
                  System.out.println("Got a createResponse: " + body.toString());
                  assertEquals(body.toString(), "123456");
                });
            testComplete();
          });
  request.end();
  await();
}
 
Example 16
Source File: RESTServiceUnhandledExceptionsTest.java    From vxms with Apache License 2.0 5 votes vote down vote up
@Test
public void unhandledExceptionBlocking() throws InterruptedException {
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/unhandledExceptionBlocking?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: "
                            + resp.statusMessage()
                            + "  CODE: "
                            + resp.statusCode());
                    // assertEquals(key, "val");
                    testComplete();
                  });
            }
          });
  request.end();

  await(5000, TimeUnit.MILLISECONDS);
}
 
Example 17
Source File: RESTJerseyClientSessionTest.java    From vxms with Apache License 2.0 5 votes vote down vote up
@Test
public void sessionTest() throws InterruptedException {
  // System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client
          .get(
              SERVICE_REST_GET + "/session",
              resp -> {
                resp.exceptionHandler(error -> {});

                resp.bodyHandler(
                    body -> {
                      System.out.println("Got a createResponse: " + body.toString());
                      assertNotNull(body.toString());
                      //   assertEquals(body.toString(), "<h1>fgdfgdf</h1>");
                      testComplete();
                    });
              })
          .putHeader("Content-Type", "application/json;charset=UTF-8");
  request.end();
  await();
}
 
Example 18
Source File: RESTVerticleRouteBuilderSelfhostedTest.java    From vxms with Apache License 2.0 5 votes vote down vote up
@Test
public void endpointSix() throws InterruptedException {
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/endpointSix?val=123&tmp=456",
          resp -> {
            resp.bodyHandler(
                body -> {
                  System.out.println("Got a createResponse: " + body.toString());
                  Payload<String> pp = null;
                  try {
                    pp = (Payload<String>) Serializer.deserialize(body.getBytes());
                  } catch (Exception e) {
                    e.printStackTrace();
                    fail();
                  }
                  assertEquals(pp.getValue(), new Payload<>("123" + "456").getValue());
                    testComplete();
                });

          });
  request.end();
  await();
}
 
Example 19
Source File: RESTJerseyClientCORSTest.java    From vxms with Apache License 2.0 5 votes vote down vote up
@Test
public void WsServiceThree_1() throws InterruptedException {
  System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT3);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client
          .get(
              "/wsService/stringGETResponseSyncAsync2",
              resp -> {
                resp.exceptionHandler(error -> {});

                resp.bodyHandler(
                    body -> {
                      System.out.println(
                          "Status: " + resp.statusCode() + " message:" + resp.statusMessage());
                      assertEquals("CORS Rejected - Invalid origin", resp.statusMessage());
                      testComplete();
                    });
              })
          .putHeader("Origin", "http://org.jacpfx.org");
  request.end();
  await();
}
 
Example 20
Source File: RESTServiceChainStringTest.java    From vxms with Apache License 2.0 4 votes vote down vote up
@Test
public void basicTestAndThenWithErrorAndCircuitBreaker() throws InterruptedException {

  HttpClientOptions options = new HttpClientOptions();
  options.setDefaultPort(PORT);
  options.setDefaultHost(HOST);
  HttpClient client = vertx.createHttpClient(options);

  HttpClientRequest request =
      client.get(
          "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/crash",
          resp ->
              resp.bodyHandler(
                  body -> {
                    System.out.println("Got a createResponse: " + body.toString());

                    assertEquals(body.toString(), "failure");
                    HttpClientRequest request2 =
                        client.get(
                            "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/value",
                            resp2 ->
                                resp2.bodyHandler(
                                    body2 -> {
                                      System.out.println(
                                          "Got a createResponse: " + body2.toString());
                                      assertEquals(body2.toString(), "failure");
                                      // wait 1s, but circuit is still open
                                      vertx.setTimer(
                                          1205,
                                          handler -> {
                                            HttpClientRequest request3 =
                                                client.get(
                                                    "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/value",
                                                    resp3 ->
                                                        resp3.bodyHandler(
                                                            body3 -> {
                                                              System.out.println(
                                                                  "Got a createResponse: "
                                                                      + body3.toString());

                                                              assertEquals(
                                                                  body3.toString(), "failure");
                                                              // wait another 1s, now circuit
                                                              // should be closed
                                                              vertx.setTimer(
                                                                  2005,
                                                                  handler2 -> {
                                                                    HttpClientRequest request4 =
                                                                        client.get(
                                                                            "/wsService/basicTestAndThenWithErrorAndCircuitBreaker/value",
                                                                            resp4 ->
                                                                                resp4.bodyHandler(
                                                                                    body4 -> {
                                                                                      System.out
                                                                                          .println(
                                                                                              "Got a createResponse: "
                                                                                                  + body4
                                                                                                      .toString());

                                                                                      assertEquals(
                                                                                          body4
                                                                                              .toString(),
                                                                                          "value");

                                                                                      // should be
                                                                                      // closed
                                                                                      testComplete();
                                                                                    }));
                                                                    request4.end();
                                                                  });
                                                            }));
                                            request3.end();
                                          });
                                    }));
                    request2.end();
                  }));
  request.end();

  await(80000, TimeUnit.MILLISECONDS);
}