URL parameter encoding bug
"Mark Hobson" <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi there,
I believe I've encountered a parameter encoding bug with URL encoded
post requests in httpunit. See the below testcase for an example - it
passes on windows, but fails on linux.
I believe this is due to the call to String.getBytes() in
URLEncodedMessageBody.writeTo() which uses the platforms native
encoding - i.e. ISO-8859-1 in windows, which is the correct encoding
for HTTP, and then UTF-8 in linux, which is an incorrect encoding for
HTTP.
I've run a similar servlet test under tomcat on both windows and linux
and it works as expected, which implies this is a bug in httpunit.
Let me know if you all agree and I'll raise a bug. Any workarounds
gratefully accepted.
Cheers,
Mark
-------------------------------------------8<---------------------------------------------
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.servletunit.InvocationContext;
import com.meterware.servletunit.ServletRunner;
public class Test extends TestCase
{
public static class TestServlet extends HttpServlet
{
public String param;
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
param = request.getParameter("param");
}
}
public void test() throws IOException, ServletException
{
PostMethodWebRequest request = new
PostMethodWebRequest("http://localhost/servlet");
request.setParameter("param", new String("£"));
ServletRunner runner = new ServletRunner();
runner.registerServlet("servlet", TestServlet.class.getName());
InvocationContext context = runner.newClient().newInvocation(request);
context.service();
TestServlet servlet = (TestServlet) context.getServlet();
assertEquals("£", servlet.param);
}
}
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642