Class DefensicsApiClientConnect
- java.lang.Object
-
- com.synopsys.defensics.apiserver.client.DefensicsApiClientConnect
-
public class DefensicsApiClientConnect extends Object
Helper class for client requests.
-
-
Constructor Summary
Constructors Constructor Description DefensicsApiClientConnect(HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, String token)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
delete(HttpUrl url, String operation)
Do a HTTP DELETE.protected <T> List<T>
getArrayItem(HttpUrl url, String operationString, com.fasterxml.jackson.core.type.TypeReference<ItemArray<T>> typeReference)
Getter for array item.Optional<Map<String,HealthCheckResult>>
getHealthCheck(HttpUrl healthcheckUrl)
protected InputStream
getInputStream(HttpUrl url, String operationString)
GET given URL and return response as a stream.protected <T> Optional<T>
getSingleItem(HttpUrl url, String operationString, com.fasterxml.jackson.core.type.TypeReference<Item<T>> typeReference)
Get single JSON item.protected <T> T
post(HttpUrl url, RequestBody body, String operationString, com.fasterxml.jackson.core.type.TypeReference<Item<T>> typeReference)
Make HTTP POST request to given url with given RequestBody.protected void
postAction(HttpUrl startUrl, String operation)
protected void
postNoResponse(HttpUrl url, RequestBody body, String operationString)
Calls post(url, body, operationString, null).void
setUserAgent(String userAgentString)
-
-
-
Constructor Detail
-
DefensicsApiClientConnect
public DefensicsApiClientConnect(HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, String token)
Constructor.- Parameters:
httpClient
- Java HTTP client.objectMapper
- Object mapper.token
- Token to use in request. Can be null.
-
-
Method Detail
-
setUserAgent
public void setUserAgent(String userAgentString)
-
getInputStream
protected InputStream getInputStream(HttpUrl url, String operationString)
GET given URL and return response as a stream. Note: caller needs to close the stream.- Parameters:
url
- URL to GEToperationString
- Operation tried- Returns:
- Response as a stream
-
postAction
protected void postAction(HttpUrl startUrl, String operation)
- Parameters:
startUrl
- the target url.operation
- name of the operation.
-
postNoResponse
protected void postNoResponse(HttpUrl url, RequestBody body, String operationString)
Calls post(url, body, operationString, null).- Parameters:
url
- the target url.body
- Body to send.operationString
- name of the operation.
-
delete
protected void delete(HttpUrl url, String operation)
Do a HTTP DELETE.- Parameters:
url
- the target URL.operation
- operation for logging.
-
post
protected <T> T post(HttpUrl url, RequestBody body, String operationString, com.fasterxml.jackson.core.type.TypeReference<Item<T>> typeReference)
Make HTTP POST request to given url with given RequestBody. Read response if typeReference is non-null, otherwise null is returned.- Type Parameters:
T
- Expected result type. Note that Item unwrapping is defined already.- Parameters:
url
- URLbody
- Request bodyoperationString
- String used in e.g. error conditions. In format "upload testplan"typeReference
- Type reference where to de-serialize response. If null, response is not read and null is returned.- Returns:
- De-serialized response or null
-
getArrayItem
protected <T> List<T> getArrayItem(HttpUrl url, String operationString, com.fasterxml.jackson.core.type.TypeReference<ItemArray<T>> typeReference)
Getter for array item.- Parameters:
url
- the target url.operationString
- name of the operation for logging.typeReference
- type of the response.- Returns:
- List of objects.
-
getSingleItem
protected <T> Optional<T> getSingleItem(HttpUrl url, String operationString, com.fasterxml.jackson.core.type.TypeReference<Item<T>> typeReference)
Get single JSON item.- Parameters:
url
- the target url.operationString
- name of the operation for logging.typeReference
- type of the response.- Returns:
- Item wrapped in Optional.
-
getHealthCheck
public Optional<Map<String,HealthCheckResult>> getHealthCheck(HttpUrl healthcheckUrl)
-
-