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

top.jfunc.http.component.DefaultCompletedUrlCreator Maven / Gradle / Ivy

package top.jfunc.http.component;

import top.jfunc.http.config.Config;
import top.jfunc.http.request.HttpRequest;
import top.jfunc.http.util.ParamUtil;
import top.jfunc.common.utils.MapUtil;
import top.jfunc.common.utils.MultiValueMap;
import top.jfunc.common.utils.ObjectUtil;

/**
 * @author xiongshiyan at 2020/1/6 , contact me with email [email protected] or phone 15208384257
 */
public class DefaultCompletedUrlCreator implements CompletedUrlCreator {
    /**
     * 处理Route参数、BaseURL、Query参数
     * @param httpRequest 请求
     * @return 处理过后的URL
     */
    @Override
    public String complete(HttpRequest httpRequest) {
        Config config = httpRequest.getConfig();
        Config.throwExIfNull(config);
        //1.处理Route参数
        String routeUrl = ParamUtil.replaceRouteParamsIfNecessary(httpRequest.getUrl() , httpRequest.getRouteParams());
        //2.处理BaseUrl
        String urlWithBase = ParamUtil.concatUrlIfNecessary(config.getBaseUrl() , routeUrl);
        //3.处理Query参数
        MultiValueMap params = MapUtil.mergeMap(httpRequest.getQueryParams(), config.getDefaultQueryParams());
        String queryCharsetWithDefault = ObjectUtil.defaultIfNull(httpRequest.getQueryParamCharset() , config.getDefaultQueryCharset());
        return ParamUtil.contactUrlParams(urlWithBase, params, queryCharsetWithDefault);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy