简体   繁体   中英

Retrieving the REST URL pattern from a servlet filter

I have created a rest service with the following url pattern

/author/{authorId}/book/{bookId}

In run time I can access the service with the following path

/author/1234/book/1001

Now I have a ServletFilter defined. Every request to access the url/author/1234/book/1001 is hitting the filter too. In this filter how can I find the url pattern of the incoming request ie, /author/{authorId}/book/{bookId} .

Regards -Albin

first find the real path of the request. that is the requested_uri - context_path

String uri = req.getRequestURI();
String context = req.getContextPath();
String realPath = uri.substring(context.length());

then use regex to extract authorId and bookId

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM