I have a WebClient that sends a JSON object with login credentials to a remote server. The remote server then returns the cookie. After which I need to POST data to that remote server along with the cookie. However, I cannot work out how re-use the cookie within the POST.
As far as I can tell, the login response gives the following structure MultiValueMap<String, ResponseCookie>
, however the code to set the cookie on the POST requires MultiValueMap<String, String>
or just cookie(String, String)
.
I assume that I must be missing some converter magic, but what? Do I even need return the whole cookie?
The cookie looks like this:
{SSO_Sticky_Session-47873-loadBalancedAdminGrp=[SSO_Sticky_Session-47873-loadBalancedAdminGrp=BNAMAKAKJABP; Path=/; HttpOnly], AUTH_TOKEN=[AUTH_TOKEN=v0l3baVZejIKjdzA1KGpkz4ccnosE6rKLQig1D2bdb-voFmVrF_aaYgzWl3Yc8QK; Path=/], uid=[uid=sjzipQdBtU30OlVbPWtDK2625i24i6t6g3Rjl5y5XcI=; Path=/], __cfduid=[__cfduid=dd872f39fd1d3bfe2a5c7316cd9ff63cd1554623603; Path=/; Domain=.aDomain.net; Max-Age=31535999; Expires=Mon, 6 Apr 2020 07:53:23 GMT; HttpOnly], JSESSIONID=[JSESSIONID=A264A713AD060EE12DA8215AEF66A3C0; Path=/aPath/; HttpOnly]}
My code is below. I have removed content type for brevity;
WebClient webClient = WebClient.create("https://remoteServer");
MultiValueMap<String, ResponseCookie> myCookies;
webClient
.post()
.uri("uri/login")
.body(Mono.just(myLoginObject), MyLogin.class)
.exchange()
.subscribe(r ->
System.err.println("Received:" + r.cookies());
myCookies = r.cookies();
);
webClient
.post()
.uri("/uri/data")
.cookies(????) // what goes here ??
.body(....)
.exchange();