Move 204 empty checks into request helper and make Error class private
This commit is contained in:
@@ -22,13 +22,13 @@ package de.stklcode.jvault.connector.internal;
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.8 Extracted from static inner class.
|
||||
*/
|
||||
public final class Error {
|
||||
public static final String READ_RESPONSE = "Unable to read response";
|
||||
public static final String PARSE_RESPONSE = "Unable to parse response";
|
||||
public static final String UNEXPECTED_RESPONSE = "Received response where none was expected";
|
||||
public static final String URI_FORMAT = "Invalid URI format";
|
||||
public static final String RESPONSE_CODE = "Invalid response code";
|
||||
public static final String INIT_SSL_CONTEXT = "Unable to intialize SSLContext";
|
||||
final class Error {
|
||||
static final String READ_RESPONSE = "Unable to read response";
|
||||
static final String PARSE_RESPONSE = "Unable to parse response";
|
||||
static final String UNEXPECTED_RESPONSE = "Received response where none was expected";
|
||||
static final String URI_FORMAT = "Invalid URI format";
|
||||
static final String RESPONSE_CODE = "Invalid response code";
|
||||
static final String INIT_SSL_CONTEXT = "Unable to intialize SSLContext";
|
||||
|
||||
/**
|
||||
* Constructor hidden, this class should not be instantiated.
|
||||
|
@@ -117,6 +117,20 @@ public final class RequestHelper implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute HTTP request using POST method and expect empty (204) response.
|
||||
*
|
||||
* @param path URL path (relative to base).
|
||||
* @param token Vault token (may be {@code null}).
|
||||
* @throws VaultConnectorException on connection error
|
||||
* @since 0.8
|
||||
*/
|
||||
public void postWithoutResponse(final String path, final Object payload, final String token) throws VaultConnectorException {
|
||||
if (!post(path, payload, token).isEmpty()) {
|
||||
throw new InvalidResponseException(Error.UNEXPECTED_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute HTTP request using PUT method.
|
||||
*
|
||||
@@ -171,6 +185,22 @@ public final class RequestHelper implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute HTTP request using PUT method and expect empty (204) response.
|
||||
*
|
||||
* @param path URL path (relative to base).
|
||||
* @param payload Map of payload values (will be converted to JSON).
|
||||
* @param token Vault token (may be {@code null}).
|
||||
* @throws VaultConnectorException on connection error
|
||||
* @since 0.8
|
||||
*/
|
||||
public void putWithoutResponse(final String path, final Map<String, String> payload, final String token)
|
||||
throws VaultConnectorException {
|
||||
if (!put(path, payload, token).isEmpty()) {
|
||||
throw new InvalidResponseException(Error.UNEXPECTED_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute HTTP request using DELETE method.
|
||||
*
|
||||
@@ -192,6 +222,20 @@ public final class RequestHelper implements Serializable {
|
||||
return request(delete, retries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute HTTP request using DELETE method and expect empty (204) response.
|
||||
*
|
||||
* @param path URL path (relative to base).
|
||||
* @param token Vault token (may be {@code null}).
|
||||
* @throws VaultConnectorException on connection error
|
||||
* @since 0.8
|
||||
*/
|
||||
public void deleteWithoutResponse(final String path, final String token) throws VaultConnectorException {
|
||||
if (!delete(path, token).isEmpty()) {
|
||||
throw new InvalidResponseException(Error.UNEXPECTED_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute HTTP request using GET method.
|
||||
*
|
||||
|
Reference in New Issue
Block a user