semicolon in the restful service URL truncate the characters after it

997 Views Asked by At

I have the below code as my restful service operation.

    @GET
    @UnitOfWork
    @Timed(name = "get-requests")
    @Path("/{referenceId}")
    public Response get(@Auth @ApiParam(access = "internal") UserPrincipal user,
            @ApiParam(name = "id", value = "reference ID", required = true)
            @PathParam("referenceId") String id) {
         return Response.ok(id).build();
    }

However, I noticed if I pass in m1234;5678, I get only m1234 returned. I tried @Path("/{referenceId:.*}"), but it doesn't work. I also tried use @Encode at the top of the method to make sure the url is not decoded and then try to replace %3B with ";" in the code. But it seems not working also.

Please note that I cannot use Spring framework. Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

The ; denotes a matrix parameter. Use @MatrixParam to get its value.

See also the answers to this question: URL matrix parameters vs. request parameters

Edit: The key of the matrix parameter would be 5678, the value would be null.

There is a way to get achieve what you want by using PathSegment as the type of the parameter instead of String:

@PathParam("referenceId) PathSegment id

In the body of the method, you can use

String idValue = id.getPath();

to get m1234;5678.