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

com.hashicorp.nomad.javasdk.ServerResponse Maven / Gradle / Ivy

There is a newer version: 0.11.3.0
Show newest version
package com.hashicorp.nomad.javasdk;

import org.apache.http.HttpResponse;

import javax.annotation.Nullable;
import java.math.BigInteger;

/**
 * A response from a Nomad server API.
 * 

* The index in a ServerResponse can be used with {@link QueryOptions} in subsequent requests to perform * Blocking Queries. * * @param type of value that was extracted from the response body */ public class ServerResponse extends NomadResponse { public static final String X_NOMAD_INDEX = "X-Nomad-Index"; protected final HttpResponse httpResponse; /** * Creates a new ServerResponse. * * @param httpResponse the underlying HTTP response * @param rawEntity the unparsed HTTP response entity (body) * @param value response value extracted from the response entity */ public ServerResponse(HttpResponse httpResponse, String rawEntity, @Nullable T value) { super(rawEntity, value); this.httpResponse = httpResponse; } /** * Returns the raw HttpResponse. */ public HttpResponse getHttpResponse() { return httpResponse; } /** * Returns the value of the @{code X-Nomad-Index} header. * * @throws ResponseHeaderException if the header is missing or cannot be parsed * @see Blocking Queries */ public BigInteger getIndex() throws ResponseHeaderException { String stringValue = httpResponse.getFirstHeader(X_NOMAD_INDEX).getValue(); try { return new BigInteger(stringValue); } catch (NumberFormatException e) { throw ResponseHeaderException.parsing(X_NOMAD_INDEX, stringValue, e); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy