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 ObjectMapper
    com.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 ObjectMapper
    java.lang.String getResponse()
    Gets the last response string fetched by this client.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 fetch
      headers - the HTTP headers to include
      mediaType - 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 fetch
      responseType - 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 fetch
      headers - the HTTP headers to include
      mediaType - the HTTP mime type
      responseType - 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.JsonProcessingException
      Fetches 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.JsonProcessingException
      Fetch json json node.
      Parameters:
      URL - the url to fetch
      headers - 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.JsonProcessingException
      Fetches 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 fetch
      mapToType - 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.JsonProcessingException
      Fetches 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 fetch
      headers - the HTTP headers to include
      mapToType - 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.JsonProcessingException
      Fetches 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 fetch
      headers - the HTTP headers to include
      mapToType - the type to convert the returned JSON into
      mapper - the Jackson ObjectMapper to use
      Returns:
      the deserialized response
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - the json processing exception