Organizational Research By

Surprising Reserch Topic

unable to get cookie at angular js created at server sidejersey


unable to get cookie at angular js created at server sidejersey  using -'javascript,angularjs,cookies,jersey,jax-rs'

I have one cookie which is created at server side(Rest Service).
Below is rest service which creates cookie:

        @Path("token")
        public class AuthService {

        @POST
        @Produces(MediaType.APPLICATION_JSON)
        public Response generateToken(@Context HttpServletRequest httpServletRequest) {

        //some code to get serializedJwt and xsrftoken. path is "/" and domain is "http://localhost"

        Cookie jwtCookie = new Cookie("jwt", serializedJwt, path, domain);
        Cookie xsrfCookie = new Cookie("X-XSRF-TOKEN", xsrfToken, path, domain);

        NewCookie newJwtCookie = new NewCookie(jwtCookie, null, maxAge, false);
        NewCookie newXsrfCookie = new NewCookie(xsrfCookie, null, maxAge, false);

        return Response.status(SUCCESSFUL_REQUEST)
        .header(ERROR_HEADER_NAME, SUCCESS)
        .header("SET-COOKIE", newJwtCookie.toString()+" ; HttpOnly")
        .header("SET-COOKIE", newXsrfCookie.toString())
        .entity(MAPPER.writeValueAsString(responseBody)).build();
        }
        }


Now i am trying to retrive this cookie from angular js(v1.4.6) app.

        console.log($cookies.get("X-XSRF-TOKEN")); //prints undefined
        $cookies.put('abc',"kishore"); //just for testing purpose
        console.log($cookies.get("abc")); //this prints kishore
        console.log(document.cookie); //this prints "abc=kishore"


Note:
httpOnly is false for X-XSRF-TOKEN.
    

asked Oct 6, 2015 by ankitarajoria4
0 votes
6 views



Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

...