Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.Collections$UnmodifiableRandomAccessList to Collections.singletonList

How to I convert a java.util.Collections$UnmodifiableRandomAccessList to a Collections.singletonList? In a attempt to store session between two services, i found this, but I cant figure out the step in between. First get the cookie info that i need to set:

Map<String, Collections> headerInfo = (Map<String, Collections>)
 ((BindingProvider) port).getResponseContext()
                         .get(MessageContext.HTTP_RESPONSE_HEADERS);

Now I can get the cookie info i need; If I do a

System.out.println(headerInfo.get("Set-Cookie"));

I get something like this

Set-Cookie=[PHPSESSID=rpsnc2g7o4ltbr6l9qus177p14; path=/];

Now I just need to do this:

((BindingProvider) port2).getRequestContext()
   .put(MessageContext.HTTP_REQUEST_HEADERS, 
      Collections.singletonMap("Cookie", Collections.singletonList(cookieValue)));

But I can not figure out how to get from headerInfo.get("Set-Cookie") to: cookieValue

This is the question I found the first part of my problems solution in Q:
JAX-WS client: maintain session/cookies across multiple services
(It might explain my problem a bit too)

like image 522
Steffen Avatar asked Dec 29 '25 23:12

Steffen


1 Answers

The solution was to use the original list by casting to the correct class/interface:

List<String>

instead of:

Collections

worked.

Map<String, List<String>> headers = (Map<String, List<String>>)((BindingProvider) authPort).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
List<String> setCookie = (List<String>) headers.get("Set-Cookie");
((BindingProvider) servicePort).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,Collections.singletonMap("Cookie", setCookie ));
like image 109
Steffen Avatar answered Dec 31 '25 12:12

Steffen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!