Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 21994 invoked from network); 2 Dec 2002 06:15:10 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 Dec 2002 06:15:10 -0000 Received: (qmail 10254 invoked by uid 97); 2 Dec 2002 06:16:18 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 10183 invoked by uid 97); 2 Dec 2002 06:16:17 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 10171 invoked by uid 97); 2 Dec 2002 06:16:16 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 2 Dec 2002 06:14:56 -0000 Message-ID: <20021202061456.10589.qmail@icarus.apache.org> From: jsdever@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient Cookie.java HttpMethodBase.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jsdever 2002/12/01 22:14:56 Modified: httpclient/src/java/org/apache/commons/httpclient Cookie.java HttpMethodBase.java Log: Improve logging for Cookie class. Reduced the amount of output in the logs caused by rejection of an invalid cookie. Changes: 1) I find a full call stack dump is a bit too much for a such a matter as rejected cookie. I took liberty in removing it 2) Invalid cookie is reported only once in the HttpMethodBase class with WARN priority 3) Exception messages are less wordy Contributed by: Oleg Kalnichevski Revision Changes Path 1.28 +138 -147 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java Index: Cookie.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- Cookie.java 29 Nov 2002 19:03:02 -0000 1.27 +++ Cookie.java 2 Dec 2002 06:14:56 -0000 1.28 @@ -807,152 +807,143 @@ defaultPath = path; } - try { - HeaderElement[] headerElements = - HeaderElement.parse(setCookie.getValue()); - - Cookie[] cookies = new Cookie[headerElements.length]; - - int index = 0; - for (int i = 0; i < headerElements.length; i++) { - - HeaderElement headerelement = headerElements[i]; - Cookie cookie = new Cookie(domain, - headerelement.getName(), - headerelement.getValue(), - defaultPath, - null, - false); - - // cycle through the parameters - NameValuePair[] parameters = headerelement.getParameters(); - // could be null. In case only a header element and no parameters. - if (parameters != null) { - - for (int j = 0; j < parameters.length; j++) { - - String param_name = parameters[j].getName().toLowerCase(); - String param_value = parameters[j].getValue(); - - if (param_name.equals("version")) { - - if (param_value == null) { - throw new HttpException("Bad cookie header: missing value for version attribute"); - } - try { - cookie.setVersion(Integer.parseInt(param_value)); - } catch (NumberFormatException e) { - throw new HttpException( "Bad cookie header: invalid version attribute: " + e.getMessage()); - } - - } - else if (param_name.equals("path")) { - - if (param_value == null) { - throw new HttpException("Bad cookie header: missing value for path attribute"); - } - cookie.setPath(param_value); - cookie.setPathAttributeSpecified(true); - - } - else if (param_name.equals("domain")) { - - if (param_value == null) { - throw new HttpException("Bad cookie header: missing value for domain attribute"); - } - cookie.setDomain(param_value); - cookie.setDomainAttributeSpecified(true); - - } - else if (param_name.equals("max-age")) { - - if (param_value == null) { - throw new HttpException("Bad cookie header: missing value for max-age attribute"); - } - int age; + HeaderElement[] headerElements = + HeaderElement.parse(setCookie.getValue()); + + Cookie[] cookies = new Cookie[headerElements.length]; + + int index = 0; + for (int i = 0; i < headerElements.length; i++) { + + HeaderElement headerelement = headerElements[i]; + Cookie cookie = new Cookie(domain, + headerelement.getName(), + headerelement.getValue(), + defaultPath, + null, + false); + + // cycle through the parameters + NameValuePair[] parameters = headerelement.getParameters(); + // could be null. In case only a header element and no parameters. + if (parameters != null) { + + for (int j = 0; j < parameters.length; j++) { + + String param_name = parameters[j].getName().toLowerCase(); + String param_value = parameters[j].getValue(); + + if (param_name.equals("version")) { + + if (param_value == null) { + throw new HttpException("Missing value for version attribute"); + } + try { + cookie.setVersion(Integer.parseInt(param_value)); + } catch (NumberFormatException e) { + throw new HttpException( "Invalid version attribute: " + e.getMessage()); + } + + } + else if (param_name.equals("path")) { + + if (param_value == null) { + throw new HttpException("Missing value for path attribute"); + } + cookie.setPath(param_value); + cookie.setPathAttributeSpecified(true); + + } + else if (param_name.equals("domain")) { + + if (param_value == null) { + throw new HttpException("Missing value for domain attribute"); + } + cookie.setDomain(param_value); + cookie.setDomainAttributeSpecified(true); + + } + else if (param_name.equals("max-age")) { + + if (param_value == null) { + throw new HttpException("Missing value for max-age attribute"); + } + int age; + try { + age = Integer.parseInt(param_value); + } catch (NumberFormatException e) { + throw new HttpException( "Invalid max-age attribute: " + e.getMessage()); + } + cookie.setExpiryDate(new Date(System.currentTimeMillis() + + age * 1000L)); + + } + else if (param_name.equals("secure")) { + + cookie.setSecure(true); + + } + else if (param_name.equals("comment")) { + + cookie.setComment(param_value); + + } + else if (param_name.equals("expires")) { + + if (param_value == null) { + throw new HttpException("Missing value for expires attribute"); + } + boolean set = false; + // trim single quotes around expiry if present + // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5279 + if(param_value.length() > 1 && + param_value.startsWith("'") && + param_value.endsWith("'")) { + param_value = param_value.substring(1,param_value.length()-1); + } + + for(int k=0;k 1 && - param_value.startsWith("'") && - param_value.endsWith("'")) { - param_value = param_value.substring(1,param_value.length()-1); - } - - for(int k=0;k For additional commands, e-mail: