I recently solved this problem in one of my applications. My urls look like this.
/categories/{category}/subcategories/{subcategory}
My problem was that I wanted to map each url pattern to a Java class so that I could call the correct class to render the data.
My application uses Netty, but the URL recognition tool does not use third-party libraries.
What this allows me to do is to analyze the URL that comes from the browser, create a map with key-value pairs (in this case, category and subcategory), and also create an instance of the correct handler for each unique URL pattern. A total of about 150 lines of Java code for parsing, customizing the application, and defining unique URL patterns.
You can view the code for the recognizer on GitHub: https://github.com/joachimhs/Contentice/blob/master/Contentice.api/src/main/java/no/haagensoftware/contentice/util/URLResolver.java
UrlResolver.getValueForUrl will return a URLData with the information you need for your URL: https://github.com/joachimhs/Contentice/blob/master/Contentice.api/src/main/java/no/haagensoftware/contentice/data/URLData .java
Once this is installed, I can associate the URLs with Netty Handlers:
this.urlResolver.addUrlPattern("/categories", CategoriesHandler.class); this.urlResolver.addUrlPattern("/categories/{category}", CategoryHandler.class); this.urlResolver.addUrlPattern("/categories/{category}/subcategories", SubCategoriesHandler.class); this.urlResolver.addUrlPattern("/categories/{category}/subcategories/{subcategory}", SubCategoryHandler.class);
Inside my handlers, I can just get a parameter map:
String category = null; logger.info("parameterMap: " + getParameterMap()); if (getParameterMap() != null) { category = getParameterMap().get("category"); }
Hope this helps :)