Esempio n. 1
0
  public void asyncCallback() {
    final Client client = ClientFactory.newClient();
    Invocation request =
        client.request("http://jaxrs.examples.org/jaxrsApplication/customers/{id}").get();
    request.pathParam("id", 123);

    // invoke a request in background
    client.queue(
        request,
        new InvocationCallback<Customer>() {

          @Override
          public void onComplete(Future<Customer> future) {
            // Do something
          }
        });

    // invoke another request in background
    Future<?> handle =
        request
            .pathParam("id", 456)
            .queue(
                new InvocationCallback<HttpResponse>() {

                  @Override
                  public void onComplete(Future<HttpResponse> future) {
                    // do something
                  }
                });
    handle.cancel(true);
  }
Esempio n. 2
0
  public void asyncCallbackUsingSubResourceClient() throws Exception {
    final Client client = ClientFactory.newClient();
    Link anyCustomerUri = client.link("http://jaxrs.examples.org/jaxrsApplication/customers/{id}");

    // invoke a request in background
    Future<Customer> handle =
        anyCustomerUri
            .pathParam("id", 123) // Link
            .get() // Invocation (extends HttpRequest)
            .queue(
                new InvocationCallback<Customer>() {

                  @Override
                  public void onComplete(Future<Customer> future) {
                    // Do something
                  }
                });
    handle.cancel(true);

    // invoke another request in background
    anyCustomerUri
        .pathParam("id", 456) // Link
        .get() // Invocation (extends HttpRequest)
        .queue(
            new InvocationCallback<HttpResponse>() {

              @Override
              public void onComplete(Future<HttpResponse> future) {
                // do something
              }
            });

    // invoke one more request using newClient
    HttpRequest<?> request = anyCustomerUri.pathParam("id", 789).get();
    request.cookie(new Cookie("fooName", "XYZ"));
    Future<HttpResponse> response = client.queue(request);
    assert response.get() != null;
  }