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

org.jsoftware.restclient.plugins.CustomRequestHeaderPlugin Maven / Gradle / Ivy

There is a newer version: 1.5
Show newest version
package org.jsoftware.restclient.plugins;

import org.apache.commons.lang3.StringUtils;
import org.jsoftware.restclient.RestClientPlugin;

/**
 * Add custom header to request
 * @author szalik
 */
public class CustomRequestHeaderPlugin implements RestClientPlugin {
    private final String headerName, headerValue;

    public CustomRequestHeaderPlugin(String headerName, String headerValue) {
        this.headerName = headerName;
        this.headerValue = headerValue;
        if (StringUtils.isBlank(headerName)) {
            throw new IllegalArgumentException("Parameter 'headerName' cannot be blank");
        }
        if (StringUtils.isBlank(headerValue)) {
            throw new IllegalArgumentException("Parameter 'headerValue' cannot be blank");
        }
    }

    @Override
    public void plugin(PluginContext context, PluginChain chain) throws Exception {
        context.getRequest().addHeader(headerName, headerValue);
        chain.continueChain();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy