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

top.jfunc.http.component.jodd.JoddHttpRequestExecutor Maven / Gradle / Ivy

package top.jfunc.http.component.jodd;

import jodd.http.HttpResponse;
import top.jfunc.http.base.ContentCallback;
import top.jfunc.http.component.*;
import top.jfunc.http.request.HttpRequest;
import top.jfunc.http.response.ClientHttpResponse;

import java.io.IOException;

/**
 * Jodd实现的处理
 * @author xiongshiyan
 * @since 2020.12.01
 * @since 1.2.12
 */
public class JoddHttpRequestExecutor extends BaseHttpRequestExecutor implements HttpRequestExecutor {
    private RequesterFactory httpRequestRequesterFactory;

    public JoddHttpRequestExecutor() {
        super(new DefaultJoddHeaderHandler(), new DefaultJoddStreamExtractor(), new DefaultJoddHeaderExtractor());
        this.httpRequestRequesterFactory = new DefaultJoddHttpRequestFactory();
    }

    public JoddHttpRequestExecutor(HeaderHandler httpRequestHeaderHandler, StreamExtractor responseStreamExtractor,
                                   HeaderExtractor responseHeaderExtractor,
                                   RequesterFactory httpRequestRequesterFactory) {
        super(httpRequestHeaderHandler, responseStreamExtractor, responseHeaderExtractor);
        this.httpRequestRequesterFactory = httpRequestRequesterFactory;
    }

    @Override
    public ClientHttpResponse execute(HttpRequest httpRequest, ContentCallback contentCallback) throws IOException{
        //1.获取Request
        jodd.http.HttpRequest request = getHttpRequestRequesterFactory().create(httpRequest);

        //2.处理body
        handleBody(request , contentCallback , httpRequest);

        //3.设置header
        handleHeaders(request , httpRequest);

        //4.真正请求
        HttpResponse response = getResponse(request, httpRequest);
        return new JoddClientHttpResponse(response, httpRequest, getResponseStreamExtractor(), getResponseHeaderExtractor());
    }

    protected HttpResponse getResponse(jodd.http.HttpRequest request, top.jfunc.http.request.HttpRequest httpRequest) throws IOException {
        return request.send();
    }

    public RequesterFactory getHttpRequestRequesterFactory() {
        return httpRequestRequesterFactory;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy