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

com.github.ywilkof.sparkrestclient.HttpRequestUtil Maven / Gradle / Ivy

Go to download

Fluent utility client for interacting with Spark Standalone Mode's Rest API for submitting, killing and monitoring the state of jobs.

There is a newer version: 1.3.9
Show newest version
package com.github.ywilkof.sparkrestclient;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.BasicResponseHandler;

import java.io.IOException;

public class HttpRequestUtil {

    static   T executeHttpMethodAndGetResponse(HttpClient client, HttpRequestBase httpRequest, Class responseClass) throws FailedSparkRequestException {
        T response;
        try {
            final String stringResponse = client.execute(httpRequest, new BasicResponseHandler());
            if (stringResponse != null) {
                response = MapperWrapper.MAPPER.readValue(stringResponse, responseClass);
            } else {
                throw new FailedSparkRequestException("Received empty string response");
            }
        } catch (IOException e) {
            throw new FailedSparkRequestException(e);
        } finally {
            httpRequest.releaseConnection();
        }

        if (response == null) {
            throw new FailedSparkRequestException("An issue occured with the cluster's response.");
        }

        return response;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy