Question

I have to following URI which outputs categories and subcategories:

Pattern:

www.uri.com/webservice/category1/category2/category3/category4

Example:

www.uri.com/webservice/1/56/104/605

This URI can have none,one or more subcategories like in the example. How do i get these parameters (1,56,104,605) in an array so i can check if each category is a subcategory of the other?

Was it helpful?

Solution

Inject an UriInfo instance in your resource method and use the getPathParameters() or getPathSegments() method:

@Path("category/{categoryIds:.+}/product/{productId}")
public ReturnType myMethod(@Context UriInfo uriInfo) {

    for (PathSegment pathSegment: uriInfo.getPathSegments()) {
        //do here what you want with the uriInfo
    }
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top