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

org.mule.module.http.internal.request.HttpRequesterRequestBuilder Maven / Gradle / Ivy

There is a newer version: 3.9.0
Show newest version
/*
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */
package org.mule.module.http.internal.request;

import org.mule.api.MuleEvent;
import org.mule.module.http.internal.HttpMessageBuilder;
import org.mule.module.http.internal.HttpParamType;
import org.mule.module.http.internal.ParameterMap;

import java.util.List;

public class HttpRequesterRequestBuilder extends HttpMessageBuilder
{

    public ParameterMap getQueryParams(MuleEvent event)
    {
        return resolveParams(event, HttpParamType.QUERY_PARAM);
    }

    public ParameterMap getHeaders(MuleEvent event)
    {
        return resolveParams(event, HttpParamType.HEADER);
    }

    public String replaceUriParams(String path, MuleEvent event)
    {
        ParameterMap uriParamMap = resolveParams(event, HttpParamType.URI_PARAM);

        for (String uriParamName : uriParamMap.keySet())
        {
            // If more than one value has been defined for a URI param, use the last one (to allow overrides)

            List uriParamValues = uriParamMap.getAll(uriParamName);
            String uriParamValue = uriParamValues.get(uriParamValues.size() - 1);

            if (uriParamValue == null)
            {
                throw new NullPointerException(String.format("Expression {%s} evaluated to null.", uriParamName));
            }

            path = path.replaceAll(String.format("\\{%s\\}", uriParamName), uriParamValue);
        }
        return path;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy