utils: add findCookie value by key helping method in HttpUtils finds cookie value from an array of cookie by key name
Signed-off-by: Rohit Yadav <[email protected]> (cherry picked from commit 78ea36d099371b9a59cbf1e3efd48b853ecc37ca) Signed-off-by: Rohit Yadav <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7ae9f87d Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7ae9f87d Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7ae9f87d Branch: refs/heads/master Commit: 7ae9f87d59b8d45f7dbadcf5b0819e62976a9ff9 Parents: 0c8c089 Author: Rohit Yadav <[email protected]> Authored: Fri May 29 15:27:31 2015 +0200 Committer: Rohit Yadav <[email protected]> Committed: Fri May 29 15:41:59 2015 +0200 ---------------------------------------------------------------------- utils/src/com/cloud/utils/HttpUtils.java | 10 ++++++++++ 1 file changed, 10 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ae9f87d/utils/src/com/cloud/utils/HttpUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/HttpUtils.java b/utils/src/com/cloud/utils/HttpUtils.java index 58768dc..2940985 100644 --- a/utils/src/com/cloud/utils/HttpUtils.java +++ b/utils/src/com/cloud/utils/HttpUtils.java @@ -21,6 +21,7 @@ package com.cloud.utils; import org.apache.log4j.Logger; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -49,6 +50,15 @@ public class HttpUtils { } } + public static String findCookie(final Cookie[] cookies, final String key) { + for (Cookie cookie: cookies) { + if (cookie != null && cookie.getName().equals(key)) { + return cookie.getValue(); + } + } + return null; + } + public static void writeHttpResponse(final HttpServletResponse resp, final String response, final Integer responseCode, final String responseType, final String jsonContentType) { try {
