Search in sources :

Example 1 with Cookie

use of jakarta.ws.rs.core.Cookie in project jaxrs-api by eclipse-ee4j.

the class BasicExamples method asyncCallbackUsingSubResourceClient.

public void asyncCallbackUsingSubResourceClient() throws Exception {
    final Client client = ClientBuilder.newClient();
    WebTarget anyCustomerUri = client.target("http://jaxrs.examples.org/jaxrsApplication/customers/{id}");
    // invoke a request in background
    Future<Customer> handle = // Target
    anyCustomerUri.resolveTemplate("id", 123).request().async().get(new InvocationCallback<Customer>() {

        @Override
        public void completed(Customer customer) {
        // do something
        }

        @Override
        public void failed(Throwable throwable) {
        // do something
        }
    });
    handle.cancel(true);
    // invoke another request in background
    // Target
    anyCustomerUri.resolveTemplate("id", 456).request().async().get(new InvocationCallback<Response>() {

        @Override
        public void completed(Response customer) {
        // do something
        }

        @Override
        public void failed(Throwable throwable) {
        // do something
        }
    });
    // invoke one more request using newClient
    Future<Response> response = anyCustomerUri.resolveTemplate("id", 789).request().cookie(new Cookie("fooName", "XYZ")).async().get();
    assert response.get() != null;
}
Also used : Response(jakarta.ws.rs.core.Response) Cookie(jakarta.ws.rs.core.Cookie) WebTarget(jakarta.ws.rs.client.WebTarget) Client(jakarta.ws.rs.client.Client) ThrottledClient(jaxrs.examples.client.custom.ThrottledClient)

Example 2 with Cookie

use of jakarta.ws.rs.core.Cookie in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getCookiesTest.

/*
   * @testName: getCookiesTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:432; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get any cookies that accompanied the request. Returns a
   * read-only map of cookie name (String) to Cookie.
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getCookiesTest() throws Fault {
    Cookie cts = new Cookie("cts", "cts");
    Cookie tck = new Cookie("tck", "tck");
    Cookie jee = new Cookie("jee", "jee");
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            String cookies = JaxrsUtil.iterableToString(";", context.getCookies().values());
            Response r = Response.ok(cookies).build();
            context.abortWith(r);
        }
    };
    Invocation invocation = buildBuilder(provider).cookie(cts).cookie(tck).cookie(jee).buildGet();
    Response response = invoke(invocation);
    String entity = response.readEntity(String.class);
    assertContains(entity, "cts");
    assertContains(entity, "tck");
    assertContains(entity, "jee");
}
Also used : Cookie(jakarta.ws.rs.core.Cookie) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) Test(org.junit.jupiter.api.Test)

Example 3 with Cookie

use of jakarta.ws.rs.core.Cookie in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method constructorTest5.

/*
     * @testName: constructorTest5
     * 
     * @assertion_ids: JAXRS:JAVADOC:49; JAXRS:JAVADOC:53; JAXRS:JAVADOC:54;
     * JAXRS:JAVADOC:55; JAXRS:JAVADOC:56; JAXRS:JAVADOC:57;
     * 
     * @test_Strategy: Create a version 0 Cookie instance using Constructor
     * Cookie(String, String, String, String, int)
     */
@Test
public void constructorTest5() throws Fault {
    String name = "name_1";
    String value = "value_1";
    String path = "/acme";
    String domain = "y.x.foo.com";
    int version = 0;
    Cookie ck5 = new Cookie(name, value, path, domain, version);
    verifyCookie(ck5, name, value, path, domain, version);
}
Also used : Cookie(jakarta.ws.rs.core.Cookie) Test(org.junit.jupiter.api.Test)

Example 4 with Cookie

use of jakarta.ws.rs.core.Cookie in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method constructorTest2.

/*
     * @testName: constructorTest2
     * 
     * @assertion_ids: JAXRS:JAVADOC:50; JAXRS:JAVADOC:53; JAXRS:JAVADOC:54;
     * JAXRS:JAVADOC:55; JAXRS:JAVADOC:56; JAXRS:JAVADOC:57;
     * 
     * @test_Strategy: Create a Cookie instance using Constructor Cookie(String,
     * String, String, String)
     */
@Test
public void constructorTest2() throws Fault {
    String name = "name_1";
    String value = "value_1";
    String path = "/acme";
    String domain = "";
    int version = 1;
    Cookie ck2 = new Cookie(name, value, path, domain);
    verifyCookie(ck2, name, value, path, domain, version);
}
Also used : Cookie(jakarta.ws.rs.core.Cookie) Test(org.junit.jupiter.api.Test)

Example 5 with Cookie

use of jakarta.ws.rs.core.Cookie in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method constructorTest3.

/*
     * @testName: constructorTest3
     * 
     * @assertion_ids: JAXRS:JAVADOC:50; JAXRS:JAVADOC:53; JAXRS:JAVADOC:54;
     * JAXRS:JAVADOC:55; JAXRS:JAVADOC:56; JAXRS:JAVADOC:57;
     * 
     * @test_Strategy: Create a Cookie instance using Constructor Cookie(String,
     * String, String, String)
     */
@Test
public void constructorTest3() throws Fault {
    String name = "name_1";
    String value = "value_1";
    String path = "";
    String domain = "y.x.foo.com";
    int version = 1;
    Cookie ck3 = new Cookie(name, value, path, domain);
    verifyCookie(ck3, name, value, path, domain, version);
}
Also used : Cookie(jakarta.ws.rs.core.Cookie) Test(org.junit.jupiter.api.Test)

Aggregations

Cookie (jakarta.ws.rs.core.Cookie)36 Test (org.junit.jupiter.api.Test)31 NewCookie (jakarta.ws.rs.core.NewCookie)21 Response (jakarta.ws.rs.core.Response)7 Invocation (jakarta.ws.rs.client.Invocation)3 ParamEntityWithFromString (ee.jakarta.tck.ws.rs.ee.rs.ParamEntityWithFromString)2 GET (jakarta.ws.rs.GET)2 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)2 Path (jakarta.ws.rs.Path)1 Client (jakarta.ws.rs.client.Client)1 WebTarget (jakarta.ws.rs.client.WebTarget)1 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ThrottledClient (jaxrs.examples.client.custom.ThrottledClient)1