Skip to content

Commit

Permalink
Merge pull request #2538 from praminda/ws-path-param
Browse files Browse the repository at this point in the history
Fix path param population error in Websocket APIs
  • Loading branch information
pubudu538 authored Dec 7, 2021
2 parents ee416e1 + e58f010 commit 7991147
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand All @@ -33,6 +35,7 @@
* through out the complete request flow through the gateway enforcer.
*/
public class RequestContext {
private static final Logger logger = LogManager.getLogger(RequestContext.class);

//constants
public static final String CLUSTER_HEADER = "x-wso2-cluster-header";
Expand Down Expand Up @@ -447,6 +450,11 @@ public Builder pathTemplate(String requestPathTemplate) {
*/
private Map<String, String> populatePathParameters(String basePath, String resourceTemplate,
String rawPath) {
if (resourceTemplate == null || rawPath == null) {
logger.debug("Skip populating the path parameters. template: {}, rawPath: {}", resourceTemplate,
rawPath);
return null;
}
// Format the basePath and resourcePath to maintain consistency
String formattedBasePath = basePath.startsWith("/") ? basePath : "/" + basePath;
formattedBasePath = formattedBasePath.endsWith("/") ?
Expand All @@ -457,8 +465,7 @@ private Map<String, String> populatePathParameters(String basePath, String resou
String formattedRawPath = rawPath.split("\\?")[0];
final ParameterResolver parameterResolver = new ParameterResolver
(formattedBasePath + formattedResourcePathTemplate);
final Map<String, String> resultMap = parameterResolver.parametersByName(formattedRawPath);
return resultMap;
return parameterResolver.parametersByName(formattedRawPath);
}
}
}

0 comments on commit 7991147

Please sign in to comment.