Search in sources :

Example 76 with WebTarget

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

the class JAXRSClientIT method getConfigurationTest.

/*
   * @testName: getConfigurationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:977; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the immutable configuration of the request.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getConfigurationTest() throws Fault {
    final Client client = ClientBuilder.newClient();
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Client contextClient = context.getClient();
            assertEquals(contextClient, client, "the client instance is different from the context one");
            Configuration contextConfig = context.getConfiguration();
            assertNotNull(contextConfig, "context.getConfiguration() returned null");
            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) Configuration(jakarta.ws.rs.core.Configuration) 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)

Example 77 with WebTarget

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

the class JAXRSClientIT method setEntityTest.

/*
   * @testName: setEntityTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:450; JAXRS:JAVADOC:434; JAXRS:JAVADOC:435;
   * JAXRS:JAVADOC:438; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456; JAXRS:SPEC:85;
   * 
   * @test_Strategy: Set a new response message entity. It is the callers
   * responsibility to wrap the actual entity with
   * jakarta.ws.rs.core.GenericEntity if preservation of its generic type is
   * required.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void setEntityTest() throws Fault {
    final AtomicInteger counter = new AtomicInteger(0);
    ContextProvider provider = new SetEntityProvider(counter);
    ContextProvider provider2 = new SetEntityProvider(counter) {
    };
    Entity<ByteArrayInputStream> entity = createEntity(new ByteArrayInputStream("test".getBytes()));
    WebTarget target = buildTarget(provider, provider2);
    Invocation invocation = target.request().buildPost(entity);
    Response response = invoke(invocation);
    assertStatus(response, Status.OK);
}
Also used : Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 78 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(ClientRequestFilter requestFilter, ContextProvider... provider) {
    WebTarget target = buildTarget(requestFilter, provider);
    Invocation i = target.request().buildGet();
    return i;
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget)

Example 79 with WebTarget

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

the class MultipartClient method retrievePdfs.

public List<Path> retrievePdfs(String remoteDirName) throws IOException {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:9080/multipart").queryParam("dirName", remoteDirName);
    Response response = target.request(MediaType.MULTIPART_FORM_DATA).get();
    List<EntityPart> parts = response.readEntity(new GenericType<List<EntityPart>>() {
    });
    return parts.stream().map(part -> {
        try (InputStream is = part.getContent()) {
            Path file = Files.createFile(Paths.get(part.getFileName().orElse(part.getName() + ".pdf")));
            Files.copy(is, file);
            return file;
        } catch (IOException ioex) {
            LOG.log(Level.WARNING, "Failed to process attachment part {0}", part);
            return null;
        }
    }).collect(Collectors.toList());
}
Also used : Response(jakarta.ws.rs.core.Response) Client(jakarta.ws.rs.client.Client) Files(java.nio.file.Files) EntityPart(jakarta.ws.rs.core.EntityPart) WebTarget(jakarta.ws.rs.client.WebTarget) IOException(java.io.IOException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Level(java.util.logging.Level) Entity(jakarta.ws.rs.client.Entity) GenericType(jakarta.ws.rs.core.GenericType) List(java.util.List) Response(jakarta.ws.rs.core.Response) MediaType(jakarta.ws.rs.core.MediaType) Paths(java.nio.file.Paths) Path(java.nio.file.Path) InputStream(java.io.InputStream) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) Path(java.nio.file.Path) InputStream(java.io.InputStream) List(java.util.List) WebTarget(jakarta.ws.rs.client.WebTarget) IOException(java.io.IOException) Client(jakarta.ws.rs.client.Client) EntityPart(jakarta.ws.rs.core.EntityPart)

Example 80 with WebTarget

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

the class JAXRSClientIT method createSyncInvokerForMethod.

/**
 * Create SyncInvoker for given resource method and start time
 */
protected SyncInvoker createSyncInvokerForMethod(String methodName) {
    Client client = ClientBuilder.newClient();
    client.register(new JdkLoggingFilter(false));
    WebTarget target = client.target(getUrl(methodName));
    SyncInvoker sync = target.request();
    return sync;
}
Also used : JdkLoggingFilter(ee.jakarta.tck.ws.rs.common.client.JdkLoggingFilter) SyncInvoker(jakarta.ws.rs.client.SyncInvoker) WebTarget(jakarta.ws.rs.client.WebTarget) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client)

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