Search in sources :

Example 41 with WebTarget

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

the class JAXRSClientIT method startAsyncInvokerForMethod.

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

Example 42 with WebTarget

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

the class JaxrsWebTestCase method execute.

/**
 * Executes the test case.
 *
 * @throws TestFailureException
 *           if the test fails for any reason.
 * @throws IllegalStateException
 *           if no request was configured or if no Validator is available at
 *           runtime.
 */
public void execute() throws TestFailureException {
    verifyValidationStrategy();
    verifySettings();
    try {
        String url = logClientRequestAndGetUrl();
        client = getClientWithRegisteredProviders();
        WebTarget target = client.target(url.toString());
        Invocation i = buildRequest(target);
        response = invoke(i);
        if (bufferEntity)
            response.bufferEntity();
    } catch (Throwable t) {
        String message = t.getMessage();
        StringBuilder sb = new StringBuilder();
        sb.append("[FATAL] Unexpected failure during test execution.\n");
        // print client call code to report into JIRA when needed
        sb.append(printClientCall().toString());
        // Inherited message
        sb.append((message == null ? t.toString() : message));
        throw new TestFailureException(sb.toString(), t);
    }
    // Validate this test case instance
    if (!strategy.validate(this)) {
        throw new TestFailureException("Test FAILED!");
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) TestFailureException(ee.jakarta.tck.ws.rs.common.webclient.TestFailureException)

Example 43 with WebTarget

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

the class BasicExamples method creatingResourceAndSubResourceUris.

public void creatingResourceAndSubResourceUris() {
    // Target( http://jaxrs.examples.org/jaxrsApplication/customers/ )
    WebTarget customersUri = ClientBuilder.newClient().target("http://jaxrs.examples.org/jaxrsApplication/customers");
    // Target( http://jaxrs.examples.org/jaxrsApplication/customers/{id}/ )
    WebTarget anyCustomerUri = customersUri.path("{id}");
    // Target( http://jaxrs.examples.org/jaxrsApplication/customers/123/ )
    WebTarget customer123 = anyCustomerUri.resolveTemplate("id", 123);
    assert customer123 != null;
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget)

Example 44 with WebTarget

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

the class CacheExample method cacheExample.

public void cacheExample() {
    Client client = ClientBuilder.newClient();
    client.register(CachingFeature.class);
    WebTarget resource = client.target("http://example.com/foo/bar.txt");
    String text = resource.request("text/plain").get(String.class);
    String second = resource.request("text/plain").get(String.class);
    System.out.println(text);
    System.out.println(second);
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) Client(jakarta.ws.rs.client.Client)

Example 45 with WebTarget

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

the class GzipExample method gzipExample.

public void gzipExample() {
    WebTarget target = ClientBuilder.newClient().target("http://example.com/foo/bar.txt");
    target.register(GzipEntityInterceptor.class);
    // getting a gzip encoded body
    String body = target.request("text/plain").get(String.class);
    // send a gzip encoded body
    target.request().header("Content-Encoding", "gzip").post(text(body));
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget)

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