com.gomcarter.frameworks.httpapi.message.request.RequestMessage Maven / Gradle / Ivy
package com.gomcarter.frameworks.httpapi.message.request;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.http.entity.ContentType;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.*;
/**
* @author gomcarter
*/
@Data
@Accessors(chain = true)
public class RequestMessage {
private String apiName;
private ContentType contentType;
private Map headers = new HashMap<>();
private Map> parameters = new HashMap<>();
/**
* 替换url上的 %s
*/
private List restParameters = new ArrayList<>();
private Map files;
private String body;
private String bodyPartName = "body";
private Charset charset;
public RequestMessage(String apiName, ContentType contentType, Charset charset) {
super();
this.apiName = apiName;
this.contentType = contentType == null ? ContentType.APPLICATION_JSON : contentType;
this.charset = charset == null ? Charset.defaultCharset() : charset;
}
public void addHeader(String key, String value) {
this.headers.put(key, value);
}
public void addAllParameter(Map params) {
params.forEach(this::addParameter);
}
public void addParameter(String name, String value) {
Set values = parameters.computeIfAbsent(name, k -> new HashSet<>());
values.add(value);
}
}