java - JerseyTest framework path encoding replaces ? with %3F -
i have failing test, should passing. service works fine, jerseytest junit test failing status 400.
using postman or browser, when try url against deployed service:
http://localhost:8080/myservice/123?appid=local&userid=jcn
i correct result, status 200 , see following in log:
info: 4 * server has received request on thread http-nio-8080-exec-5 4 > http://localhost:8080/myservice/123?appid=local&userid=jcn
note ? in url, correct.
but when try unit test in jeryseytest-extended junit class:
@test public void getwithcorrecturlexecuteswithouterror() { string x = target("myservice/123?appid=local&userid=jcn").request().get(string.class); }
it fails status 400, , see in log:
info: 1 * server has received request on thread grizzly-http-server-0 1 > http://localhost:9998/myservice/123%3fappid=local&userid=jcn
note ? has been replaced %3f.
i don't understand happening. if try "%3f" url in browser, see same 400 error unit test. feel encoding of url problem.
here jersey resource, partial listing because it's kind of long, pretty sure relevant part:
@component @path("/myservice") public class myresource { @autowired somedao somedao; @notblank @queryparam("appid") private string appid; @notblank @queryparam("userid") private string userid; @get @path("/{id}") @produces(mediatype.application_json) public status getstatus(@notblank @pathparam("id") string id) { errors = new arraylist<>(); status retval; if(validateid(id)) { retval = somedao.getstatus(id); } else { throw new badparameterexception(string.join(" | ", errors)); } return retval; } }
you can use queryparam
method on webtarget
instance:
string x = target("myservice/123") .queryparam("appid", "local") .queryparam("userid", "jcn") .request() .get(string.class);
Comments
Post a Comment