/*
 * Copyright © 2023 by Data Virtuality GmbH
 */
package org.teiid.resource.adapter.ws;

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.URI;

public class HttpMethodWithEntity extends HttpEntityEnclosingRequestBase {
    private final String method;

    public HttpMethodWithEntity(String method, String uri, InputStreamEntity entity) throws IOException {
        this.method = method;
        this.setURI(URI.create(uri));
        byte[] bytes = EntityUtils.toByteArray(entity);
        this.setEntity(new ByteArrayEntity(bytes, ContentType.get(entity)));
    }

    public String getMethod() {
        return method;
    }
}
