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

cz.jalasoft.net.http.HttpGetRequest Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package cz.jalasoft.net.http;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Honza Lastovicka on 18.5.15.
 */
public abstract class HttpGetRequest extends HttpRequest {

    private final Map parameters = new HashMap<>();

    public HttpGetRequest urlParameter(String name, String value) {
        this.parameters.put(name, value);
        return this;
    }

    public HttpGetRequest rawUrlParameters(String parameters) {
        if (parameters == null || parameters.isEmpty()) {
            throw new IllegalArgumentException("Raw http get parameters must not be null or empty.");
        }

        String[] parameterPairs = parameters.split("&");

        for(String parameterPair : parameterPairs) {
            String[] keyValue = parameterPair.split("=");

            if (keyValue.length != 2) {
                throw new IllegalArgumentException("Incorrect format of parameter. Expected: key=value");
            }

            String key = keyValue[0];
            String value = keyValue[1];

            this.parameters.put(key, value);
        }
        return this;
    }

    protected final Map parameters() {
        return parameters;
    }

    @Override
    HttpGetRequest getThis() {
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy