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.SensorThingsService(DataModel... models) Creates a new SensorThingsService without an endpoint url set.SensorThingsService(URI endpoint, DataModel... models) Creates a new SensorThingsService with the given endpoint URI.SensorThingsService(URI endpoint, List<DataModel> models) Creates a new SensorThingsService with the given endpoint URI.SensorThingsService(URL endpoint, DataModel... models) Creates a new SensorThingsService with the given endpoint URL.SensorThingsService(URL endpoint, List<DataModel> models) Creates a new SensorThingsService with the given endpoint URL.SensorThingsService(List<DataModel> models) Creates a new SensorThingsService without an endpoint url set. -
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.<T extends DataModel>
Tint<T extends DataModel>
booleanbooleanCheck 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 SensorThingsServicesetEndpoint(URI endpoint) Sets the endpoint URL/URI.final SensorThingsServicesetEndpoint(URL endpoint) Sets the endpoint URL/URI.setRequestTimeoutMs(int requestTimeoutMs) setTokenManager(TokenManager tokenManager) Sets the TokenManager.final SensorThingsServicesetUrlReplace(String urlReplace) In some cases the server generates URLs using a different base URL.voidsetVersion(Version version) Explicitly set the version for servers that do not conform to the standard and do not have the version number in the 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. The models will be initialised in the order they are returned by the list.- Parameters:
models- The data models to use.
-
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 data model to use.
-
SensorThingsService
Creates a new SensorThingsService without an endpoint url set. The endpoint url MUST be set before the service can be used. The models will be initialised in the order they have.- Parameters:
models- The data models to use.
-
SensorThingsService
Creates a new SensorThingsService with the given endpoint URI. The models will be initialised in the order they have.- Parameters:
endpoint- the base URI of the SensorThings servicemodels- The data models to use.- Throws:
MalformedURLException- when building the final URL fails.
-
SensorThingsService
Creates a new SensorThingsService with the given endpoint URI. The models will be initialised in the order they have.- Parameters:
endpoint- the base URI of the SensorThings servicemodels- The data models to use.- Throws:
MalformedURLException- when building the final URL fails.
-
SensorThingsService
Creates a new SensorThingsService with the given endpoint URL. The models will be initialised in the order they have.- Parameters:
endpoint- the base URL of the SensorThings servicemodels- The data models to use.- Throws:
MalformedURLException- when building the final URL fails.
-
SensorThingsService
Creates a new SensorThingsService with the given endpoint URL. The models will be initialised in the order they have.- Parameters:
endpoint- the base URL of the SensorThings servicemodels- The data models to use.- Throws:
MalformedURLException- when building the final URL fails.
-
-
Method Details
-
getModelRegistry
-
getModel
-
hasModel
-
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.- Returns:
- this.
- 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.- Returns:
- this.
- 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.- Returns:
- this.
-
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. -
getModels
-
getVersion
-
setVersion
Explicitly set the version for servers that do not conform to the standard and do not have the version number in the URL.- Parameters:
version- the version to use.
-
getRequestTimeoutMs
public int getRequestTimeoutMs() -
setRequestTimeoutMs
-