package core.framework.impl.web.request;

import core.framework.util.Encodings;
import core.framework.util.Maps;
import core.framework.web.exception.BadRequestException;

import java.util.Map;

import static core.framework.util.Strings.format;

/**
 * @author neo
 */
public final class PathParams {
    private final Map<String, String> params = Maps.newHashMap();

    public void put(String name, String value) {
        if (value.isEmpty()) throw new BadRequestException(format("path param must not be empty, name={}, value={}", name, value), "INVALID_HTTP_REQUEST");
        // value here is not decoded, refer to core.framework.impl.web.request.RequestParser.path
        // decodeURIComponent won't throw exception, if the uri is invalid, undertow decoding will break first and return 400
        params.put(name, Encodings.decodeURIComponent(value));
    }

    public String get(String name) {
        String value = params.get(name);
        if (value == null) throw new Error("path param not found, name=" + name);
        return value;
    }
}

@@ -567,24 +567,98 @@
 ST%22);%0A      
+  try %7B%0A            params.put(name, Encodings.decodeURIComponent(value));
   // value h
@@ -749,188 +749,142 @@
     
-// decodeURIComponent won't throw exception, if the uri is invalid, undertow decoding will break first and return 400%0A        params.put(name, Encodings.decodeURIComponent(value));
+%7D catch (IllegalArgumentException e) %7B%0A            throw new BadRequestException(e.getMessage(), %22INVALID_HTTP_REQUEST%22, e);%0A        %7D
 %0A   

fix unit test