use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class BasicExamples method asyncCallback.
public void asyncCallback() {
final Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://jaxrs.examples.org/jaxrsApplication/customers/{id}");
target.resolveTemplate("id", 123).request().async().get(new InvocationCallback<Customer>() {
@Override
public void completed(Customer customer) {
// Do something
}
@Override
public void failed(Throwable error) {
// process error
}
});
// invoke another request in background
Future<?> handle = target.resolveTemplate("id", 456).request().async().get(new InvocationCallback<Response>() {
@Override
public void completed(Response response) {
// do something
}
@Override
public void failed(Throwable error) {
// process error
}
});
handle.cancel(true);
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method createInvocationBuilder.
private static Invocation.Builder createInvocationBuilder(ClientRequestFilter filter) {
Client client = ClientBuilder.newClient();
if (filter != null)
client.register(filter);
WebTarget target = client.target("http://cts.tck:888");
Invocation.Builder builder = target.request();
return builder;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method resolveTemplateWithBooleanTrueTest.
/*
* @testName: resolveTemplateWithBooleanTrueTest
*
* @assertion_ids: JAXRS:JAVADOC:942;
*
* @test_Strategy: Create a new instance by resolving a URI template with a
* given name in the URI of the current target instance using a supplied
* value. In case a template name or value is entered a NullPointerException
* is thrown. A snapshot of the present configuration of the current (parent)
* target instance is taken and is inherited by the newly constructed (child)
* target instance.
*
* if true, the slash ('/') characters in template values will be encoded if
* the template is placed in the URI path component, otherwise the slash
* characters will not be encoded in path templates.
*/
@Test
public void resolveTemplateWithBooleanTrueTest() throws Fault {
WebTarget target = createWebTarget();
target = target.path("{path}").resolveTemplate("path", SLASHED, true);
assertConfigurationSnapshot(target);
URI uri = target.getUri();
assertUriContains(uri, "/" + SLASHED.replace("%", "%25").replace("/", "%2F"));
logMsg("URI", uri, "contains given path parameter");
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method resolveTemplatesReturnsTheSameTargetTest.
/*
* @testName: resolveTemplatesReturnsTheSameTargetTest
*
* @assertion_ids: JAXRS:JAVADOC:946;
*
* @test_Strategy: A call to the method with an empty parameter map is
* ignored, i.e. same WebTarget instance is returned.
*/
@Test
public void resolveTemplatesReturnsTheSameTargetTest() throws Fault {
WebTarget target = createWebTarget();
target = target.path("{path}");
WebTarget other = target.resolveTemplates(new TreeMap<String, Object>());
assertEquals(target, other, "#pathParams did not return the same target when the input map is empty");
logMsg("#pathParams returned the same traget wehn empty as expected");
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getUriTest.
/*
* @testName: getUriTest
*
* @assertion_ids: JAXRS:JAVADOC:608;
*
* @test_Strategy: Get the URI identifying the resource.
*/
@Test
public void getUriTest() throws Fault {
WebTarget target = createWebTarget();
URI uri = target.getUri();
assertContains(uri.toASCIIString(), URL);
logMsg("URI", uri, "contains", URL);
}
Aggregations