Search in sources :

Example 46 with WebTarget

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);
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) Client(jakarta.ws.rs.client.Client) ThrottledClient(jaxrs.examples.client.custom.ThrottledClient)

Example 47 with WebTarget

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;
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client)

Example 48 with WebTarget

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");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 49 with WebTarget

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");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 50 with WebTarget

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);
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

WebTarget (jakarta.ws.rs.client.WebTarget)96 Test (org.junit.jupiter.api.Test)63 Client (jakarta.ws.rs.client.Client)52 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)27 Response (jakarta.ws.rs.core.Response)24 Configuration (jakarta.ws.rs.core.Configuration)17 URI (java.net.URI)17 Invocation (jakarta.ws.rs.client.Invocation)16 Assertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable)14 SingleCheckAssertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable)14 JaxrsCommonClient (ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient)14 HashMap (java.util.HashMap)8 JdkLoggingFilter (ee.jakarta.tck.ws.rs.common.client.JdkLoggingFilter)6 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)5 InboundSseEvent (jakarta.ws.rs.sse.InboundSseEvent)5 SseEventSource (jakarta.ws.rs.sse.SseEventSource)5 ConfigurableObject (ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject)4 LinkedHolder (ee.jakarta.tck.ws.rs.common.util.LinkedHolder)4 Configurable (jakarta.ws.rs.core.Configurable)4 ThrottledClient (jaxrs.examples.client.custom.ThrottledClient)4