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

io.github.saoxuequ.http.request.smooth.EntityInvoker Maven / Gradle / Ivy

package io.github.saoxuequ.http.request.smooth;

import io.github.saoxuequ.http.request.common.Readable;
import io.github.saoxuequ.http.request.core.Entity;
import io.github.saoxuequ.http.request.core.EntityRequest;
import io.github.saoxuequ.http.request.core.HttpExecutor;
import io.github.saoxuequ.http.request.utils.UriTemplate;

import java.net.URI;
import java.util.Collections;
import java.util.List;

public class EntityInvoker extends AbstractInvoker> {

    private final Entity requestEntity;

    public EntityInvoker(HttpExecutor httpExecutor, CookieProvider cookieProvider,
                         String method, UriTemplate urlTemplate,
                         Entity requestEntity, Readable responseReader) {
        super(httpExecutor, cookieProvider, method, urlTemplate, responseReader);
        this.requestEntity = requestEntity;
    }

    @Override
    protected EntityInvoker self() {
        return this;
    }

    public R invoke(List urlParams, W body) {
        requestEntity.setEntity(body);
        URI uri = getUrlTemplate().generateUri(urlParams);
        if (getCookieProvider() != null) {
            setCookies(getCookieProvider().provide(uri));
        }
        EntityRequest request = new EntityRequest<>(getMethod(),
                uri,
                getHeaders(),
                requestEntity,
                getResponseReader());
        return getHttpExecutor().execute(request, getConnTimeout(), getReadTimeout());
    }

    public R invoke(W body) {
        requestEntity.setEntity(body);
        URI uri = getUrlTemplate().generateUri(Collections.emptyList());
        if (getCookieProvider() != null) {
            setCookies(getCookieProvider().provide(uri));
        }
        EntityRequest request = new EntityRequest<>(getMethod(),
                uri,
                getHeaders(),
                requestEntity,
                getResponseReader());
        return getHttpExecutor().execute(request, getConnTimeout(), getReadTimeout());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy