Return-Path: Delivered-To: apmail-jakarta-jmeter-dev-archive@jakarta.apache.org Received: (qmail 15002 invoked by uid 500); 7 Jun 2001 21:36:10 -0000 Mailing-List: contact jmeter-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: jmeter-dev@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list jmeter-dev@jakarta.apache.org Received: (qmail 14825 invoked from network); 7 Jun 2001 21:36:06 -0000 From: tusharbhatia@discoverfinancial.com Subject: Data problems in URL arguments To: jmeter-dev@jakarta.apache.org X-Mailer: Lotus Notes Release 5.0.3 (Intl) 21 March 2000 Message-ID: Date: Thu, 7 Jun 2001 16:31:05 -0500 X-MIMETrack: Serialize by Router on DCDALM09/DFSI(Release 5.0.2c (Intl)|2 February 2000) at 06/07/2001 04:31:21 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N Hi, If the URL Config arguments (POST or GET parameters) contain characters that are not accepted by xml (such as <, >, &, quote and apostrophe), then saving/ reading these arguments leads to exceptions. The following changes were required (code is included ahead) to take care of this situation. 1) A class XMLDataConverter was created that converted all strings to a format acceptable by xml. Similar classes can be found in xerces and other xml parsers/engines but I wasn't sure if we should create dependencies on these. 2) ArgumentHandler.writeArgument is modified appropriately such that the above class is invoked when the arguments are being saved. 3) ArgumentHandler.argument(String) is modified to manage the handling of xml tags. Please refer to the comments in the code that try to explain why changes were needed to this method. thanks Tushar ============================================================= New file: org.apache.jmeter.util.XMLDataHandler package org.apache.jmeter.util; /** * Converts string data to xml by removing all non-xml characters and replacing them with * appropriate XML types. * @author: Tushar Bhatia */ public class XMLDataConverter { private static String TOKENS = "&'\"<>\n\r\t\f\b\\"; /** Converts a string to the XML format. Removes quote, apostrophe, less than, greater than and ampersand characters and substitutes with the appropriate xml replacements. */ public static String convertToXML(String input){ if(input == null) return null; String retVal = ""; StringBuffer buffer = new StringBuffer(input); int length = buffer.length(); for(int i = 0; i < length; i++){ char ch = buffer.charAt(i); int chInt = (int)ch; if(Character.isLetterOrDigit(ch) || ch=='\n' || ch=='\r' || ch=='\t' || ch==' ') continue; int chType = Character.getType(ch); if(chType == Character.CONTROL || chType == Character.UNASSIGNED) buffer.setCharAt(i, ' '); } input = buffer.toString(); java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(input, TOKENS, true); while(tokenizer.hasMoreTokens()) { String nextToken = tokenizer.nextToken(); length = nextToken.length(); if(length > 1) retVal += nextToken; else if(length == 1){ // could be a delimiter char ch = nextToken.charAt(0); switch(ch) { case '&': retVal += "&"; break; case '\'': retVal += "'"; break; case '"': retVal += """; break; case '<': retVal += "<"; break; case '>': retVal += ">"; break; case '\n': case '\r': case '\t': case '\f': case '\b': case '\\': retVal += "&#" + (int)ch + ";"; break; default: retVal += nextToken; } } } return retVal; } } ================================================= changes to ArgumentHandler.java Index: ./src/org/apache/jmeter/save/handlers/ArgumentsHandler.java =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/org/apache/jmeter/save/handlers/ArgumentsHandler.java,v retrieving revision 1.4 diff -r1.4 ArgumentsHandler.java 77a78,83 > > /** set to true each time a new Argument starts. > @see argument(java.lang.String) for an explanation of this variable. > */ > private boolean newArgumentStarted = false; > 102c108,111 < out.write(arg.getValue().toString()); --- > String value = arg.getValue().toString(); > if(value != null) > value = org.apache.jmeter.util.XMLDataConverter.convertToXML(value.toString()); > out.write((value != null)?value:""); 123a133,134 > currentArgument = currentArgument.trim(); > newArgumentStarted = true; 125c136,143 < --- > > /** This method is invoked each time there are arguments (not attributes) for > any xml tag. eg. Argument Data contains one attribute > and the argument 'Argument Data'. > This works ok as long as 'Argument Data' contains no special xml characters such as < or > etc. > If it does and the argument was '5<6' (i.e 5 is less than 6), the method would be invoked > 3 times with data being (5, <, 6). Changes in this method take care of this situation. > */ 132,133c150,168 < args.addArgument(currentArgument,data); < currentArgument = null; --- > if(newArgumentStarted == false) { > // we already have visited this function for the sameCurrentArgument > // this may be the 2nd (3rd,..) call to this method for the same currentArgument. > // We have to get the data already stored against the > // currentArgument and append the new data to it > String oldData = (String)args.getValueAt(args.getRowCount() - 1, 1); > args.setValueAt(oldData + data, args.getRowCount() - 1, 1); > } > else > args.addArgument(currentArgument,data); > // because if there are multiple parts to the CDATA in one argument eg. <abcd> > // there would be three calls to this method. > if(newArgumentStarted == true) { > currentArgument = null; // we will not need it again > newArgumentStarted = false; // this is no longer new. > } > > //args.addArgument(currentArgument,data); > //currentArgument = null; --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org