org.mockserver.mappers.URIMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-core Show documentation
Show all versions of mockserver-core Show documentation
Functionality used by all MockServer modules for matching and expectations
package org.mockserver.mappers;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.Parameter;
import java.util.List;
/**
* @author jamesdbloom
*/
public class URIMapper {
public static String getURI(HttpRequest httpRequest) {
StringBuilder queryString = new StringBuilder();
List queryStringParameters = httpRequest.getQueryStringParameters();
for (int i = 0; i < queryStringParameters.size(); i++) {
Parameter parameter = queryStringParameters.get(i);
if (parameter.getValues().isEmpty()) {
queryString.append(parameter.getName());
queryString.append('=');
} else {
List values = parameter.getValues();
for (int j = 0; j < values.size(); j++) {
String value = values.get(j);
queryString.append(parameter.getName());
queryString.append('=');
queryString.append(value);
if (j < (values.size() - 1)) {
queryString.append('&');
}
}
}
if (i < (queryStringParameters.size() - 1)) {
queryString.append('&');
}
}
return httpRequest.getPath() + queryString.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy