java.util.Collections$UnmodifiableRandomAccessList 到 Collections.singletonList
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20462819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.util.Collections$UnmodifiableRandomAccessList to Collections.singletonList
提问by Steffen
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:
如何将 a 转换java.util.Collections$UnmodifiableRandomAccessList
为 a Collections.singletonList
?在尝试存储两个服务之间的会话时,我发现了这一点,但我无法弄清楚两者之间的步骤。首先获取我需要设置的cookie信息:
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
现在我可以得到我需要的 cookie 信息;如果我做一个
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
但我不知道如何从
headerInfo.get("Set-Cookie")
到: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)
这是我在 Q:
JAX-WS 客户端:跨多个服务维护会话/cookies 中找到我的问题解决方案的第一部分的问题
(这可能也解释了我的问题)
采纳答案by Steffen
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 ));