Jersey encoded query param but rest service doesn't want it encoded

628 Views Asked by At

I am trying to make a rest request to microsoft but some of the query parameters that I need to use are being encoded by jersey which results in them being wrong when interpreted by the rest service.

For example,

static String authorizationcode = "M2a34718e-5a3e-f8a1-4edb-d55adaf9aac9&lc=1033";

If this authorization code is encoded then the rest call fails. Here is my code. I didn't see any obvious way to get around this problem. The client secret is also problematic as it can contain a space which seems to be encoded to a "+" before being sent across.

    WebResource webResource = client.resource(OneDriveEnum.OAUTH20_TOKEN_URL.toString());
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();

    queryParams.add(API_PARAM_CLIENT_ID, principal.getClientId());
    queryParams.add(API_PARAM_CLIENT_SECRET, principal.getClientSecret());
    queryParams.add(API_PARAM_CODE, principal.getAuthorizationCode());
    queryParams.add(API_PARAM_REDIRECT_URI, OneDriveEnum.OAUTH20_DESKTOP_REDIRECT_URL.toString());
    queryParams.add(API_PARAM_GRANT_TYPE, OneDriveEnum.GRANT_TYPE_AUTHORIZATION_CODE.toString());

    Builder b = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON);

    ClientResponse clientResponse = b.get(ClientResponse.class);

Thanks for any thoughts !

1

There are 1 best solutions below

0
On

Yeah as you point out, it was the extra parameter in the parameter value that was causing the problem. Thanks!