Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@RequiresCookie / @SetsCookie #1771

@marcbiaggini

Description

@marcbiaggini

Hi Everyone, I would like to understand a little bit more about this annotations. My specific case is related to requires and sets Cookies annotations. I´ve created my Interface as below:

@Rest(rootUrl = "http://myURL/api/myaccount", converters = { MappingJackson2HttpMessageConverter.class , FormHttpMessageConverter.class})
public interface MyAccount extends RestClientErrorHandling {

  @Get("/get")
  @RequiresCookie({"_aecp_dev","_aecp_dev_user"})
  UserResponse getMyAccountInfo();

  @Get("/get_user")
  @RequiresCookie({"_aecp_dev","_aecp_dev_user"})
  UserResponse getUserInfo();

  @Post("/login")
  @Headers(@Header(name ="Content-Type", value="application/x-www-form-urlencoded"))
  @SetsCookie({"_aecp_dev","_aecp_dev_user"})
  GenericResponse logIn(@Body MultiValueMap formParams);

void setCookie(String name, String value);
  String getCookie(String name);
}

Basically my problem comes when I´m trying to call the login Mehod, it supposed that once that it was called, this mothod must to set those cookies "_aecp_dev" and "_aecp_dev_user". But instead, the cookie with the key "_aecp_dev" is getting set with the value of the key "aecp_dev_user", due to in the MyAccount generated class exist this function inside logIn mehod:

 List<String> allCookies = response.getHeaders().get("Set-Cookie");

 if (allCookies!= null) {

    for (String rawCookie: allCookies) {
                    for (String thisCookieName: requestedCookies) {
                     /***In this line is were the problem appears cuz both keys start with the same name***/
                        if (rawCookie.startsWith(thisCookieName)) {
                            int valueEnd = rawCookie.indexOf(';');
                            if (valueEnd == -1) {
                                valueEnd = rawCookie.length();
                            }
                            availableCookies.put(thisCookieName, rawCookie.substring((rawCookie.indexOf("=")+ 1), valueEnd));
                            break;
                        }
                    }
                }

Any ideas? what I´m doing worng?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions