
org.swiftboot.web.command.HttpCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swiftboot-web Show documentation
Show all versions of swiftboot-web Show documentation
Basic module for enterprise web applications
package org.swiftboot.web.command;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* 所有 HTTP(S) 请求命令都继承自 HttpCommand
*
* @author swiftech
*/
@ApiModel
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class HttpCommand implements Serializable {
/**
* HTTP(S) 请求头
*/
@ApiModelProperty("HTTP(S) headers")
@JsonIgnore
private Map headers;
public HttpCommand() {
}
public Map getHeaders() {
return headers;
}
public void setHeader(String k, String v) {
if (this.headers == null) {
this.headers = new HashMap<>();
}
this.headers.put(k, v);
}
public String getHeader(String k) {
if (this.headers != null) {
return this.headers.get(k);
}
return null;
}
@JsonIgnore
public String getHeaderString() {
StringBuffer buf = new StringBuffer();
if (headers != null) {
for (String header : headers.keySet()) {
buf.append(header).append(headers.get(header));
}
}
return buf.toString();
}
@Override
public String toString() {
try {
return new ObjectMapper().writeValueAsString(this);
} catch (JsonProcessingException e) {
return super.toString();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy