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;
   }
@Test
   void testBuildURIFromPatternWithEncoding() {
      // Prepare a bunch of parameters.
      Parameter nameParam = new Parameter();
      nameParam.setName("name");
      nameParam.setValue("Eclair Cafe");

      Parameter descriptionParam = new Parameter();
      descriptionParam.setName("description");
      descriptionParam.setValue("My desc");

      List<Parameter> parameters = new ArrayList<>();
      parameters.add(nameParam);
      parameters.add(descriptionParam);

      // Test with old wadl like template format.
      String pattern = "http://localhost:8080/pastry/{name}";
      String uri = URIBuilder.buildURIFromPattern(pattern, parameters);
      assertTrue("http://localhost:8080/pastry/Eclair%20Cafe?description=My+desc".equals(uri));

      // Test with new swagger like template format.
      pattern = "http://localhost:8080/pastry/:name";
      uri = URIBuilder.buildURIFromPattern(pattern, parameters);
      assertTrue("http://localhost:8080/pastry/Eclair%20Cafe?description=My+desc".equals(uri));
   }