org.appng.api.rest

## Class RestClient

- java.lang.Object
- - org.appng.api.rest.RestClient

-     public class RestClient
      extends Object

  A simple client for the appNG REST API, open for extension. Note that this class is NOT thread-safe!

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `RestClient.Pageable` Wraps paging and sorting

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<String,String>` | `cookies`
    `protected org.springframework.web.client.RestTemplate` | `restTemplate`
    `protected String` | `url`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RestClient(String url)` Creates a new `RestClient`.
    `RestClient(String url, Map<String,String> cookies)` Creates a new `RestClient`, using an existing cookie.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `RestResponseEntity<Datasource>` | `datasource(String application, String id)` Retrieves the `Datasource`.
    `RestResponseEntity<Datasource>` | `datasource(String application, String id, org.springframework.util.MultiValueMap<String,String> parameters)` Retrieves the `Datasource`.
    `RestResponseEntity<Datasource>` | `datasource(String application, String id, RestClient.Pageable pageable)` Retrieves the `Datasource`.
    `RestResponseEntity<Datasource>` | `datasource(String application, String id, RestClient.Pageable pageable, org.springframework.util.MultiValueMap<String,String> parameters)` Retrieves the `Datasource`.
    `<OUT,IN> RestResponseEntity<IN>` | `exchange(String path, OUT body, Class<IN> returnType, org.springframework.http.HttpMethod method)` Retrieves a REST-Resource with a given HTTP method. Example:
    `protected <IN,OUT> RestResponseEntity<IN>` | `exchange(URI uri, OUT body, org.springframework.http.HttpMethod method, Class<IN> returnType)`
    `protected <IN,OUT> RestResponseEntity<IN>` | `exchange(URI uri, OUT body, org.springframework.http.HttpMethod method, Class<IN> returnType, boolean acceptAnyType)`
    `RestResponseEntity<Action>` | `getAction(Link link)` Retrieves the `Action` represented by the `Link`
    `RestResponseEntity<Action>` | `getAction(String application, String eventId, String actionId, String... pathVariables)` Retrieves the `Action`.
    `protected URI` | `getActionURL(String application, String eventId, String actionId, String[] pathVariables)`
    `RestResponseEntity<byte[]>` | `getBinaryData(Link link)` Returns the resource represented by the link as binary data
    `RestResponseEntity<byte[]>` | `getBinaryData(String relativePath)` Returns the resource represented by the relative path
    `Map<String,String>` | `getCookies()` Returns the current cookies or this client
    `protected org.springframework.http.HttpHeaders` | `getHeaders(boolean acceptAnyType)`
    `<IN> RestResponseEntity<IN>` | `getResource(String path, Class<IN> returnType)` Retrieves a REST-Resource with HTTP GET. Example:
    `RestResponseEntity<Action>` | `performAction(Action data, Link link)` Performs an `Action`, the URI is defined by the `Link`.
    `RestResponseEntity<Action>` | `performAction(String application, Action data, String... pathVariables)` Performs an `Action`.
    `protected void` | `setCookies(org.springframework.http.ResponseEntity<?> entity)`

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

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

- - ### Field Detail

    - #### restTemplate

          protected org.springframework.web.client.RestTemplate restTemplate

    - #### cookies

          protected Map<String,String> cookies

    - #### url

          protected String url

  - ### Constructor Detail

    - #### RestClient

          public RestClient(String url)

      Creates a new `RestClient`.

      Note that you probably need to perform a login action before you can use this client.

      Parameters:
        `url` - the URL pointing to a site's service URL (`/service/<site-name>`)

    - #### RestClient

          public RestClient(String url,
                            Map<String,String> cookies)

      Creates a new `RestClient`, using an existing cookie. This cookie should be retrieved from another client that performed a login action.
      Parameters:
        `url` - the URL pointing to a site's service URL (`/service/<site-name>`)
        `cookies` - the cookie to use
      See Also:
        `getCookies()`

  - ### Method Detail

    - #### datasource

          public RestResponseEntity<Datasource> datasource(String application,
                                                           String id)
                                                    throws URISyntaxException

      Retrieves the `Datasource`.
      Parameters:
        `application` - the name of the application
        `id` - the ID of the `Datasource`
      Returns:
        the `Datasource` wrapped in a `RestResponseEntity`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### datasource

          public RestResponseEntity<Datasource> datasource(String application,
                                                           String id,
                                                           RestClient.Pageable pageable)
                                                    throws URISyntaxException

      Retrieves the `Datasource`.
      Parameters:
        `application` - the name of the application
        `id` - the ID of the `Datasource`
        `pageable` - a `RestClient.Pageable` (optional)
      Returns:
        the `Datasource` wrapped in a `RestResponseEntity`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### datasource

          public RestResponseEntity<Datasource> datasource(String application,
                                                           String id,
                                                           org.springframework.util.MultiValueMap<String,String> parameters)
                                                    throws URISyntaxException

      Retrieves the `Datasource`.
      Parameters:
        `application` - the name of the application
        `id` - the ID of the `Datasource`
        `parameters` - some additional parameters
      Returns:
        the `Datasource` wrapped in a `RestResponseEntity`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### datasource

          public RestResponseEntity<Datasource> datasource(String application,
                                                           String id,
                                                           RestClient.Pageable pageable,
                                                           org.springframework.util.MultiValueMap<String,String> parameters)
                                                    throws URISyntaxException

      Retrieves the `Datasource`.
      Parameters:
        `application` - the name of the application
        `id` - the ID of the `Datasource`
        `pageable` - a `RestClient.Pageable` (optional)
        `parameters` - some additional parameters
      Returns:
        the `Datasource` wrapped in a `RestResponseEntity`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### getAction

          public RestResponseEntity<Action> getAction(String application,
                                                      String eventId,
                                                      String actionId,
                                                      String... pathVariables)
                                               throws URISyntaxException

      Retrieves the `Action`.
      Parameters:
        `application` - the name of the application
        `eventId` - the event-ID of the `Action`
        `actionId` - the ID of the `Action`
        `pathVariables` - some additional path variables
      Returns:
        the (unprocessed) `Action` wrapped in a `RestResponseEntity`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### getAction

          public RestResponseEntity<Action> getAction(Link link)
                                               throws URISyntaxException

      Retrieves the `Action` represented by the `Link`
      Parameters:
        `link` - the `Link` representing the `Action`'s URI
      Returns:
        the (unprocessed) `Action` wrapped in a `RestResponseEntity`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### performAction

          public RestResponseEntity<Action> performAction(Action data,
                                                          Link link)
                                                   throws URISyntaxException

      Performs an `Action`, the URI is defined by the `Link`.
      Parameters:
        `data` - the `Action`-data to send
        `link` - the `Link`
      Returns:
        a `RestResponseEntity` wrapping the resulting `Action`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### setCookies

          protected void setCookies(org.springframework.http.ResponseEntity<?> entity)

    - #### getActionURL

          protected URI getActionURL(String application,
                                     String eventId,
                                     String actionId,
                                     String[] pathVariables)
                              throws URISyntaxException

      Throws:
        `URISyntaxException`

    - #### performAction

          public RestResponseEntity<Action> performAction(String application,
                                                          Action data,
                                                          String... pathVariables)
                                                   throws URISyntaxException

      Performs an `Action`.
      Parameters:
        `application` - the name of the application
        `data` - the `Action`-data to send
        `pathVariables` - some additional path variables
      Returns:
        a `RestResponseEntity` wrapping the resulting `Action`
      Throws:
        `URISyntaxException` - if something is wrong with the URI

    - #### getHeaders

          protected org.springframework.http.HttpHeaders getHeaders(boolean acceptAnyType)

    - #### getCookies

          public Map<String,String> getCookies()

      Returns the current cookies or this client
      Returns:
        the cookie's map

    - #### getBinaryData

          public RestResponseEntity<byte[]> getBinaryData(Link link)
                                                   throws URISyntaxException

      Returns the resource represented by the link as binary data
      Parameters:
        `link` - the ink to there resource
      Returns:
        the resource
      Throws:
        `URISyntaxException` - if something is wrong with the link

    - #### getBinaryData

          public RestResponseEntity<byte[]> getBinaryData(String relativePath)
                                                   throws URISyntaxException

      Returns the resource represented by the relative path
      Parameters:
        `relativePath` - the relative path, e.g. `/application/rest/downloads/4711`
      Returns:
        the resource
      Throws:
        `URISyntaxException` - if something is wrong with the path

    - #### exchange

          public <OUT,IN> RestResponseEntity<IN> exchange(String path,
                                                          OUT body,
                                                          Class<IN> returnType,
                                                          org.springframework.http.HttpMethod method)
                                                   throws URISyntaxException

      Retrieves a REST-Resource with a given HTTP method.
      Example:

           ResponseEntity result = restClient.retrieveResource("/application/rest/calculator/add/47/11", null, Integer.class, HttpMethod.GET)

      Parameters:
        `path` - the relative path to the resource, starting with the application's name
        `body` - the request body (optional)
        `returnType` - the type of the response
        `method` - the `HttpMethod` to use
      Returns:
        the `RestResponseEntity`
      Throws:
        `URISyntaxException`

    - #### exchange

          protected <IN,OUT> RestResponseEntity<IN> exchange(URI uri,
                                                             OUT body,
                                                             org.springframework.http.HttpMethod method,
                                                             Class<IN> returnType)

    - #### exchange

          protected <IN,OUT> RestResponseEntity<IN> exchange(URI uri,
                                                             OUT body,
                                                             org.springframework.http.HttpMethod method,
                                                             Class<IN> returnType,
                                                             boolean acceptAnyType)

    - #### getResource

          public <IN> RestResponseEntity<IN> getResource(String path,
                                                         Class<IN> returnType)
                                                  throws URISyntaxException

      Retrieves a REST-Resource with HTTP GET.
      Example:

           ResponseEntity result = restClient.retrieveResource("/application/rest/calculator/add/47/11", null, Integer.class, HttpMethod.GET)

      Parameters:
        `path` - the relative path to the resource, starting with the application's name
        `returnType` - the type of the response
      Returns:
        the `RestResponseEntity`
      Throws:
        `URISyntaxException`

Copyright © 2011–2023 aiticon GmbH. All rights reserved.