List of usage examples for org.apache.commons.httpclient.cookie MalformedCookieException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.apache.jmeter.protocol.http.control.CookieManager.java
public void addCookieFromHeader(String cookieHeader, URL url) { boolean debugEnabled = log.isDebugEnabled(); if (debugEnabled) { log.debug("Received Cookie: " + cookieHeader + " From: " + url.toExternalForm()); }//from w w w .j a v a2 s . c o m String protocol = url.getProtocol(); String host = url.getHost(); int port = HTTPSamplerBase.getDefaultPort(protocol, url.getPort()); String path = url.getPath(); boolean isSecure = HTTPSamplerBase.isSecure(protocol); org.apache.commons.httpclient.Cookie[] cookies = null; try { cookies = cookieSpec.parse(host, port, path, isSecure, cookieHeader); } catch (MalformedCookieException e) { log.warn(cookieHeader + e.getLocalizedMessage()); } catch (IllegalArgumentException e) { log.warn(cookieHeader + e.getLocalizedMessage()); } if (cookies == null) { return; } for (int i = 0; i < cookies.length; i++) { org.apache.commons.httpclient.Cookie cookie = cookies[i]; try { if (CHECK_COOKIES) { cookieSpec.validate(host, port, path, isSecure, cookie); } Date expiryDate = cookie.getExpiryDate(); long exp = 0; if (expiryDate != null) { exp = expiryDate.getTime(); } Cookie newCookie = new Cookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getSecure(), exp / 1000, cookie.isPathAttributeSpecified(), cookie.isDomainAttributeSpecified()); // Store session cookies as well as unexpired ones if (exp == 0 || exp >= System.currentTimeMillis()) { newCookie.setVersion(cookie.getVersion()); add(newCookie); // Has its own debug log; removes matching cookies } else { removeMatchingCookies(newCookie); if (debugEnabled) { log.debug("Dropping expired Cookie: " + newCookie.toString()); } } } catch (MalformedCookieException e) { // This means the cookie was wrong for the URL log.debug("Not storing invalid cookie: <" + cookieHeader + "> for URL " + url + " (" + e.getLocalizedMessage() + ")"); } catch (IllegalArgumentException e) { log.warn(cookieHeader + e.getLocalizedMessage()); } } }