Search in sources :

Example 6 with Parameter

use of io.github.microcks.domain.Parameter in project microcks by microcks.

the class URIBuilder method buildURIFromPattern.

/**
 * Build a URI from a URI pattern (using {} or /: for marked variable parts) and using
 * other query parameters
 * @param pattern The URI pattern to use
 * @param parameters The set of parameters (whether template or query based)
 * @return The instanciated URI from template and parameters
 */
public static String buildURIFromPattern(String pattern, List<Parameter> parameters) {
    if (parameters != null) {
        // Browse parameters and choose between template or query one.
        for (Parameter parameter : parameters) {
            String wadlTemplate = "{" + parameter.getName() + "}";
            String swaggerTemplate = "/:" + parameter.getName();
            if (pattern.contains(wadlTemplate)) {
                // It's a template parameter.
                pattern = pattern.replace(wadlTemplate, encodePath(parameter.getValue()));
            } else if (pattern.contains(swaggerTemplate)) {
                // It's a template parameter.
                pattern = pattern.replace(":" + parameter.getName(), encodePath(parameter.getValue()));
            } else {
                // It's a query parameter, ensure we have started delimiting them.
                if (!pattern.contains("?")) {
                    pattern += "?";
                }
                if (pattern.contains("=")) {
                    pattern += "&";
                }
                pattern += parameter.getName() + "=" + encodeValue(parameter.getValue());
            }
        }
    }
    return pattern;
}
Also used : Parameter(io.github.microcks.domain.Parameter)

Aggregations

Parameter (io.github.microcks.domain.Parameter)6 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Header (io.github.microcks.domain.Header)1 Request (io.github.microcks.domain.Request)1 EvaluableRequest (io.github.microcks.util.el.EvaluableRequest)1 TemplateEngine (io.github.microcks.util.el.TemplateEngine)1 HashMap (java.util.HashMap)1