How can I get hold of a value of a particular cookie from list of cookies. Below is how I am trying:
Map<String, List<String>> map = (Map<String,
List<String>>) context.get(MessageContext.HTTP_RESPONSE_HEADERS);
List<String> contentType = getHTTPHeader(map);
if (contentType != null) {
StringBuffer strBuf = new StringBuffer();
for (String type : contentType) {
strBuf.append(type);
}
System.out.println("Content-Type:" + strBuf.toString());
}
List<String> cookies = map.get("Set-Cookie");
if (cookies != null) {
System.out.println("cookies != null");
StringBuffer strBuf = new StringBuffer();
for (String type : cookies) {
System.out.println(" Looping cookie ");
strBuf.append(type);
}
System.out.println("Cookie:" + strBuf.toString());
}else{
System.out.println("cookies == null");
}
I get following results and I want to get hold of value for "JSESSIONID"
Cookie:JSESSIONID=88E53DE2E78TRE86E1C2B021BA240B; Path=/us-webservice
Thanks.
cookie.substring(cookie.indexOf(':'), cookie.indexOf(';')).split("=")[1]
or if you want regular expressions
Pattern p = Pattern.compile( "JSESSIONID=([A-Z0-9]+)");
Matcher m = p.matcher(cookie);
m.find();
m.group(1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.