Search in sources :

Example 36 with Cookie

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

the class CookieParamTest method cookieParamHandling.

@GET
public Response cookieParamHandling(@QueryParam("todo") String todo, @CookieParam("name1") @DefaultValue("abc") String value, @DefaultValue("CookieParamTest") @CookieParam("ParamEntityWithConstructor") ParamEntityWithConstructor paramEntityWithConstructor, @DefaultValue("CookieParamTest") @CookieParam("ParamEntityWithFromString") ParamEntityWithFromString paramEntityWithFromString, @DefaultValue("CookieParamTest") @CookieParam("ParamEntityWithValueOf") ParamEntityWithValueOf paramEntityWithValueOf, @DefaultValue("CookieParamTest") @CookieParam("SetParamEntityWithFromString") Set<ParamEntityWithFromString> setParamEntityWithFromString, @DefaultValue("CookieParamTest") @CookieParam("SortedSetParamEntityWithFromString") SortedSet<ParamEntityWithFromString> sortedSetParamEntityWithFromString, @DefaultValue("CookieParamTest") @CookieParam("ListParamEntityWithFromString") List<ParamEntityWithFromString> listParamEntityWithFromString, @CookieParam("ParamEntityThrowingWebApplicationException") ParamEntityThrowingWebApplicationException paramEntityThrowingWebApplicationException, @CookieParam("ParamEntityThrowingExceptionGivenByName") ParamEntityThrowingExceptionGivenByName paramEntityThrowingExceptionGivenByName) {
    sb = new StringBuilder();
    Response.ResponseBuilder respb = Response.status(200);
    if (todo == null) {
        sb.append("todo=null");
    } else if (todo.equalsIgnoreCase("setCookie")) {
        String cookie_name = "name1";
        String cookie_value = "value1";
        Cookie ck = new Cookie(cookie_name, cookie_value);
        NewCookie nck = new NewCookie(ck);
        respb = respb.cookie(nck);
        sb.append("setCookie=done");
    } else if (todo.equalsIgnoreCase("verifycookie")) {
        sb.append("name1" + "=" + value);
        sb.append("verifyCookie=done");
    } else if (todo.equals("")) {
        setReturnValues(paramEntityWithConstructor, paramEntityWithFromString, paramEntityWithValueOf, setParamEntityWithFromString, sortedSetParamEntityWithFromString, listParamEntityWithFromString, "");
        setReturnValues(fieldParamEntityWithConstructor, fieldParamEntityWithFromString, fieldParamEntityWithValueOf, fieldSetParamEntityWithFromString, fieldSortedSetParamEntityWithFromString, fieldListParamEntityWithFromString, FIELD);
    } else if (todo.contains("ParamEntity")) {
        setNewCookie(respb, todo);
        setReturnValues(paramEntityWithConstructor, paramEntityWithFromString, paramEntityWithValueOf, setParamEntityWithFromString, sortedSetParamEntityWithFromString, listParamEntityWithFromString, "");
        setReturnValues(fieldParamEntityWithConstructor, fieldParamEntityWithFromString, fieldParamEntityWithValueOf, fieldSetParamEntityWithFromString, fieldSortedSetParamEntityWithFromString, fieldListParamEntityWithFromString, FIELD);
    } else {
        sb.append("other stuff");
    }
    return respb.entity(sb.toString()).build();
}
Also used : Response(jakarta.ws.rs.core.Response) NewCookie(jakarta.ws.rs.core.NewCookie) Cookie(jakarta.ws.rs.core.Cookie) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) ParamEntityWithFromString(ee.jakarta.tck.ws.rs.ee.rs.ParamEntityWithFromString) NewCookie(jakarta.ws.rs.core.NewCookie) GET(jakarta.ws.rs.GET)

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