Repository: wso2/product-microgateway
Issue: PathParameters does not resolve if the rawPath contains a trailing slash

### Description:
If there is a path called `/pet/{petId}` and the inbound request has `/pet/2/`. Due to trailing slash, the path parameters are not resolved for the usage of custom filters.

And following error log also getting printed.
```
PathTemplate and RawPath is mismatched.
```

### Steps to reproduce:
Refer to the description.

### Affected Product Version:
Choreo-Connect-1.0.0-alpha

### Environment details (with versions):
- OS:
- Client:
- Env (Docker/K8s):

---
### Optional Fields
#### Related Issues:
<!-- Any related issues from this/other repositories-->

#### Suggested Labels:
<!--Only to be used by non-members-->

#### Suggested Assignees:
<!--Only to be used by non-members-->


Changed files:
enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/ParameterResolver.java
enforcer-parent/commons/src/test/java/org/wso2/choreo/connect/enforcer/commons/model/RequestContextTest.java

diff --git a/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/ParameterResolver.java b/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/ParameterResolver.java
index 4ae2c4c83..1ba41f305 100644
--- a/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/ParameterResolver.java
+++ b/enforcer-parent/commons/src/main/java/org/wso2/choreo/connect/enforcer/commons/model/ParameterResolver.java
@@ -29,14 +29,16 @@ import java.util.regex.Pattern;
 
 class ParameterResolver {
 
-    private static final Pattern PARAMETER_PATTERN = Pattern.compile("(\\\\{[a-zA-Z]+\\\\})");
+    private static final Pattern PARAMETER_PATTERN = Pattern.compile("(\\\\{[a-zA-Z0-9]+[a-z-_A-Z0-9]*\\\\})");
     private static final Logger logger = LogManager.getLogger(ParameterResolver.class);
     private final List<String> parameterNames = new ArrayList<>();
     private final Pattern pattern;
 
     public ParameterResolver(final String parameterTemplate) {
-
-        final Matcher matcher = PARAMETER_PATTERN.matcher(parameterTemplate);
+        // This formatting is required since /foo and /foo/ are considered to be equal
+        String formattedPathParamTemplate = parameterTemplate.endsWith("/") ?
+                parameterTemplate.substring(0, parameterTemplate.length() - 1) : parameterTemplate;
+        final Matcher matcher = PARAMETER_PATTERN.matcher(formattedPathParamTemplate);
 
         while (matcher.find()) {
             if (matcher.groupCount() == 1) {
@@ -55,7 +57,10 @@ class ParameterResolver {
     }
 
     public Map<String, String> parametersByName(final String uriString) throws IllegalArgumentException {
-        final Matcher matcher = pattern.matcher(uriString);
+        // This formatting is required since /foo and /foo/ are considered to be equal
+        String formattedURI = uriString.endsWith("/") ?
+                uriString.substring(0, uriString.length() - 1) : uriString;
+        final Matcher matcher = pattern.matcher(formattedURI);
         if (!matcher.matches()) {
             // Unlikely to occur as this pair is already matched within router.
             logger.error("PathTemplate and RawPath is mismatched.");
diff --git a/enforcer-parent/commons/src/test/java/org/wso2/choreo/connect/enforcer/commons/model/RequestContextTest.java b/enforcer-parent/commons/src/test/java/org/wso2/choreo/connect/enforcer/commons/model/RequestContextTest.java
index 4b6263f0a..6c9e4fe31 100644
--- a/enforcer-parent/commons/src/test/java/org/wso2/choreo/connect/enforcer/commons/model/RequestContextTest.java
+++ b/enforcer-parent/commons/src/test/java/org/wso2/choreo/connect/enforcer/commons/model/RequestContextTest.java
@@ -38,6 +38,36 @@ public class RequestContextTest {
                 "statusType", "available");
     }
 
+    @Test
+    public void testPathParametersWithTrailingSlashInTemplate() {
+        testPathParamValues("/v2/pet/12/status/available", "/v2", "/pet/{petId}/status/{statusType}/",
+                "petId", "12");
+    }
+
+    @Test
+    public void testPathParametersWithTrailingSlashInRawPath() {
+        testPathParamValues("/v2/pet/12/status/available/", "/v2", "/pet/{petId}/status/{statusType}",
+                "petId", "12");
+    }
+
+    @Test
+    public void testPathParametersWithHyphen() {
+        testPathParamValues("/v2/pet/12/status/available", "/v2", "/pet/{pet-Id}/status/{statusType}",
+                "pet-Id", "12");
+    }
+
+    @Test
+    public void testPathParametersWithUnderscore() {
+        testPathParamValues("/v2/pet/12/status/available", "/v2", "/pet/{pet_Id}/status/{statusType}",
+                "pet_Id", "12");
+    }
+
+    @Test
+    public void testPathParametersWithNumbers() {
+        testPathParamValues("/v2/pet/12/status/available", "/v2", "/pet/{petId2}/status/{statusType}",
+                "petId2", "12");
+    }
+
     @Test
     public void testPathParameterGenerationWithWildcard() {
         testPathParamValues("/v2/pet/12/2/random/random2", "/v2", "/pet/{petId}/{imageId}/*",