Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking a 'REST' service which have query parameters in the URL

I have to invoke a GET on a service which returns text/xml.

The endpoint is something like this:

http://service.com/rest.asp?param1=34&param2=88&param3=foo

When I hit this url directly on a browser (or some UI tool), all's good. I get a response.

Now, I am trying to use CXF WebClient to fetch the result using a piece of code like this:

String path = "rest.asp?param1=34&param2=88&param3=foo";

webClient.path(path)
    .type(MediaType.APPLICATION_JSON)
    .accept(MediaType.TEXT_XML_TYPE)
    .get(Response.class);

I was debugging the code and found that the request being sent was url encoded which appears something like this:

http://service.com/rest.asp%3Fparam1=34%26param2=88%26param3=foo

Now, the problem is the server doesn't seem to understand this request with encoded stuff. It throws a 404. Hitting this encoded url on the browser also results in a 404.

What should I do to be able to get a response successfully (or not let the WebClient encode the url)?

like image 727
TJ- Avatar asked Feb 08 '13 10:02

TJ-


1 Answers

Specify the parameters using the query method:

String path = "rest.asp";
webClient.path(path)
    .type(MediaType.APPLICATION_JSON)
    .accept(MediaType.TEXT_XML_TYPE)
    .query("param1","34")
    .query("param2","88")
    .query("param3","foo")
    .get(Response.class);
like image 174
Andre Avatar answered Sep 26 '22 18:09

Andre