ServletUtil { public static String extractCookie(final HttpServletRequest request, final String name) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie.getValue(); } } } return null; } private  ServletUtil(); static boolean isEnableSubSessions(); static boolean checkResourceRequest(final HttpServletRequest request,
			final HttpServletResponse response); static void processRequest(final HttpServletHelper helper, final WComponent ui,
			final InterceptorComponent interceptorChain); static boolean isStaticResourceRequest(final HttpServletRequest req); static void handleStaticResourceRequest(final HttpServletRequest request,
			final HttpServletResponse response); static boolean isThemeResourceRequest(final HttpServletRequest req); static void handleThemeResourceRequest(final HttpServletRequest req,
			final HttpServletResponse resp); static InterceptorComponent createInterceptorChain(final HttpServletRequest request); static void handleError(final HttpServletHelper helper, final Throwable throwable); static boolean isMultipart(final HttpServletRequest request); static Map<String, String[]> getRequestParameters(final HttpServletRequest request); static String getRequestParameterValue(final HttpServletRequest request, final String key); static String[] getRequestParameterValues(final HttpServletRequest request, final String key); static Map<String, FileItem[]> getRequestFileItems(final HttpServletRequest request); static FileItem getRequestFileItemValue(final HttpServletRequest request, final String key); static FileItem[] getRequestFileItemValues(final HttpServletRequest request, final String key); static void setupRequestParameters(final HttpServletRequest request); static void extractParameterMap(final HttpServletRequest request, final Map<String, String[]> parameters,
			final Map<String, FileItem[]> files); static String extractCookie(final HttpServletRequest request, final String name); static void uploadFileItems(final List<FileItem> fileItems, final Map<String, String[]> parameters,
			final Map<String, FileItem[]> files); static DeviceType getDevice(final HttpServletRequest request); static DeviceType getDevice(final Request request);  }
@Test public void testExtractCookie() { String cookieName = "mycookiename"; String cookieValue = "mycookievalue"; MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); httpServletRequest.setCookie(cookieName, cookieValue); Assert.assertEquals("Got cookie value by name", cookieValue, ServletUtil.extractCookie(httpServletRequest, cookieName)); }
@Test public void testExtractCookieAmongstMany() { String cookieName = "mycookiename"; String cookieValue = "mycookievalue"; MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); for (byte i = 0; i < 10; i++) { httpServletRequest.setCookie(cookieName + i, cookieValue + 1); } httpServletRequest.setCookie(cookieName, cookieValue); Assert.assertEquals("Got cookie value by name", cookieValue, ServletUtil.extractCookie(httpServletRequest, cookieName)); }
@Test public void testExtractCookieNoneFound() { String cookieName = "mycookiename"; MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); Assert.assertNull("Got cookie value by name", ServletUtil.extractCookie(httpServletRequest, cookieName)); }