Re: How to simulate UTF-8 encoded request parameters
"James Abley" <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Stefan, That was my understanding. So if you're reporting a bug in HTTPUnit, and you have a test case already, are you psyched to provide a patch as well? Cheers, James On 17/04/07, Stefan Hübner <[email protected]> wrote: > Hi James, > > sorry for the late response, which I hope will reach you nevertheless. > I will try to describe make my point more precisely. > > The problem *only* shows up, when rolling servlets inside HTTPunit (or > the ServletRunner, to be more precisely). In Tomcat everything is > fine, provided URIEncoding is set to UTF-8, of course. > > So what I am after is httpunit to behave exactly like tomcat > configured with UTF-8-URIEncoding. That is: I want HttpUnit to > url-encode request parameters using utf-8 when I send the request *and > decode* them back into usefull values using utf-8-urldecoding when > HttpServletRequest#getParameter(...) is invoked. > > My problem is, that I just can't get HttpUnit doing it that way. What > I found httpunit does is, it encodes parameter values using utf-8 > (which I think is activated by > HttpUnitOptions.setDefaultCharacterSet("utf-8");). But invoking > HttpServletRequest#getParameter(...) from inside the servlet (running > in httpunit) returns parameter values decoded using ISO-8859-1. This > behaviour causes my servlet tests to fail when I test them using > ServletRunner. > > Didn't the testcase provided serve as an example for the behaviour I'm > struggling with? It doesn't really involve a servlet. But the fact > alone, that request.getParameter() doesn't return what was expected, > should have prooved httpunit doing strange things here. Doesn't it? > > It's here: > > // Thought, this would simulate a containers URIEncoding-setting > > HttpUnitOptions.setDefaultCharacterSet("utf-8"); > > > > ServletRunner servletRunner = new ServletRunner(); > > > > WebRequest request = new GetMethodWebRequest("http://localhost/dummy"); > > request.setParameter("param", "\u00e4\u00f6\u00fc"); > > > > ServletUnitClient sc = servletRunner.newClient(); > > InvocationContext ic = sc.newInvocation(request); > > HttpServletRequest httpRequest = ic.getRequest(); > > > > // Test fails with "ComparisonFailure: expected: <äöü> but was: <äöü>" > > assertEquals("äöü", httpRequest.getParameter("param")); > > } > > Did this help make my point slightly clearer to you? > > > Thanks for trying to help me! > Stefan > > > > 2007/4/12, James Abley <[email protected]>: > > I haven't fully understood your problem. > > > > Is the problem with your Servlet, or is it with HTTPUnit? > > > > If it's your servlet, then potentially the container can be configured > > to decode parameters using UTF-8 rather than Latin-1, or whatever. > > > > For example, see Tomcat, especially, the URIEncoding attribute on a Connector. > > > > http://tomcat.apache.org/tomcat-5.5-doc/config/http.html > > > > >From the sounds of your initial post, it sounds like you've done > > something like this? > > > > Do you have test cases which are hitting the full servlet, rather than > > something within HTTPUnit? > > > > James > > > > On 12/04/07, andresgr <[email protected]> wrote: > > > Google for "httpunit utf". > > > > > > :) > > > > > > > > > -- > > > -=-=-=-=-=-=-=-=-=-=-=-=- > > > Andrés González. > > > http://coyotevil.blogspot.com > > > > > > ------------------------------------------------------------------------- > > > Take Surveys. Earn Cash. Influence the Future of IT > > > Join SourceForge.net's Techsay panel and you'll get the chance to share your > > > opinions on IT & business topics through brief surveys-and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > _______________________________________________ > > > Httpunit-develop mailing list > > > [email protected] > > > https://lists.sourceforge.net/lists/listinfo/httpunit-develop > > > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share your > > opinions on IT & business topics through brief surveys-and earn cash > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > > Httpunit-develop mailing list > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/httpunit-develop > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Httpunit-develop mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/httpunit-develop > ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/