All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockserver.mappers.URIMapper Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
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