4 messages in com.canoo.lists.webtestRe[2]: [Webtest] Request/response enc...
FromSent OnAttachments
Marek Mosiewicz16 Aug 2004 01:20 
Paul King16 Aug 2004 14:41 
ilfrin16 Aug 2004 23:51 
ilfrin23 Aug 2004 10:17 
Subject:Re[2]: [Webtest] Request/response encoding problem
From:ilfrin (ilf@poczta.onet.pl)
Date:08/23/2004 10:17:13 AM
List:com.canoo.lists.webtest

Hi Paul,

ok, problem solved ..

PK> You can change the character set used for encoding as follows:

PK> <config ...> PK> <option name="DefaultCharacterSet" value="ISO-8859-2"/> PK> </config>

no, this does NOTHING .. the reason why is this code fragment from

com.canoo.webtest.steps.request.Target.java:

... private boolean tryCallingMethod(Header option, Class optionClass) { Class[] booleanClass = {boolean.class}; Object[] booleanObject = {new
Boolean("true".equalsIgnoreCase(option.getValue()))}; try { Method method = optionClass.getDeclaredMethod("set" + option.getName(),
booleanClass); if (method != null) method.invoke(optionClass, booleanObject); log("set option <" + option.getName() + "> to value <" + option.getValue() +
">"); return true; } catch (IllegalArgumentException e) { handleUnexpectedException(e); } catch (IllegalAccessException e) { handleUnexpectedException(e); } catch (InvocationTargetException e) { handleUnexpectedException(e); } catch (Exception e) { // ignore }

return false; } ...

so AFAIU only true/false values are accepted ..

so tracing our problem down we found that com.meterware.httpunit.HttpUnitUtils has a not very pretty implementation of decode:

/** * Returns an interpretation of the specified URL-encoded string. * FIXME: currently assumes iso-8859-1 character set. **/ public static String decode( String byteString ) { char[] chars = byteString.toCharArray(); StringBuffer sb = new StringBuffer(chars.length); char[] hexNum = { '0', '0', '0' };

int i = 0; while (i < chars.length) { if (chars[i] == '+') { i++; sb.append( ' ' ); } else if (chars[i] == '%') { i++; hexNum[1] = chars[i++]; hexNum[2] = chars[i++]; sb.append( (char) Integer.parseInt( new String( hexNum ), 16 ) ); } else { sb.append( chars[i++] ); } } return sb.toString(); }

so we changed it to:

public static String decode( String byteString ) { try { return URLDecoder.decode(byteString,"ISO-8859-2"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }

and the world is bright again :), I'll of course change the hardcoded charset when I get the rest of the script working ...