I'm unit testing my Java/Jersey web service and running into an interesting test case. I'm checking the status codes of different URI entries to make sure that incorrect URIs won't destroy my code or anything. In test cases where I throw in invalid characters (such as !@$#<>, etc.), my browser pulls up a 404 error like I would expect, but JUnit is showing the error as a 500 error. This happens in cases where I throw in things like "<134->" and cases where I try injecting html code (such as "myURI<html><p>hello</p><br></html>/restofmyURI
").
Any ideas why I would be getting different server responses for the same call, and/or how to consolidate the responses?
Instead of encoding the String directly. Encode the url object. That should help prevent the MalformedURLException
Just want to tie up loose ends for my process here. I ended up not needing to encode my tests since the URLs would be called directly, not through a browser, but I had an encoding method in place before I realized that. Based upon Kaj's suggestion (see comments on my original question), I encoded the string in parts, splitting at any characters I needed to leave unencoded (namely
:
and/
for this case). It's a bit more complicated than I feel it needs to be, but it served its purpose.--Edit: Relevant Code--
Here is the method of my test which I call to open a connection to the server (using basic authentication):
The encoding (if necessary) would be done before being passed into this method.