Search in sources :

Example 26 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method createInvocationBuilder.

protected 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 27 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method checkConfig.

protected void checkConfig(Registrar registrar, Assertable assertable, Object[] registerables) throws Fault {
    Client client = ClientBuilder.newClient();
    Configuration config = client.getConfiguration();
    registeredClassesCnt = config.getClasses().size();
    registeredInstancesCnt = config.getInstances().size();
    logMsg("Already registered", registeredClassesCnt, "classes");
    logMsg("Already registered", registeredInstancesCnt, "instances");
    register(registrar, client, registerables[0]);
    assertable.check1OnClient(client);
    assertable.incrementLocation();
    WebTarget target = client.target("http://tck.cts:888");
    register(registrar, target, registerables[1]);
    assertable.check2OnTarget(target);
    assertable.incrementLocation();
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client)

Example 28 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method fromResourceMethodLinkUsedInInvocationTest.

/*
     * @testName: fromResourceMethodLinkUsedInInvocationTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:787;
     * 
     * @test_Strategy: Generate a link by introspecting a resource method.
     */
@Test
public void fromResourceMethodLinkUsedInInvocationTest() throws Fault {
    final String linkName = "link";
    Client client = ClientBuilder.newClient();
    client.register(new ClientRequestFilter() {

        @Override
        public void filter(ClientRequestContext ctx) throws IOException {
            String uri = ctx.getUri().toASCIIString();
            Link.Builder builder = Link.fromMethod(Resource.class, "consumesAppJson").rel(linkName);
            Link link = builder.build();
            Response response = Response.ok(uri).links(link).build();
            ctx.abortWith(response);
        }
    });
    // Phase 1, ask for a link;
    WebTarget target = client.target(url() + "resource/get");
    Response response = target.request().get();
    String entity = response.readEntity(String.class);
    assertTrue(response.hasLink(linkName), "No link received");
    assertContains(url() + "resource/get", entity);
    // Phase 2, use the link, check the correctness
    assertTrue(response.hasLink(linkName), "No link received");
    Link link = response.getLink(linkName);
    response = client.invocation(link).post(null);
    entity = response.readEntity(String.class);
    assertTrue(response.hasLink(linkName), "No link received");
    assertContains(url() + "resource/consumesappjson", entity);
    logMsg("Opaque Link has been used in Client.invocation() sucessfully");
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Builder(jakarta.ws.rs.core.Link.Builder) UriBuilder(jakarta.ws.rs.core.UriBuilder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) IOException(java.io.IOException) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 29 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class BuilderClientIT method invocation.

protected Invocation.Builder invocation() {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(URL);
    Builder b = target.request();
    return b;
}
Also used : ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Builder(jakarta.ws.rs.client.Invocation.Builder) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) WebTarget(jakarta.ws.rs.client.WebTarget) Client(jakarta.ws.rs.client.Client)

Example 30 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method isRegisteredProviderRegisteredInstanceTest.

/*
     * @testName: isRegisteredProviderRegisteredInstanceTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:1001; JAXRS:JAVADOC:1002;
     * 
     * @test_Strategy: Check if a particular JAX-RS component instance (such as
     * providers or features) has been previously registered in the runtime
     * configuration context.
     * 
     * Method returns true only in case an instance equal to the component instance
     * is already present among the components previously registered in the
     * configuration context.
     */
@Test
public void isRegisteredProviderRegisteredInstanceTest() throws Fault {
    Assertable assertable = new Assertable() {

        CallableProvider1 p1 = new CallableProvider1();

        CallableProvider2 p2 = new CallableProvider2();

        @Override
        public void check1OnClient(Client client) throws Fault {
            client.register(p1);
            assertSizeAndLog(client.getConfiguration(), 1);
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            target.register(p2);
            assertSizeAndLog(target.getConfiguration(), 2);
        }

        void assertSizeAndLog(Configuration config, int size) throws Fault {
            assertFalse(config.isRegistered(CallableProvider.class), "CallableProvider is unexpectedly registered");
            switch(size) {
                case 2:
                    assertFalse(config.isRegistered(new CallableProvider2()), "CallableProvider2 is registered " + getLocation());
                    assertTrue(config.isRegistered(p2), "CallableProvider2.class is NOT registered " + getLocation());
                    assertTrue(config.isRegistered(CallableProvider2.class), "CallableProvider2.class is NOT registered " + getLocation());
                    logMsg("Found registered CallableProvider2 as expected", getLocation());
                case 1:
                    assertFalse(config.isRegistered(new CallableProvider1()), "CallableProvider1 is registered " + getLocation());
                    assertTrue(config.isRegistered(p1), "CallableProvider1.class is NOT registered " + getLocation());
                    assertTrue(config.isRegistered(CallableProvider1.class), "CallableProvider1.class is NOT registered " + getLocation());
                    logMsg("Found registered CallableProvider1 as expected", getLocation());
            }
        }
    };
    checkConfigWithProperties(assertable);
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) CallableProvider(ee.jakarta.tck.ws.rs.api.rs.core.configurable.CallableProvider) Assertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable) SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client) 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