com.github.ywilkof.sparkrestclient.HttpRequestUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spark-jobs-rest-client Show documentation
Show all versions of spark-jobs-rest-client Show documentation
Fluent utility client for interacting with Spark Standalone Mode's Rest API for submitting, killing and monitoring the state of jobs.
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;
}
}