예제 #1
0
  public void responseUsingSubResourceClient() {
    Link customersUri =
        ClientFactory.newClient().link("http://jaxrs.examples.org/jaxrsApplication/customers");
    Link customer = customersUri.path("{id}");

    // Create a customer
    HttpResponse response =
        customersUri.post().entity(new Customer("Bill"), "application/xml").invoke();
    assert response.getStatusCode() == 201;

    Customer favorite;
    // view a customer
    favorite =
        customer
            .get() // Invocation (extends HttpRequest)
            .pathParam("id", 123)
            .invoke(Customer.class);
    assert favorite != null;

    // view a customer (alternative)
    favorite =
        customer
            .pathParam(
                "id", 123) // Link ("http://jaxrs.examples.org/jaxrsApplication/customers/123/")
            .get() // Invocation (extends HttpRequest)
            .invoke(Customer.class);
    assert favorite != null;
  }
예제 #2
0
  public void asyncResponse() throws Exception {
    Future<HttpResponse> future =
        ClientFactory.newClient()
            .request("http://jaxrs.examples.org/jaxrsApplication/customers/{id}")
            .get()
            .pathParam("id", 123)
            .queue();

    HttpResponse response = future.get();
    Customer customer = response.getEntity(Customer.class);
    assert customer != null;
  }
예제 #3
0
  public void defaultResponse() {
    Customer customer;
    HttpResponse response;

    final Link customersUri =
        ClientFactory.newClient().link("http://jaxrs.examples.org/jaxrsApplication/customers");

    response = customersUri.path("{id}").get().pathParam("id", 123).invoke();
    customer = response.getEntity(Customer.class);
    assert customer != null;

    response = customersUri.post().entity(new Customer("Marek"), "application/xml").invoke();
    assert response.getStatusCode() == 201;
  }
예제 #4
0
  public void creatingResourceUriRequestsAndInvocations() {
    final Client client = ClientFactory.newClient();
    final Link customersUri = client.link("http://jaxrs.examples.org/jaxrsApplication/customers");

    // Create link request, customize it and invoke using newClient
    HttpRequest<?> request = customersUri.get();
    request.accept(MediaType.APPLICATION_XML).header("Foo", "Bar");
    HttpResponse responseA = client.invoke(request);
    assert responseA.getStatusCode() == 200;

    // Direct invocation leveraging the Invocation interface
    HttpResponse responseB =
        customersUri
            .get() // Invocation (extends HttpRequest)
            .accept(MediaType.APPLICATION_XML)
            .header("Foo", "Bar")
            .invoke();
    assert responseB.getStatusCode() == 200;
  }