mercredi 11 mars 2015

MockHttpServletRequest ignoring set fields, how do I get around this?



I am trying to test a servlet filter for a Tomcat application. To do so, I am using the MockHttpServletRequest provided by Spring.


I set it up like this:



MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setRemoteHost("mycompany.com");
request.setRequestURI("/myapp.php");
request.setSecure(true);


but when I the following:



System.out.println(request.getRequestURL());


produces: http://localhost/myapp.php. On the other hand, if I explicitly request one of the fields I set, like:



System.out.println(request.getRemoteHost());


I get: mycompany.com


What's going on here? How can I get getRequestURL to produce what I'm really after: http://ift.tt/18BK6nE




Aucun commentaire:

Enregistrer un commentaire