Search in sources :

Example 46 with NewCookie

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

the class ResponseTest method getHeaders.

@POST
@Path("headers")
public Response getHeaders(String headers) {
    CacheControl ccl = new CacheControl();
    NewCookie cookie = new NewCookie("cookie", "eikooc");
    String encoding = "gzip";
    Date date = Calendar.getInstance().getTime();
    ResponseBuilder builder = Response.ok();
    if (headers != null && headers.length() != 0) {
        builder = builder.cacheControl(ccl).cookie(cookie).encoding(encoding).expires(date).language(Locale.CANADA_FRENCH);
    }
    return builder.build();
}
Also used : CacheControl(jakarta.ws.rs.core.CacheControl) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Date(java.util.Date) NewCookie(jakarta.ws.rs.core.NewCookie) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 47 with NewCookie

use of jakarta.ws.rs.core.NewCookie 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)

Example 48 with NewCookie

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

the class Resource method getCookies.

@Path("getcookies")
@GET
public Response getCookies() {
    NewCookie cookie = new NewCookie(ResponseFilter.COOKIENAME, ResponseFilter.COOKIENAME);
    ResponseBuilder builder = createResponseWithHeader();
    Response response = builder.cookie(cookie).build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) NewCookie(jakarta.ws.rs.core.NewCookie) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Aggregations

NewCookie (jakarta.ws.rs.core.NewCookie)48 Test (org.junit.jupiter.api.Test)41 Cookie (jakarta.ws.rs.core.Cookie)20 Response (jakarta.ws.rs.core.Response)13 Path (jakarta.ws.rs.Path)4 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)4 GET (jakarta.ws.rs.GET)3 CacheControl (jakarta.ws.rs.core.CacheControl)3 Date (java.util.Date)3 ParamEntityWithFromString (ee.jakarta.tck.ws.rs.ee.rs.ParamEntityWithFromString)2 POST (jakarta.ws.rs.POST)2 IOException (java.io.IOException)2 Consumes (jakarta.ws.rs.Consumes)1 ProcessingException (jakarta.ws.rs.ProcessingException)1 Produces (jakarta.ws.rs.Produces)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 URISyntaxException (java.net.URISyntaxException)1