Package tenapull.client
Class GenericClient
java.lang.Object
tenapull.client.GenericClient
- Direct Known Subclasses:
NessusClient
public abstract class GenericClient
extends java.lang.Object
Abstract generic client with methods for fetching resources at URLS, adding HTTP headers,
and JSON deserialization
-
Constructor Summary
Constructors Constructor Description GenericClient(boolean acceptAnySSL)
Instantiates a new Generic client. -
Method Summary
Modifier and Type Method Description java.lang.String
fetch(java.lang.String URL)
Fetches the resource at the provided URL and returns it as a string.<R> R
fetch(java.lang.String URL, java.lang.Class<R> responseType)
Fetches the resource at the provided URL and returns it as the class provided in the responseClass argument.java.lang.String
fetch(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, javax.ws.rs.core.MediaType mediaType)
Fetches the resource at the provided URL and returns it as a string<R> R
fetch(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, javax.ws.rs.core.MediaType mediaType, java.lang.Class<R> responseType)
Fetches the resource at the provided URL and returns it as the class provided in the responseClass argument.com.fasterxml.jackson.databind.JsonNode
fetchJson(java.lang.String URL)
Fetches the resource at the given url and converts it into a JsonNode using a standard Jackson ObjectMapper<T> T
fetchJson(java.lang.String URL, java.lang.Class<T> mapToType)
Fetches the resource at the given url and converts it into the given mapToType using a standard Jackson ObjectMappercom.fasterxml.jackson.databind.JsonNode
fetchJson(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers)
Fetch json json node.<R> R
fetchJson(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Class<R> mapToType, com.fasterxml.jackson.databind.ObjectMapper mapper)
Fetches the resource at the given url and converts it into the given mapToType using the provided Jackson ObjectMapper.<T> T
fetchJson(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Class<T> mapToType)
Fetches the resource at the given url and converts it into the given mapToType using a standard Jackson ObjectMapperjava.lang.String
getResponse()
Gets the last response string fetched by this client.
-
Constructor Details
-
GenericClient
public GenericClient(boolean acceptAnySSL)Instantiates a new Generic client.- Parameters:
acceptAnySSL
- whether to construct a normal client, or a client which accepts any SSL certificate using the AcceptAnySSL static utility
-
-
Method Details
-
getResponse
public java.lang.String getResponse()Gets the last response string fetched by this client. Typically used in the event of exceptions being thrown during deserialization of the string.- Returns:
- the most recent response string
-
fetch
public java.lang.String fetch(java.lang.String URL)Fetches the resource at the provided URL and returns it as a string.- Parameters:
URL
- the url to fetch- Returns:
- the string returned by the server at the given URL
-
fetch
public java.lang.String fetch(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, javax.ws.rs.core.MediaType mediaType)Fetches the resource at the provided URL and returns it as a string- Parameters:
URL
- the url to fetchheaders
- the HTTP headers to includemediaType
- the HTTP mime type- Returns:
- the string return by the server at the given URL
-
fetch
public <R> R fetch(java.lang.String URL, java.lang.Class<R> responseType)Fetches the resource at the provided URL and returns it as the class provided in the responseClass argument.- Type Parameters:
R
- The responseType- Parameters:
URL
- the url to fetchresponseType
- the responseType- Returns:
- the response returned by the server at the given URL, converted into the responseType
-
fetch
public <R> R fetch(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, javax.ws.rs.core.MediaType mediaType, java.lang.Class<R> responseType)Fetches the resource at the provided URL and returns it as the class provided in the responseClass argument.- Type Parameters:
R
- the responseType- Parameters:
URL
- the url to fetchheaders
- the HTTP headers to includemediaType
- the HTTP mime typeresponseType
- the response type- Returns:
- the response returned by the server at the given URL, converted into the responseType
-
fetchJson
public com.fasterxml.jackson.databind.JsonNode fetchJson(java.lang.String URL) throws com.fasterxml.jackson.core.JsonProcessingExceptionFetches the resource at the given url and converts it into a JsonNode using a standard Jackson ObjectMapper- Parameters:
URL
- the url to fetch- Returns:
- the response returned by the server at the given URL, converted into a JsonNode
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- if the Jackson ObjectMapper runs into a problem converting the response into a JsonNode
-
fetchJson
public com.fasterxml.jackson.databind.JsonNode fetchJson(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers) throws com.fasterxml.jackson.core.JsonProcessingExceptionFetch json json node.- Parameters:
URL
- the url to fetchheaders
- the HTTP headers to include- Returns:
- the response returned by the server at the given URL, converted into a JsonNode
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- if the Jackson ObjectMapper runs into a problem converting the response into a JsonNode
-
fetchJson
public <T> T fetchJson(java.lang.String URL, java.lang.Class<T> mapToType) throws com.fasterxml.jackson.core.JsonProcessingExceptionFetches the resource at the given url and converts it into the given mapToType using a standard Jackson ObjectMapper- Type Parameters:
T
- The type to map the response to- Parameters:
URL
- the url to fetchmapToType
- the type to convert the returned JSON into- Returns:
- the deserialized response
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- if the Jackson ObjectMapper runs into a problem converting the response into the mapToType
-
fetchJson
public <T> T fetchJson(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Class<T> mapToType) throws com.fasterxml.jackson.core.JsonProcessingExceptionFetches the resource at the given url and converts it into the given mapToType using a standard Jackson ObjectMapper- Type Parameters:
T
- the type to map the response to- Parameters:
URL
- the url to fetchheaders
- the HTTP headers to includemapToType
- the type to convert the returned JSON into- Returns:
- the deserialized response
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- if the Jackson ObjectMapper runs into a problem converting the response into a JsonNode
-
fetchJson
public <R> R fetchJson(java.lang.String URL, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Class<R> mapToType, com.fasterxml.jackson.databind.ObjectMapper mapper) throws com.fasterxml.jackson.core.JsonProcessingExceptionFetches the resource at the given url and converts it into the given mapToType using the provided Jackson ObjectMapper. Can be used for customized mapping- Type Parameters:
R
- the type to map the response to- Parameters:
URL
- the url to fetchheaders
- the HTTP headers to includemapToType
- the type to convert the returned JSON intomapper
- the Jackson ObjectMapper to use- Returns:
- the deserialized response
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- the json processing exception
-