[Httpunit-develop] Feed Back about HttpUnit Encording
Brought to you by:
russgold
From: Tuyoshi U. <t-...@bp...> - 2000-12-19 17:46:14
|
Hello all, Now I am testing JavaServlet Application with HttpUnit. I think HttpUnit is very Smart Program!! But,When I use "WebResponse.getTables()" with Japanese Character (our project's web pageencoding is Shift_JIS),Returned String character was wrong character(ex ?????,,and so on).and that character ccould not transrate other encoding by String Constructor. So,I wanted to use HttpUnit with Japanese Character. I read httpunit's source and When I changed next source like below, HttpUnit with Japanese Character work correctly!! Would you mind adding "multy-byte encoding option" to HttpUnit? #in Japan,Web Page is almost,EUC_JP or Shift_JIS or ISO2022JP ------------ReceivedPage.java private static Tidy getParser() { Tidy tidy = new Tidy(); tidy.setCharEncoding(org.w3c.tidy.Configuration.RAW); // Add Line tidy.setQuiet( true ); tidy.setShowWarnings( HttpUnitOptions.getParserWarningsEnabled() ); return tidy; } --------------------------- -----------WebResponse.java private String _characterSet = "Shift_JIS"; // Changed from "us-ascii" private static String getResponseText( URL url, URLConnection connection ) { StringBuffer sb = new StringBuffer(); try { // Chaned Constructor of InputStreamReader BufferedReader input = new BufferedReader( new InputStreamReader(connection.getInputStream() ,"Shift_JIS") ); ---------------------------- ----------------------TestAp(sample) WebResponse response; ... String [][] customers = response.getTables()[0].asText(); String customerJP = getShiftJIS(customers); assertEquals("XXXX",customersJP[1][1]); // XXXX is Japanese assertEquals("????",customersJP[2][1]); // ???? is Japanese assertEquals("****",customersJP[3][1]); // **** is Japanese } ... private String [][] getShiftJIS(String [][] shiftJis){ int arrayFirst = shiftJis.length; int arraySecond = shiftJis[0].length; int i,l; String [][] retString = new String[arrayFirst][arraySecond]; for(i = 0 ; i < arrayFirst ; i++){ for(l = 0 ; l < arraySecond ; l++){ try{ retString[i][l] = new String(shiftJis[i][l].getBytes("8859_1"), "Shift_JIS"); }catch (Exception e){ } } } return retString; } ... ---------------------------- Sorry my English knowledge and code is very Poor... --- // Tuyoshi Ushio // t-...@bp... |