I'm working with a list that contains urls that should be excluded in a filter.
List<String> excludeFromFilter = Arrays.asList(ApiResources.Account_LOGIN,
ApiResources.Account.URI_GET_MERCHANT,
ApiResources.Account.URI_GET_ACCOUNT);
Next, for the functionality, I evaluate if excludeFromFilter
contains the url that I passed through the request:
final HttpServletResponse response = (HttpServletResponse) servletResponse;
final String path = request.getPathInfo();
if (!excludeFromFilter.contains(path)) {
...
}
The problem is that sometimes I have to verify that a url that contains a parameter is excluded, for example: /api/accounts/24
what would correspond to the constant ApiResources.Account.URI_GET_ACCOUNT
that has the value /api/accounts/{accountId}
. I can not replace 24 with {accountId} for validation because later I may need to exclude a url that contains another parameter, for example /api/accounts/{merchantId}
.
How can I use the contains () function to validate if the url has any number in that parameter. Currently this is the list:
[/ user / login, / api / merchants / {merchantId}, / api / accounts / {accountId}]
and for this last value it should be true
the function contains () with values such as: "/api/accounts/24"
, "/api/accounts/1"
, "/api/accounts/130"
.