com.h3c.sdn.misc

## Class ResourceClient

- java.lang.Object
- - com.h3c.sdn.misc.ResourceClient

- Direct Known Subclasses:
    PoolableResourceClient

      public abstract class ResourceClient
      extends Object

  Base implementation of client services for accessing remote resources.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `LOGIN_TOKEN` Header field used to carry the authentication token.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceClient()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `annotate(org.apache.http.client.methods.HttpRequestBase request, LoginContext login)` Annotate the given request with the token of the supplied login context.
    `protected org.apache.http.client.HttpClient` | `client()`
    `ResponseData` | `delete(LoginContext login, URI uri)` Issues a delete request against the specified URI.
    `ResponseData` | `delete(LoginContext login, URI uri, byte[] request)` Issues a delete request against the specified URI.
    `ResponseData` | `get(LoginContext login, URI uri)` Issues a get request against the specified URI.
    `InputStream` | `getInputStream(LoginContext login, URI uri, String mediaType)` Issues a get request against the specified URI.
    `ResponseData` | `post(LoginContext login, URI uri)` Issues a post request against the specified URI
    `ResponseData` | `post(LoginContext login, URI uri, byte[] request)` Issues a post request against the specified URI.
    `ResponseData` | `post(LoginContext login, URI uri, org.apache.http.Header[] headers, byte[] request)` Issues a post request against the specified URI.
    `ResponseData` | `post(LoginContext login, URI uri, org.apache.http.Header[] headers, InputStream request)` Issues a post request against the specified URI, with the expectation that the response will not contain data.
    `ResponseData` | `put(LoginContext login, URI uri)` Issues a put request against the specified URI, with the expectation that the response will not contain data
    `ResponseData` | `put(LoginContext login, URI uri, byte[] request)` Issues a put request against the specified URI.
    `ResponseData` | `put(LoginContext login, URI uri, org.apache.http.Header[] headers, byte[] request)` Issues a put request against the specified URI.
    `protected byte[]` | `request(WebUtils.Tag request)` Converts the specified tag to byte array in UTF-8.
    `protected com.fasterxml.jackson.databind.JsonNode` | `response(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] response, String dataLabel)` Read and parse the specified JSON response.
    `protected org.apache.commons.configuration.XMLConfiguration` | `response(String root, byte[] response)` Get the XML configuration created from the specified request data and rooted at the specified element.
    `protected URI` | `uri(IpAddress address, int port, String path)` Creates a URI for accessing the specified resource path at the given address and port.
    `protected URI` | `uri(IpAddress address, int port, String path, boolean isSSL, QueryParameter... parameters)` Creates a URI for accessing the specified resource path at the given address and port.
    `protected String` | `webContext(String path)` Create a full web path.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### LOGIN_TOKEN

          public static final String LOGIN_TOKEN

      Header field used to carry the authentication token.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ResourceClient

          public ResourceClient()

  - ### Method Detail

    - #### webContext

          protected String webContext(String path)

      Create a full web path.
      Parameters:
        `path` - relative path
      Returns:
        full path

    - #### uri

          protected URI uri(IpAddress address,
                int port,
                String path)

      Creates a URI for accessing the specified resource path at the given address and port.
      Parameters:
        `address` - server address
        `port` - server port
        `path` - resource path
      Returns:
        resource URI
      Throws:
        `IllegalArgumentException` - if address or path have invalid format

    - #### uri

          protected URI uri(IpAddress address,
                int port,
                String path,
                boolean isSSL,
                QueryParameter... parameters)

      Creates a URI for accessing the specified resource path at the given address and port.
      Parameters:
        `address` - server address
        `port` - server port
        `path` - resource path
        `isSSL` - SSL enabled or not
        `parameters` - query parameters
      Returns:
        resource URI
      Throws:
        `IllegalArgumentException` - if address or path have invalid format

    - #### request

          protected byte[] request(WebUtils.Tag request)

      Converts the specified tag to byte array in UTF-8.
      Parameters:
        `request` - tag structure
      Returns:
        byte array containing the tag data
      Throws:
        `RuntimeException` - if UTF-8 encoding is not available

    - #### response

          protected org.apache.commons.configuration.XMLConfiguration response(String root,
                                                                   byte[] response)

      Get the XML configuration created from the specified request data and rooted at the specified element.
      Parameters:
        `root` - root element name
        `response` - XML-encoded request data
      Returns:
        XML configuration object
      Throws:
        `RuntimeException` - if data could not be extracted

    - #### response

          protected com.fasterxml.jackson.databind.JsonNode response(com.fasterxml.jackson.databind.ObjectMapper mapper,
                                                         byte[] response,
                                                         String dataLabel)
                                                              throws IOException

      Read and parse the specified JSON response.
      Parameters:
        `mapper` - JSON object mapper to use
        `response` - response data
        `dataLabel` - request data label to be used in a log message, should a parse or read error occur
      Returns:
        JSON node
      Throws:
        `IOException` - if issues arise when reading or parsing the request data

    - #### annotate

          protected void annotate(org.apache.http.client.methods.HttpRequestBase request,
                      LoginContext login)

      Annotate the given request with the token of the supplied login context. If the supplied login context is null, the annotation will not take place.
      Parameters:
        `request` - HTTP request
        `login` - optional login context

    - #### get

          public ResponseData get(LoginContext login,
                         URI uri)

      Issues a get request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### getInputStream

          public InputStream getInputStream(LoginContext login,
                                   URI uri,
                                   String mediaType)

      Issues a get request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
        `mediaType` - optional expected media type specified in the Accept header
      Returns:
        input stream to the response data
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### post

          public ResponseData post(LoginContext login,
                          URI uri,
                          byte[] request)

      Issues a post request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
        `request` - byte array of request data
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### post

          public ResponseData post(LoginContext login,
                          URI uri,
                          org.apache.http.Header[] headers,
                          byte[] request)

      Issues a post request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
        `headers` - required headers
        `request` - byte array of request data
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### post

          public ResponseData post(LoginContext login,
                          URI uri,
                          org.apache.http.Header[] headers,
                          InputStream request)

      Issues a post request against the specified URI, with the expectation that the response will not contain data.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
        `headers` - required headers
        `request` - InputStream of request data
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### post

          public ResponseData post(LoginContext login,
                          URI uri)

      Issues a post request against the specified URI
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### put

          public ResponseData put(LoginContext login,
                         URI uri,
                         byte[] request)

      Issues a put request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
        `request` - byte array of request data
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### put

          public ResponseData put(LoginContext login,
                         URI uri,
                         org.apache.http.Header[] headers,
                         byte[] request)

      Issues a put request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
        `headers` - required headers
        `request` - byte array of request data
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### put

          public ResponseData put(LoginContext login,
                         URI uri)

      Issues a put request against the specified URI, with the expectation that the response will not contain data
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### delete

          public ResponseData delete(LoginContext login,
                            URI uri)

      Issues a delete request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### delete

          public ResponseData delete(LoginContext login,
                            URI uri,
                            byte[] request)

      Issues a delete request against the specified URI.
      Parameters:
        `login` - previously established login context
        `uri` - resource URI
        `request` - byte array of request data
      Returns:
        a ResponseData object containing the status code, reason phrase and data as a byte array.
      Throws:
        `RuntimeException` - in case of an HTTP protocol error or connection problems

    - #### client

          protected org.apache.http.client.HttpClient client()

Copyright © 2014. All Rights Reserved.