Class RequestHelper
- java.lang.Object
-
- de.stklcode.jvault.connector.internal.RequestHelper
-
- All Implemented Interfaces:
Serializable
public final class RequestHelper extends Object implements Serializable
Helper class to bundle Vault HTTP requests.- Since:
- 0.8 Extracted methods from
HTTPVaultConnector
. - Author:
- Stefan Kalscheuer
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RequestHelper(String baseURL, int retries, Integer timeout, String tlsVersion, X509Certificate trustedCaCert)
Constructor of the request helper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
delete(String path, String token)
Execute HTTP request using DELETE method.void
deleteWithoutResponse(String path, String token)
Execute HTTP request using DELETE method and expect empty (204) response.String
get(String path, Map<String,String> payload, String token)
Execute HTTP request using GET method.<T> T
get(String path, Map<String,String> payload, String token, Class<T> target)
Execute HTTP request using GET method and parse JSON result to target class.String
post(String path, Object payload, String token)
Execute HTTP request using POST method.<T> T
post(String path, Object payload, String token, Class<T> target)
Execute HTTP request using POST method and parse JSON result.void
postWithoutResponse(String path, Object payload, String token)
Execute HTTP request using POST method and expect empty (204) response.String
put(String path, Map<String,String> payload, String token)
Execute HTTP request using PUT method.<T> T
put(String path, Map<String,String> payload, String token, Class<T> target)
Execute HTTP request using PUT method and parse JSON result.void
putWithoutResponse(String path, Map<String,String> payload, String token)
Execute HTTP request using PUT method and expect empty (204) response.
-
-
-
Constructor Detail
-
RequestHelper
public RequestHelper(String baseURL, int retries, Integer timeout, String tlsVersion, X509Certificate trustedCaCert)
Constructor of the request helper.- Parameters:
baseURL
- The URLretries
- Number of retries on 5xx errorstimeout
- Timeout for HTTP requests (milliseconds)tlsVersion
- TLS Version.trustedCaCert
- Trusted CA certificate
-
-
Method Detail
-
post
public String post(String path, Object payload, String token) throws VaultConnectorException
Execute HTTP request using POST method.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).- Returns:
- HTTP response
- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8 Added
token
parameter.
-
post
public <T> T post(String path, Object payload, String token, Class<T> target) throws VaultConnectorException
Execute HTTP request using POST method and parse JSON result.- Type Parameters:
T
- Target type.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).target
- Target class.- Returns:
- HTTP response
- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8
-
postWithoutResponse
public void postWithoutResponse(String path, Object payload, String token) throws VaultConnectorException
Execute HTTP request using POST method and expect empty (204) response.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8
-
put
public String put(String path, Map<String,String> payload, String token) throws VaultConnectorException
Execute HTTP request using PUT method.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).- Returns:
- HTTP response
- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8 Added
token
parameter.
-
put
public <T> T put(String path, Map<String,String> payload, String token, Class<T> target) throws VaultConnectorException
Execute HTTP request using PUT method and parse JSON result.- Type Parameters:
T
- Target type.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).target
- Target class.- Returns:
- HTTP response
- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8
-
putWithoutResponse
public void putWithoutResponse(String path, Map<String,String> payload, String token) throws VaultConnectorException
Execute HTTP request using PUT method and expect empty (204) response.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8
-
delete
public String delete(String path, String token) throws VaultConnectorException
Execute HTTP request using DELETE method.- Parameters:
path
- URL path (relative to base).token
- Vault token (may benull
).- Returns:
- HTTP response
- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8 Added
token
parameter.
-
deleteWithoutResponse
public void deleteWithoutResponse(String path, String token) throws VaultConnectorException
Execute HTTP request using DELETE method and expect empty (204) response.- Parameters:
path
- URL path (relative to base).token
- Vault token (may benull
).- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8
-
get
public String get(String path, Map<String,String> payload, String token) throws VaultConnectorException
Execute HTTP request using GET method.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).- Returns:
- HTTP response
- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8 Added
token
parameter.
-
get
public <T> T get(String path, Map<String,String> payload, String token, Class<T> target) throws VaultConnectorException
Execute HTTP request using GET method and parse JSON result to target class.- Type Parameters:
T
- Target type.- Parameters:
path
- URL path (relative to base).payload
- Map of payload values (will be converted to JSON).token
- Vault token (may benull
).target
- Target class.- Returns:
- HTTP response
- Throws:
VaultConnectorException
- on connection error- Since:
- 0.8
-
-