Why is my QueryParam returning null

Disclaimer: I am not a J2EE developer. But this code works elsewhere, but this 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 looking for lat 17.63 lng null

Call from client

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

+3


source to share


2 answers


Disclaimer: I'm not a big user of cURL, so I don't know all the nuances and why it works. It could be a shell problem.

To get it working 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 get out of &

(no quotes), but I would get URISyntaxExeption with the server.

+2


source


The character &

must be escaped, it has special meaning in the shell. You can do it 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 option or you should avoid all characters that your shell recognizes as special characters.

Try:

echo abc&def

      



This basically means:

  • run the command echo abc

    in the background ( https://unix.stackexchange.com/q/86247 ) that prints the string "abc"
  • run the command def

    (which will probably just throw an error as it doesn't exist)
+1


source







All Articles