Siddharth
Siddharth

Reputation: 9574

Why is my QueryParam returning null

Disclaimer : I am not a J2EE developer. But this code works elsewhere, but this one api is going crazy.

Code

@GET
    @Path("GetCloseby")
    @Consumes({ MediaType.TEXT_PLAIN })
    @Produces({ MediaType.APPLICATION_JSON })
    public CServiceCenters getList(@QueryParam("latitude") Double latitude,
            @QueryParam("longitude") Double longitude) {
            log.info("GetCloseby searching for lat "
                    + latitude + " lng " + longitude);

GetCloseby searching for lat 17.63 lng null

Calling from client

curl http://:8080/MYWAR/MYAPI/GetCloseby?latitude=17.63&longitude=73.9

Upvotes: 3

Views: 189

Answers (2)

Paul Samsotha
Paul Samsotha

Reputation: 208974

Disclaimer: I am not a big cURL user, so I don't know all the nuances, and why this works. It may be a shell problem.

To get it work I had to add quotes " around the url

curl "http://:8080/MYWAR/MYAPI/GetCloseby?latitude=17.63&longitude=73.9"

Note: I also tried to escape the & (without the quotes) but I would get a URISyntaxExeption with the server.

Upvotes: 2

Misch
Misch

Reputation: 10840

The & character needs to be escaped, it has a special meaning in a shell. You can do this like this: "abc&def" or like this: abc\&def. If you try the latter: there may be other special characters in this query, so either use the first variant or you have to escape all chracters which are recognized by your shell as special characters.

Try it:

echo abc&def

This basically means:

  • run the command echo abc in the background (https://unix.stackexchange.com/q/86247) which prints the string "abc"
  • run the command def (which will probably just cause an error, as it does not exist)

Upvotes: 1

Related Questions