jerseyjax-rspath-parameter

How to manage string with blanks, comma etc. as PathParam?


I created a web services that needs to get a string with blanks, commas, parenthesis and other special characters. I would like pass it as PathParam but I wasn't able to manage this string.

The string that I want to manage is similar to the follow:

POLYGON((9.5 44.6, 12.5 44.6, 12.5 42.0, 9.5 42.0, 9.5 44.6))

My method is:

@POST
@Path("/j_update_spi/{step}/{srid}/{polygon:.+}")
public Response updateSPI(@PathParam("step") String step,
                          @PathParam("srid") String srid,
                          @PathParam("polygon") String polygon){
...
}

i tried to set ".+" for polygon parameter but it doesn't work (i also tried to use .*).

If I call this service the method doesn't start.


Solution

  • I solved my problem: I changed the PathParam "polygon" and made it as optional. Then I changed regex rules into polygon PathParam.

    @POST
    @Path("/update_spi/{step}/{srid}{polygon:(/polygon/.+?)?}")
    public Response updateSPI(@PathParam("step") String step,
                              @PathParam("srid") String srid,
                              @PathParam("polygon") String polygon)
    

    in order to extract the string that defines my WKT Polygon I used split method:

    if(!polygon.matches(""))
         polygon = polygon.split("/")[2];