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

org.mule.module.http.internal.HttpMapParam Maven / Gradle / Ivy

/*
 * 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;

import org.mule.api.MuleContext;
import org.mule.api.MuleEvent;

import java.util.Iterator;
import java.util.Map;


public class HttpMapParam extends HttpParam
{

    private String expression;

    public HttpMapParam(HttpParamType type)
    {
        super(type);
    }

    public String getExpression()
    {
        return expression;
    }

    public void setExpression(String expression)
    {
        this.expression = expression;
    }

    @Override
    public void resolve(ParameterMap parameterMap, MuleEvent muleEvent)
    {
        MuleContext muleContext = muleEvent.getMuleContext();
        Map paramMap = (Map) muleContext.getExpressionManager().evaluate(expression, muleEvent);
        for (Map.Entry entry : paramMap.entrySet())
        {
            String paramName = entry.getKey().toString();
            Object paramValue = entry.getValue();

            if (paramValue instanceof Iterable)
            {
                Iterable iterable = (Iterable) paramValue;
                final Iterator iterator = iterable.iterator();
                while (iterator.hasNext())
                {
                    parameterMap.put(paramName, iterator.next().toString());
                }
            }
            else
            {
                parameterMap.put(paramName, paramValue.toString());
            }

        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy