Search code examples
javarestweb-servicesjerseyjax-rs

Question mark(?) getting replaced by %3F in jax-rs jersey


While calling an API in jax-rs jersey I have to pass a parameter. But that is getting converted into some special character. I have declared a variable mCopy which will take either false or true based on some conditions. My URI is

URI:- https://idcs-oda-xxxxxxx.com/api/v1/bots/pushRequests?copy=true

My code is

Response rawres = client.target("https://idcs-oda-xxxxxxx.com")
                                .path("bots")
                                .path("pushRequests?copy="+mcopy")
                                .request().header("Authorization",access_token)
                                .post(null, Response.class);

it throws error

  https://idcs-oda-xxxxxxx.com/api/v1/bots/pushRequests%3Fcopy=false, status=404, reason=Not Found

actually pushRequests?copy=mCopy getting converted to pushRequests%3Fcopy=false

how can I keep ? symbol as it is?


Solution

  • You're not using the API correctly. You want to do:

    Response rawres = client.target("https://idcs-oda-xxxxxxx.com")
                                    .path("bots")
                                    .path("pushRequests")
                                    .queryParam("copy", mcopy) // this is the change
                                    .request().header("Authorization",access_token)
                                    .post(null, Response.class);