Class SensorThingsService
java.lang.Object
de.fraunhofer.iosb.ilt.frostclient.SensorThingsService
A SensorThingsService represents the service endpoint of a server.
- Author:
- Nils Sommer, Hylke van der Schaaf, Michael Jacoby
-
Constructor Summary
ConstructorsConstructorDescriptionSensorThingsService(ModelRegistry modelRegistry) Creates a new SensorThingsService without an endpoint url set.The endpoint url MUST be set before the service can be used.SensorThingsService(ModelRegistry modelRegistry, URI endpoint) Constructor.SensorThingsService(ModelRegistry modelRegistry, URL endpoint) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidCreate the given entity in this service.dao(EntityType type) voidDeletes the given entity from the service.org.apache.http.client.methods.CloseableHttpResponseexecute(org.apache.http.client.methods.HttpRequestBase request) Execute the given request, adding a token header if needed.org.apache.http.impl.client.HttpClientBuilderGet the Builder used to generate the httpClient.Gets the endpoint URL for the service.getFullPath(Entity parent, NavigationProperty relation) The full path to the entity or collection.getFullPath(EntityType entityType) The full path to the entity or collection.org.apache.http.impl.client.CloseableHttpClientGet the httpclient used for requests.getPath(Entity parent, NavigationProperty relation) The local path to the entity or collection.booleanCheck if the endpoint is set.voidUpdate the given entity with the given patch.query(EntityType type) Query a main entity set.voidTriggers a rebuild of the httpClient, using the latest changes to the clientBuilder.final voidsetEndpoint(URI endpoint) Sets the endpoint URL/URI.final voidsetEndpoint(URL endpoint) Sets the endpoint URL/URI.setTokenManager(TokenManager tokenManager) Sets the TokenManager.final voidsetUrlReplace(String urlReplace) In some cases the server generates URLs using a different base URL.voidPatches the entity in the Service.
-
Constructor Details
-
SensorThingsService
Creates a new SensorThingsService without an endpoint url set.The endpoint url MUST be set before the service can be used.- Parameters:
modelRegistry- The registry with the model to use.
-
SensorThingsService
Constructor.- Parameters:
modelRegistry- The registry with the model to use.endpoint- the base URI of the SensorThings service- Throws:
MalformedURLException- when building the final url fails.
-
SensorThingsService
Constructor.- Parameters:
modelRegistry- The registry with the model to use.endpoint- the base URL of the SensorThings service- Throws:
MalformedURLException- when building the final url fails.
-
-
Method Details
-
getModelRegistry
-
getJsonReader
-
setEndpoint
Sets the endpoint URL/URI. Once the endpoint URL/URI is set it can not be changed. The endpoint url MUST be set before the service can be used.- Parameters:
endpoint- The URI of the endpoint.- Throws:
MalformedURLException- when building the final url fails.
-
setEndpoint
Sets the endpoint URL/URI. Once the endpoint URL/URI is set it can not be changed. The endpoint url MUST be set before the service can be used.- Parameters:
endpoint- The URL of the endpoint.- Throws:
MalformedURLException- when building the final url fails.
-
setUrlReplace
In some cases the server generates URLs using a different base URL. For instance when the server has a different external and internal address. This option will replace the start part of each URL generated by the server that matches the given string, with the service URL.- Parameters:
urlReplace- the endpoint url the server uses, that needs to be replaced.
-
getEndpoint
Gets the endpoint URL for the service. Throws an IllegalStateException if the endpoint is not set.- Returns:
- the endpoint URL for the service.
-
isEndpointSet
public boolean isEndpointSet()Check if the endpoint is set.- Returns:
- true if the endpoint is set, false otherwise.
-
getFullPath
The full path to the entity or collection.- Parameters:
entityType- entity type to get the path for.- Returns:
- the full path to the entity or collection.
- Throws:
ServiceFailureException- If generating the path fails.
-
execute
public org.apache.http.client.methods.CloseableHttpResponse execute(org.apache.http.client.methods.HttpRequestBase request) throws IOException Execute the given request, adding a token header if needed.- Parameters:
request- The request to execute.- Returns:
- the response.
- Throws:
IOException- in case of problems.
-
query
Query a main entity set.- Parameters:
type- the type to query.- Returns:
- a new Query for the given type.
-
dao
-
create
Create the given entity in this service. Executes a POST to the Collection of the entity type. The entity will be updated with the ID of the entity in the Service and it will be linked to the Service.- Parameters:
entity- The entity to create in the service.- Throws:
ServiceFailureException- in case the server rejects the POST.
-
update
Patches the entity in the Service.- Parameters:
entity- The entity to update in the service.- Throws:
ServiceFailureException- in case the server rejects the PATCH.
-
patch
public void patch(Entity entity, List<com.github.fge.jsonpatch.JsonPatchOperation> patch) throws ServiceFailureException Update the given entity with the given patch. Does not update the entity object itself. To see the result, fetch it anew from the server.- Parameters:
entity- The entity to update on the server.patch- The patch to apply to the entity.- Throws:
ServiceFailureException- in case the server rejects the PATCH.
-
delete
Deletes the given entity from the service.- Parameters:
entity- The entity to delete in the service.- Throws:
ServiceFailureException- in case the server rejects the DELETE.
-
setTokenManager
Sets the TokenManager. Before each request is sent to the Service, the TokenManager has the opportunity to modify the request and add any headers required for Authentication and Authorisation.- Parameters:
tokenManager- The TokenManager to use, can be null.- Returns:
- This SensorThingsService.
-
getTokenManager
- Returns:
- The current TokenManager.
-
getHttpClient
public org.apache.http.impl.client.CloseableHttpClient getHttpClient()Get the httpclient used for requests.- Returns:
- the client
-
getClientBuilder
public org.apache.http.impl.client.HttpClientBuilder getClientBuilder()Get the Builder used to generate the httpClient. If changes are made to the builder after the httpClient is already generated, callrebuildHttpClient()to trigger the httpClient to be built anew. The clientBuilder is initialised using:HttpClients.custom().useSystemProperties()- Returns:
- The client Builder used to generate the httpClient.
-
rebuildHttpClient
public void rebuildHttpClient()Triggers a rebuild of the httpClient, using the latest changes to the clientBuilder. -
getVersion
-