use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class BasicExamples method asyncCallbackUsingSubResourceClient.
public void asyncCallbackUsingSubResourceClient() throws Exception {
final Client client = ClientBuilder.newClient();
WebTarget anyCustomerUri = client.target("http://jaxrs.examples.org/jaxrsApplication/customers/{id}");
// invoke a request in background
Future<Customer> handle = // Target
anyCustomerUri.resolveTemplate("id", 123).request().async().get(new InvocationCallback<Customer>() {
@Override
public void completed(Customer customer) {
// do something
}
@Override
public void failed(Throwable throwable) {
// do something
}
});
handle.cancel(true);
// invoke another request in background
// Target
anyCustomerUri.resolveTemplate("id", 456).request().async().get(new InvocationCallback<Response>() {
@Override
public void completed(Response customer) {
// do something
}
@Override
public void failed(Throwable throwable) {
// do something
}
});
// invoke one more request using newClient
Future<Response> response = anyCustomerUri.resolveTemplate("id", 789).request().cookie(new Cookie("fooName", "XYZ")).async().get();
assert response.get() != null;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class BasicExamples method creatingResourceUriRequestsAndInvocations.
public void creatingResourceUriRequestsAndInvocations() {
final Client client = ClientBuilder.newClient();
final WebTarget customersUri = client.target("http://jaxrs.examples.org/jaxrsApplication/customers");
// Create target request, customize it and invoke using newClient
Response response = customersUri.request(MediaType.APPLICATION_XML).header("Foo", "Bar").get();
assert response.getStatus() == 200;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class BasicExamples method responseUsingSubResourceClient.
public void responseUsingSubResourceClient() {
WebTarget customersUri = ClientBuilder.newClient().target("http://jaxrs.examples.org/jaxrsApplication/customers");
WebTarget customer = customersUri.path("{id}");
// Create a customer
Response response = customersUri.request().post(xml(new Customer("Bill")));
assert response.getStatus() == 201;
Customer favorite;
// view a customer
favorite = customer.resolveTemplate("id", 123).request().get(Customer.class);
assert favorite != null;
// view a customer (alternative)
favorite = customer.resolveTemplate("id", // Target ("http://jaxrs.examples.org/jaxrsApplication/customers/123/")
123).request().get(Customer.class);
assert favorite != null;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class BasicExamples method defaultResponse.
public void defaultResponse() {
Customer customer;
Response response;
final WebTarget customersUri = ClientBuilder.newClient().target("http://jaxrs.examples.org/jaxrsApplication/customers");
response = customersUri.path("{id}").resolveTemplate("id", 123).request().get();
customer = response.readEntity(Customer.class);
assert customer != null;
response = customersUri.request().post(xml(new Customer("Marek")));
assert response.getStatus() == 201;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class SpecExamples method benefitsOfResourceUri.
public void benefitsOfResourceUri() {
Client client = ClientBuilder.newClient();
WebTarget base = client.target("http://example.org/");
WebTarget hello = base.path("hello").path("{whom}");
final WebTarget whomToGreet = hello.resolveTemplate("whom", "world");
Response res = whomToGreet.request().get();
}
Aggregations