top.jfunc.http.component.AbstractBodyContentCallbackCreator Maven / Gradle / Ivy
package top.jfunc.http.component;
import top.jfunc.http.base.ContentCallback;
import top.jfunc.http.request.HttpRequest;
import top.jfunc.http.request.StringBodyRequest;
import java.io.IOException;
/**
* @author xiongshiyan at 2020/1/7 , contact me with email [email protected] or phone 15208384257
*/
public abstract class AbstractBodyContentCallbackCreator implements ContentCallbackCreator {
@Override
public ContentCallback create(HttpRequest httpRequest) throws IOException{
if(!supportBody(httpRequest)){
return null;
}
return doCreate((StringBodyRequest) httpRequest);
}
/**
* 真正的创建方法
* @param stringBodyRequest StringBodyRequest
* @return ContentCallback
* @throws IOException IOException
*/
protected abstract ContentCallback doCreate(StringBodyRequest stringBodyRequest) throws IOException;
protected boolean supportBody(HttpRequest httpRequest){
//方法不支持
if(!httpRequest.getConfig().getMethodContentStrategy().supportContent(httpRequest.getMethod())){
return false;
}
//不是StringBodyRequest
if(!(httpRequest instanceof StringBodyRequest)){
return false;
}
StringBodyRequest stringBodyRequest = (StringBodyRequest) httpRequest;
String body = stringBodyRequest.getBody();
//body为空
if(null == body){
return false;
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy