|
TypedRest for Java
|
Base class for building REST endpoints, i.e. More...
Public Member Functions | |
| final void | setDefaultLink (String rel, String... hrefs) |
| Registers one or more default links for a specific relation type. More... | |
| final void | setDefaultLinkTemplate (String rel, String href) |
| Registers a default link template for a specific relation type. More... | |
| Set< URI > | getLinks (String rel) |
| Retrieves all links with a specific relation type cached from the last request. More... | |
| Map< URI, String > | getLinksWithTitles (String rel) |
| Retrieves all links (with titles) with a specific relation type cached from the last request. More... | |
| URI | link (String rel) |
| Retrieves a single link with a specific relation type. More... | |
| UriTemplate | linkTemplate (String rel) |
| Retrieves a link template with a specific relation type. More... | |
| String | toString () |
Public Member Functions inherited from net.typedrest.Endpoint | |
| URI | getUri () |
| The HTTP URI of the remote resource. More... | |
| Executor | getExecutor () |
| The REST executor used to communicate with the remote resource. More... | |
| ObjectMapper | getSerializer () |
| Controls the serialization of entities sent to and received from the server. More... | |
| default URI | linkTemplate (String rel, String variableName, Object value) |
| Retrieves a link template with a specific relation type and resolves it. More... | |
Protected Member Functions | |
| AbstractEndpoint (URI uri, Executor executor, ObjectMapper serializer) | |
| Creates a new REST endpoint with an absolute URI. More... | |
| AbstractEndpoint (Endpoint referrer, URI relativeUri) | |
| Creates a new REST endpoint with a relative URI. More... | |
| AbstractEndpoint (Endpoint referrer, String relativeUri) | |
| Creates a new REST endpoint with a relative URI. More... | |
| HttpResponse | executeAndHandle (Request request) throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException |
| Executes a REST request and wraps HTTP status codes in appropriate Exception types. More... | |
| HttpResponse | execute (Request request) throws IOException |
| Executes a REST request adding any configured defaultHeaders. More... | |
| void | handleResponse (HttpResponse response, Request request) throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException |
| Handles the response of a REST request and wraps HTTP status codes in appropriate Exception types. More... | |
| void | handleErrors (HttpResponse response, Request request) throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException |
| Wraps HTTP status codes in appropriate Exception types. More... | |
| void | handleHeaderLinks (HttpResponse response, Map< String, Map< URI, String >> links, Map< String, String > linkTemplates) |
| Handles links embedded in HTTP response headers. More... | |
| void | handleBodyLinks (JsonNode jsonBody, Map< String, Map< URI, String >> links, Map< String, String > linkTemplates) |
| Handles links embedded in JSON response bodies. More... | |
| void | handleCapabilities (HttpResponse response) |
| Handles allowed HTTP methods and other capabilities reported by the server. More... | |
| Optional< Boolean > | isMethodAllowed (String method) |
| Shows whether the server has indicated that a specific HTTP method is currently allowed. More... | |
Protected Attributes | |
| final URI | uri |
| final Executor | executor |
| final ObjectMapper | serializer |
| final Collection< Header > | defaultHeaders = new LinkedList<>() |
| A set of default HTTP headers to be added to each request. | |
Base class for building REST endpoints, i.e.
remote HTTP resources.
|
protected |
Creates a new REST endpoint with an absolute URI.
| uri | The HTTP URI of the remote element. |
| executor | The REST executor used to communicate with the remote element. |
| serializer | Controls the serialization of entities sent to and received from the server. |
|
protected |
Creates a new REST endpoint with a relative URI.
| referrer | The parent endpoint containing this one. |
| relativeUri | The URI of this endpoint relative to the referrer's. |
|
protected |
Creates a new REST endpoint with a relative URI.
| referrer | The parent endpoint containing this one. |
| relativeUri | The URI of this endpoint relative to the referrer's. Prefix ./ to append a trailing slash to the referrer URI if missing. Prefix ./ to append a trailing slash to the referrer URI if missing. |
|
protected |
Executes a REST request adding any configured defaultHeaders.
| request | The request to execute. |
| IOException | Network communication failed. |
| RuntimeException | Other non-success status code. |
|
protected |
Executes a REST request and wraps HTTP status codes in appropriate Exception types.
| request | The request to execute. |
| IOException | Network communication failed. |
| IllegalArgumentException | HttpStatus#SC_BAD_REQUEST |
| IllegalAccessException | HttpStatus#SC_UNAUTHORIZED or HttpStatus#SC_FORBIDDEN |
| FileNotFoundException | HttpStatus#SC_NOT_FOUND or HttpStatus#SC_GONE |
| IllegalStateException | HttpStatus#SC_CONFLICT, HttpStatus#SC_PRECONDITION_FAILED or HttpStatus#SC_REQUESTED_RANGE_NOT_SATISFIABLE |
| RuntimeException | Other non-success status code. |
| Set<URI> net.typedrest.AbstractEndpoint.getLinks | ( | String | rel | ) |
Retrieves all links with a specific relation type cached from the last request.
| rel | The relation type of the links to look for. |
Implements net.typedrest.Endpoint.
| Map<URI, String> net.typedrest.AbstractEndpoint.getLinksWithTitles | ( | String | rel | ) |
Retrieves all links (with titles) with a specific relation type cached from the last request.
| rel | The relation type of the links to look for. |
null). Implements net.typedrest.Endpoint.
|
protected |
Handles links embedded in JSON response bodies.
| jsonBody | The body to check for links. |
| links | A dictionary to add found links to. |
| linkTemplates | A dictionary to add found link templates to. |
|
protected |
Handles allowed HTTP methods and other capabilities reported by the server.
| response | The response to check for the "Allow" header. |
|
protected |
Wraps HTTP status codes in appropriate Exception types.
| response | The response to check for errors. |
| request | The original request the reponse is for. |
| IOException | Network communication failed. |
| IllegalArgumentException | HttpStatus#SC_BAD_REQUEST |
| IllegalAccessException | HttpStatus#SC_UNAUTHORIZED or HttpStatus#SC_FORBIDDEN |
| FileNotFoundException | HttpStatus#SC_NOT_FOUND or HttpStatus#SC_GONE |
| IllegalStateException | HttpStatus#SC_CONFLICT, HttpStatus#SC_PRECONDITION_FAILED or HttpStatus#SC_REQUESTED_RANGE_NOT_SATISFIABLE |
| RuntimeException | Other non-success status code. |
|
protected |
Handles links embedded in HTTP response headers.
| response | The response to check for links. |
| links | A dictionary to add found links to. |
| linkTemplates | A dictionary to add found link templates to. |
|
protected |
Handles the response of a REST request and wraps HTTP status codes in appropriate Exception types.
| response | The response to handle. |
| request | The original request the reponse is for. |
| IOException | Network communication failed. |
| IllegalArgumentException | HttpStatus#SC_BAD_REQUEST |
| IllegalAccessException | HttpStatus#SC_UNAUTHORIZED or HttpStatus#SC_FORBIDDEN |
| FileNotFoundException | HttpStatus#SC_NOT_FOUND or HttpStatus#SC_GONE |
| IllegalStateException | HttpStatus#SC_CONFLICT, HttpStatus#SC_PRECONDITION_FAILED or HttpStatus#SC_REQUESTED_RANGE_NOT_SATISFIABLE |
| RuntimeException | Other non-success status code. |
|
protected |
Shows whether the server has indicated that a specific HTTP method is currently allowed.
Uses cached data from last response.
| method | The HTTP method (e.g. GET, POST, ...) to check. |
| URI net.typedrest.AbstractEndpoint.link | ( | String | rel | ) |
Retrieves a single link with a specific relation type.
Uses cached data from last response if possible. Tries lazy lookup with HTTP HEAD on cache miss.
| rel | The relation type of the link to look for. |
| RuntimeException | No link with the specified relation type could be found. |
Implements net.typedrest.Endpoint.
| UriTemplate net.typedrest.AbstractEndpoint.linkTemplate | ( | String | rel | ) |
Retrieves a link template with a specific relation type.
Uses cached data from last response if possible. Tries lazy lookup with HTTP HEAD on cache miss.
| rel | The relation type of the template to look for. |
| RuntimeException | No link template with the specified relation type could be found. |
Implements net.typedrest.Endpoint.
| final void net.typedrest.AbstractEndpoint.setDefaultLink | ( | String | rel, |
| String... | hrefs | ||
| ) |
Registers one or more default links for a specific relation type.
These links are used when no links with this relation type are provided by the server.
This method is not thread-safe! Call this before performing any requests.
| rel | The relation type of the links to add. |
| hrefs | The hrefs of links relative to this endpoint's URI. Use null or an empty list to remove all previous entries for the relation type. |
| final void net.typedrest.AbstractEndpoint.setDefaultLinkTemplate | ( | String | rel, |
| String | href | ||
| ) |
Registers a default link template for a specific relation type.
This template is used when no template with this relation type is provided by the server.
This method is not thread-safe! Call this before performing any requests.
| rel | The relation type of the link template to add. |
| href | The href of the link template relative to this endpoint's URI. Use null to remove any previous entry for the relation type. |
1.8.15