Search in sources :

Example 6 with WebTarget

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

the class SpecExamples method typeRelationships.

public void typeRelationships() {
    Client client = ClientBuilder.newClient();
    WebTarget uri = client.target("");
    Invocation.Builder builder = uri.request("text/plain");
    SyncInvoker syncInvoker = builder;
    AsyncInvoker asyncInvoker = builder.async();
    Invocation inv = builder.buildGet();
    Response r1 = builder.get();
    Response r2 = syncInvoker.get();
    Response r3 = inv.invoke();
    Future<Response> fr1 = asyncInvoker.get();
    Future<Response> fr2 = inv.submit();
}
Also used : Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) AsyncInvoker(jakarta.ws.rs.client.AsyncInvoker) SyncInvoker(jakarta.ws.rs.client.SyncInvoker) WebTarget(jakarta.ws.rs.client.WebTarget) Client(jakarta.ws.rs.client.Client) ThrottledClient(jaxrs.examples.client.custom.ThrottledClient)

Example 7 with WebTarget

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

the class MultipartClient method sendPdfs.

public boolean sendPdfs(Path dir) throws IOException {
    List<EntityPart> parts = Files.list(dir).map(this::toPart).collect(Collectors.toList());
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:9080/multipart?dirName=abc");
    Entity<List<EntityPart>> entity = Entity.entity(parts, MediaType.MULTIPART_FORM_DATA);
    Response response = target.request().post(entity);
    return response.getStatus() == 200;
}
Also used : Response(jakarta.ws.rs.core.Response) List(java.util.List) WebTarget(jakarta.ws.rs.client.WebTarget) EntityPart(jakarta.ws.rs.core.EntityPart) Client(jakarta.ws.rs.client.Client)

Example 8 with WebTarget

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

the class JAXRSClientIT method buildInvocation.

protected static Invocation buildInvocation(ContextProvider... provider) {
    WebTarget target = buildTarget(provider);
    Invocation i = target.request().buildGet();
    return i;
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget)

Example 9 with WebTarget

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

the class JAXRSClientIT method getAcceptableLanguagesIsImmutableTest.

/*
   * @testName: getAcceptableLanguagesIsImmutableTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:428; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: a read-only list of requested response media types sorted
   * according to their q-value, with highest preference first.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getAcceptableLanguagesIsImmutableTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            List<Locale> locales = context.getAcceptableLanguages();
            try {
                locales.add(Locale.JAPAN);
            } catch (Exception e) {
            // either exception is thrown, or add does nothing
            }
            locales = context.getAcceptableLanguages();
            boolean b = locales.contains(Locale.JAPAN);
            assertTrue(!b, "getAcceptableLanguages is not read-only");
            Response r = Response.ok().build();
            context.abortWith(r);
        }
    };
    WebTarget target = buildTarget(provider);
    Invocation.Builder builder = target.request();
    Invocation invocation;
    invocation = builder.header("Accept-Language", "da, en-gb;q=0.6, en-us;q=0.7").buildGet();
    Response response = invoke(invocation);
    assertStatus(response, Status.OK);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Locale(java.util.Locale) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 10 with WebTarget

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

the class JAXRSClientIT method getClientTest.

/*
   * @testName: getClientTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:430; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the client instance associated with the request.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getClientTest() throws Fault {
    final Client client = ClientBuilder.newClient();
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Client contextClient = context.getClient();
            assertTrue(client == contextClient, "the client instance is different from the context one");
            Response r = Response.ok().build();
            context.abortWith(r);
        }
    };
    client.register(provider);
    WebTarget target = client.target(getUrl());
    Invocation invocation = target.request().buildGet();
    Response response = invoke(invocation);
    assertStatus(response, Status.OK);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) 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) 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